Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: deduplicating circuit types + typing everything #3594

Merged
merged 63 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
33d99b4
WIP
benesjan Dec 6, 2023
c464019
WIP
benesjan Dec 6, 2023
efa1ed1
cleanup
benesjan Dec 6, 2023
485169c
WIP
benesjan Dec 6, 2023
a5b126f
WIP
benesjan Dec 6, 2023
57d5a20
WIP
benesjan Dec 6, 2023
6774a0f
WIP
benesjan Dec 6, 2023
02583ad
WIP
benesjan Dec 6, 2023
75635c5
inclusion proofs compiles
benesjan Dec 6, 2023
78243f9
WIP
benesjan Dec 6, 2023
48051c6
token compiles
benesjan Dec 7, 2023
b387050
card game compiles
benesjan Dec 7, 2023
cf0a567
child contract compiles
benesjan Dec 7, 2023
cf5f582
benchmarking contract compiles
benesjan Dec 7, 2023
e3f4d05
counter contract compiles
benesjan Dec 7, 2023
8ff6fd6
docs example compiles
benesjan Dec 7, 2023
85e60d7
easy private token compiles
benesjan Dec 7, 2023
1945e86
easy private voting compiles
benesjan Dec 7, 2023
ee1ed36
ecdsa account compiles
benesjan Dec 7, 2023
98257e5
escrow contract compiles
benesjan Dec 7, 2023
5eb3343
import test contract compiles
benesjan Dec 7, 2023
18b6bae
lending and parent compile
benesjan Dec 7, 2023
208bdde
pending commitments compile
benesjan Dec 7, 2023
422bfe5
schnorr compiles
benesjan Dec 7, 2023
c83f530
schnorr single key compiles
benesjan Dec 7, 2023
c2a4b40
slow tree compiles
benesjan Dec 7, 2023
901ed12
stateful test contract compiles
benesjan Dec 7, 2023
b93ac32
token blacklist compiles
benesjan Dec 7, 2023
795cb1d
token bridge compiles
benesjan Dec 7, 2023
57d1bc2
uniswap compiles
benesjan Dec 7, 2023
2ce5992
fix
benesjan Dec 7, 2023
db7d7d4
updated interface generator
benesjan Dec 7, 2023
761e205
renamed Address as AztecAddress
benesjan Dec 7, 2023
6eab0fb
more useful FunctionSelectorLike
benesjan Dec 7, 2023
d79a548
updated types
benesjan Dec 7, 2023
db8e4a0
fix
benesjan Dec 7, 2023
4fea78d
encoder fix
benesjan Dec 8, 2023
f31fba6
fix: nuking private kernel vk tree root
benesjan Dec 8, 2023
f90a26b
nuking private_kernel_vk_tree_root to make types match
benesjan Dec 8, 2023
0877f38
fix
benesjan Dec 8, 2023
abbd1b1
updated snapshots
benesjan Dec 8, 2023
f68fb16
reverting stuff
benesjan Dec 8, 2023
7f05395
Revert "updated snapshots"
benesjan Dec 8, 2023
cb1420f
updating entrypoint
benesjan Dec 8, 2023
46e1f2c
updated snap
benesjan Dec 8, 2023
e71b33c
encoder fix
benesjan Dec 8, 2023
8472280
reverted incorrect change
benesjan Dec 8, 2023
4c519e6
fixing signatures
benesjan Dec 8, 2023
6405f47
fixed card game e2e
benesjan Dec 8, 2023
6f2c0ef
e2e nested fix
benesjan Dec 8, 2023
e5197ac
cli test fix
benesjan Dec 11, 2023
967625d
fixed integration archiver test
benesjan Dec 11, 2023
4280f14
formatting
benesjan Dec 11, 2023
abf5650
nested e2e fix
benesjan Dec 11, 2023
182a7d0
nuking block struct and fixing stuff along the way
benesjan Dec 11, 2023
3d3f6c4
fixed up_quick_start test
benesjan Dec 11, 2023
13ad736
blacklist token fix
benesjan Dec 12, 2023
3c116d9
linking issue
benesjan Dec 12, 2023
d322fe7
Merge branch 'master' into janb/deduplication
benesjan Dec 13, 2023
60b7d17
linked issue
benesjan Dec 13, 2023
eb77165
Merge branch 'master' into janb/deduplication
benesjan Dec 13, 2023
2569dd2
naming consistency fix
benesjan Dec 13, 2023
efff86b
formatting fix
benesjan Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/docs/dev_docs/contracts/syntax/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ As shown in the snippet, the application context is made up of 4 main structures

First of all, the call context.

#include_code call-context /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code call-context /yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_context.nr rust

The call context contains information about the current call being made:

Expand All @@ -75,13 +75,13 @@ The call context contains information about the current call being made:

Another structure that is contained within the context is the Block Header object. This object is a special one as it contains all of the roots of Aztec's data trees.

#include_code block-header /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code block-header /yarn-project/noir-protocol-circuits/src/crates/types/src/abis/block_header.nr rust

### Contract Deployment Data

Just like with the `is_contract_deployment` flag mentioned earlier. This data will only be set to true when the current transaction is one in which a contract is being deployed.

#include_code contract-deployment-data /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code contract-deployment-data /yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevaundray if contract was to be removed from Noir as a keyword, and used in macros instead, I guess we could be renaming that folder and its content to use a proper spelling?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on what we go with as an alternative, the short term change might be to just change it to #[contract] which would not get rid of it


### Private Global Variables

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/src/acvm/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function extractPrivateCircuitPublicInputs(
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
Fr.ZERO,
Fr.ZERO, // TODO(#3441)
witnessReader.readField(),
witnessReader.readField(),
);
Expand Down Expand Up @@ -261,7 +261,7 @@ export function extractPublicCircuitPublicInputs(partialWitness: ACVMWitness, ac
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
Fr.ZERO,
Fr.ZERO, // TODO(#3441)
witnessReader.readField(),
witnessReader.readField(),
);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export class AztecNodeService implements AztecNode {
roots[MerkleTreeId.CONTRACT_TREE],
roots[MerkleTreeId.L1_TO_L2_MESSAGES_TREE],
roots[MerkleTreeId.ARCHIVE],
Fr.ZERO,
Fr.ZERO, // TODO(#3441)
roots[MerkleTreeId.PUBLIC_DATA_TREE],
globalsHash,
);
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/aztec-nr/address-note/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ compiler_version = ">=0.18.0"
type = "lib"

[dependencies]
aztec = { path = "../aztec" }
aztec = { path = "../aztec" }
protocol_types = { path = "../../../../noir-protocol-circuits/src/crates/types" }
13 changes: 7 additions & 6 deletions yarn-project/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// docs:start:encrypted_import
use dep::aztec::log::emit_encrypted_log;
// docs:end:encrypted_import
use dep::protocol_types::address::AztecAddress;
use dep::aztec::{
note::{
note_header::NoteHeader,
Expand All @@ -21,14 +22,14 @@ global ADDRESS_NOTE_LEN: Field = 3;
// docs:start:address_note_def
// Stores an address
struct AddressNote {
address: Field,
owner: Field,
address: AztecAddress,
owner: AztecAddress,
randomness: Field,
header: NoteHeader,
}

impl AddressNote {
pub fn new(address: Field, owner: Field) -> Self {
pub fn new(address: AztecAddress, owner: AztecAddress) -> Self {
let randomness = rand();
AddressNote {
address,
Expand All @@ -41,13 +42,13 @@ impl AddressNote {


pub fn serialize(self) -> [Field; ADDRESS_NOTE_LEN]{
[self.address, self.owner, self.randomness]
[self.address.to_field(), self.owner.to_field(), self.randomness]
}

pub fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> Self {
AddressNote {
address: serialized_note[0],
owner: serialized_note[1],
address: AztecAddress::from_field(serialized_note[0]),
owner: AztecAddress::from_field(serialized_note[1]),
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
Expand Down
36 changes: 24 additions & 12 deletions yarn-project/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use dep::protocol_types::constants::{EMPTY_NULLIFIED_COMMITMENT, GENERATOR_INDEX__SIGNATURE_PAYLOAD};
use dep::aztec::{
context::{PrivateContext, PublicContext, Context},
types::address::AztecAddress,
abi::hash_args,
hash::pedersen_hash,
use dep::protocol_types::{
abis::function_selector::FunctionSelector,
address::AztecAddress,
constants::{
EMPTY_NULLIFIED_COMMITMENT,
GENERATOR_INDEX__SIGNATURE_PAYLOAD,
},
hash::{
hash_args,
pedersen_hash,
},
};
use dep::aztec::context::{
PrivateContext,
PublicContext,
Context,
};

global IS_VALID_SELECTOR = 0xe86ab4ff;
Expand All @@ -14,7 +24,8 @@ global IS_VALID_PUBLIC_SELECTOR = 0xf3661153;
// docs:start:assert_valid_authwit
// Assert that `on_behalf_of` have authorized `message_hash` with a valid authentication witness
pub fn assert_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress, message_hash: Field) {
let result = context.call_private_function(on_behalf_of.address, IS_VALID_SELECTOR, [message_hash])[0];
let is_valid_selector = FunctionSelector::from_field(IS_VALID_SELECTOR);
benesjan marked this conversation as resolved.
Show resolved Hide resolved
let result = context.call_private_function(on_behalf_of, is_valid_selector, [message_hash])[0];
context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT);
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
}
Expand All @@ -24,7 +35,7 @@ pub fn assert_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAdd
// Assert that `on_behalf_of` have authorized the current call with a valid authentication witness
pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress) {
// message_hash = H(caller, contract_this, selector, args_hash)
let message_hash = pedersen_hash([context.msg_sender(), context.this_address(), context.selector(), context.args_hash],
let message_hash = pedersen_hash([context.msg_sender().to_field(), context.this_address().to_field(), context.selector().to_field(), context.args_hash],
GENERATOR_INDEX__SIGNATURE_PAYLOAD);
assert_valid_authwit(context, on_behalf_of, message_hash);
}
Expand All @@ -33,7 +44,8 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf
// docs:start:assert_valid_authwit_public
// Assert that `on_behalf_of` have authorized `message_hash` in a public context
pub fn assert_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress, message_hash: Field) {
let result = context.call_public_function(on_behalf_of.address, IS_VALID_PUBLIC_SELECTOR, [message_hash])[0];
let is_valid_public_selector = FunctionSelector::from_field(IS_VALID_PUBLIC_SELECTOR);
let result = context.call_public_function(on_behalf_of, is_valid_public_selector, [message_hash])[0];
context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT);
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
}
Expand All @@ -43,17 +55,17 @@ pub fn assert_valid_authwit_public(context: &mut PublicContext, on_behalf_of: Az
// Assert that `on_behalf_of` have authorized the current call in a public context
pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress) {
// message_hash = H(caller, contract_this, selector, args_hash)
let message_hash = pedersen_hash([context.msg_sender(), context.this_address(), context.selector(), context.args_hash],
let message_hash = pedersen_hash([context.msg_sender().to_field(), context.this_address().to_field(), context.selector().to_field(), context.args_hash],
GENERATOR_INDEX__SIGNATURE_PAYLOAD);
assert_valid_authwit_public(context, on_behalf_of, message_hash);
}
// docs:end:assert_current_call_valid_authwit_public

// docs:start:compute_authwit_message_hash
// Compute the message hash to be used by an authentication witness
pub fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field {
pub fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: FunctionSelector, args: [Field; N]) -> Field {
let args_hash = hash_args(args);
pedersen_hash([caller.address, target.address, selector, args_hash],
pedersen_hash([caller.to_field(), target.to_field(), selector.to_field(), args_hash],
GENERATOR_INDEX__SIGNATURE_PAYLOAD)
}
// docs:end:compute_authwit_message_hash
29 changes: 19 additions & 10 deletions yarn-project/aztec-nr/authwit/src/entrypoint.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
use dep::aztec::abi;
use dep::aztec::types::vec::BoundedVec;
use dep::aztec::hash::pedersen_hash;
use dep::aztec::context::PrivateContext;
use dep::aztec::private_call_stack_item::PrivateCallStackItem;
use dep::aztec::public_call_stack_item::PublicCallStackItem;
use dep::protocol_types::constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD;
use dep::protocol_types::{
abis::{
call_stack_item::{
PrivateCallStackItem,
PublicCallStackItem,
},
function_selector::FunctionSelector,
},
address::AztecAddress,
constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD,
hash::pedersen_hash,
};

global ACCOUNT_MAX_CALLS: Field = 4;
// 1 (ARGS_HASH) + 1 (FUNCTION_SELECTOR) + 1 (TARGET_ADDRESS) + 1 (IS_PUBLIC)
Expand All @@ -14,23 +22,23 @@ global FUNCTION_CALL_SIZE_IN_BYTES: Field = 97;

struct FunctionCall {
args_hash: Field,
function_selector: Field,
target_address: Field,
function_selector: FunctionSelector,
target_address: AztecAddress,
is_public: bool,
}

impl FunctionCall {
fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {
[self.args_hash, self.function_selector, self.target_address, self.is_public as Field]
[self.args_hash, self.function_selector.to_field(), self.target_address.to_field(), self.is_public as Field]
}

fn to_be_bytes(self) -> [u8; FUNCTION_CALL_SIZE_IN_BYTES] {
let mut bytes: [u8; FUNCTION_CALL_SIZE_IN_BYTES] = [0; FUNCTION_CALL_SIZE_IN_BYTES];
let args_hash_bytes = self.args_hash.to_be_bytes(32);
for i in 0..32 { bytes[i] = args_hash_bytes[i]; }
let function_selector_bytes = self.function_selector.to_be_bytes(32);
let function_selector_bytes = self.function_selector.to_field().to_be_bytes(32);
for i in 0..32 { bytes[i + 32] = function_selector_bytes[i]; }
let target_address_bytes = self.target_address.to_be_bytes(32);
let target_address_bytes = self.target_address.to_field().to_be_bytes(32);
for i in 0..32 { bytes[i + 64] = target_address_bytes[i]; }
bytes[96] = self.is_public as u8;
bytes
Expand All @@ -42,6 +50,7 @@ global ENTRYPOINT_PAYLOAD_SIZE: Field = 17;
// FUNCTION_CALL_SIZE_IN_BYTES * ACCOUNT_MAX_CALLS + 32
global ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES: Field = 420;

// Note: If you change the following struct you have to update default_entrypoint.ts
benesjan marked this conversation as resolved.
Show resolved Hide resolved
// docs:start:entrypoint-struct
struct EntrypointPayload {
function_calls: [FunctionCall; ACCOUNT_MAX_CALLS],
Expand Down Expand Up @@ -91,7 +100,7 @@ impl EntrypointPayload {
// docs:start:entrypoint-execute-calls
fn execute_calls(self, context: &mut PrivateContext) {
for call in self.function_calls {
if call.target_address != 0 {
if !call.target_address.is_zero() {
if call.is_public {
context.call_public_function_with_packed_args(
call.target_address, call.function_selector, call.args_hash
Expand Down
Loading