Skip to content

Commit fcb04a7

Browse files
authored
feat!: deduplicating circuit types + typing everything (AztecProtocol#3594)
Fixes AztecProtocol#3592 Fixes AztecProtocol#3059
1 parent bd5355f commit fcb04a7

File tree

165 files changed

+2105
-1832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+2105
-1832
lines changed

docs/docs/dev_docs/contracts/syntax/context.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ As shown in the snippet, the application context is made up of 4 main structures
4848

4949
First of all, the call context.
5050

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

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

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

7676
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.
7777

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

8080
### Contract Deployment Data
8181

8282
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.
8383

84-
#include_code contract-deployment-data /yarn-project/aztec-nr/aztec/src/abi.nr rust
84+
#include_code contract-deployment-data /yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr rust
8585

8686
### Private Global Variables
8787

yarn-project/acir-simulator/src/acvm/deserialize.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export function extractPrivateCircuitPublicInputs(
169169
witnessReader.readField(),
170170
witnessReader.readField(),
171171
witnessReader.readField(),
172-
Fr.ZERO,
172+
Fr.ZERO, // TODO(#3441)
173173
witnessReader.readField(),
174174
witnessReader.readField(),
175175
);
@@ -261,7 +261,7 @@ export function extractPublicCircuitPublicInputs(partialWitness: ACVMWitness, ac
261261
witnessReader.readField(),
262262
witnessReader.readField(),
263263
witnessReader.readField(),
264-
Fr.ZERO,
264+
Fr.ZERO, // TODO(#3441)
265265
witnessReader.readField(),
266266
witnessReader.readField(),
267267
);

yarn-project/aztec-node/src/aztec-node/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export class AztecNodeService implements AztecNode {
539539
roots[MerkleTreeId.CONTRACT_TREE],
540540
roots[MerkleTreeId.L1_TO_L2_MESSAGES_TREE],
541541
roots[MerkleTreeId.ARCHIVE],
542-
Fr.ZERO,
542+
Fr.ZERO, // TODO(#3441)
543543
roots[MerkleTreeId.PUBLIC_DATA_TREE],
544544
globalsHash,
545545
);

yarn-project/aztec-nr/address-note/Nargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ compiler_version = ">=0.18.0"
55
type = "lib"
66

77
[dependencies]
8-
aztec = { path = "../aztec" }
8+
aztec = { path = "../aztec" }
9+
protocol_types = { path = "../../../../noir-protocol-circuits/src/crates/types" }

yarn-project/aztec-nr/address-note/src/address_note.nr

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// docs:start:encrypted_import
22
use dep::aztec::log::emit_encrypted_log;
33
// docs:end:encrypted_import
4+
use dep::protocol_types::address::AztecAddress;
45
use dep::aztec::{
56
note::{
67
note_header::NoteHeader,
@@ -21,14 +22,14 @@ global ADDRESS_NOTE_LEN: Field = 3;
2122
// docs:start:address_note_def
2223
// Stores an address
2324
struct AddressNote {
24-
address: Field,
25-
owner: Field,
25+
address: AztecAddress,
26+
owner: AztecAddress,
2627
randomness: Field,
2728
header: NoteHeader,
2829
}
2930

3031
impl AddressNote {
31-
pub fn new(address: Field, owner: Field) -> Self {
32+
pub fn new(address: AztecAddress, owner: AztecAddress) -> Self {
3233
let randomness = rand();
3334
AddressNote {
3435
address,
@@ -41,13 +42,13 @@ impl AddressNote {
4142

4243

4344
pub fn serialize(self) -> [Field; ADDRESS_NOTE_LEN]{
44-
[self.address, self.owner, self.randomness]
45+
[self.address.to_field(), self.owner.to_field(), self.randomness]
4546
}
4647

4748
pub fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> Self {
4849
AddressNote {
49-
address: serialized_note[0],
50-
owner: serialized_note[1],
50+
address: AztecAddress::from_field(serialized_note[0]),
51+
owner: AztecAddress::from_field(serialized_note[1]),
5152
randomness: serialized_note[2],
5253
header: NoteHeader::empty(),
5354
}
+24-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
use dep::protocol_types::constants::{EMPTY_NULLIFIED_COMMITMENT, GENERATOR_INDEX__SIGNATURE_PAYLOAD};
2-
use dep::aztec::{
3-
context::{PrivateContext, PublicContext, Context},
4-
types::address::AztecAddress,
5-
abi::hash_args,
6-
hash::pedersen_hash,
1+
use dep::protocol_types::{
2+
abis::function_selector::FunctionSelector,
3+
address::AztecAddress,
4+
constants::{
5+
EMPTY_NULLIFIED_COMMITMENT,
6+
GENERATOR_INDEX__SIGNATURE_PAYLOAD,
7+
},
8+
hash::{
9+
hash_args,
10+
pedersen_hash,
11+
},
12+
};
13+
use dep::aztec::context::{
14+
PrivateContext,
15+
PublicContext,
16+
Context,
717
};
818

919
global IS_VALID_SELECTOR = 0xe86ab4ff;
@@ -14,7 +24,8 @@ global IS_VALID_PUBLIC_SELECTOR = 0xf3661153;
1424
// docs:start:assert_valid_authwit
1525
// Assert that `on_behalf_of` have authorized `message_hash` with a valid authentication witness
1626
pub fn assert_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress, message_hash: Field) {
17-
let result = context.call_private_function(on_behalf_of.address, IS_VALID_SELECTOR, [message_hash])[0];
27+
let is_valid_selector = FunctionSelector::from_field(IS_VALID_SELECTOR);
28+
let result = context.call_private_function(on_behalf_of, is_valid_selector, [message_hash])[0];
1829
context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT);
1930
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
2031
}
@@ -24,7 +35,7 @@ pub fn assert_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAdd
2435
// Assert that `on_behalf_of` have authorized the current call with a valid authentication witness
2536
pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress) {
2637
// message_hash = H(caller, contract_this, selector, args_hash)
27-
let message_hash = pedersen_hash([context.msg_sender(), context.this_address(), context.selector(), context.args_hash],
38+
let message_hash = pedersen_hash([context.msg_sender().to_field(), context.this_address().to_field(), context.selector().to_field(), context.args_hash],
2839
GENERATOR_INDEX__SIGNATURE_PAYLOAD);
2940
assert_valid_authwit(context, on_behalf_of, message_hash);
3041
}
@@ -33,7 +44,8 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf
3344
// docs:start:assert_valid_authwit_public
3445
// Assert that `on_behalf_of` have authorized `message_hash` in a public context
3546
pub fn assert_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress, message_hash: Field) {
36-
let result = context.call_public_function(on_behalf_of.address, IS_VALID_PUBLIC_SELECTOR, [message_hash])[0];
47+
let is_valid_public_selector = FunctionSelector::from_field(IS_VALID_PUBLIC_SELECTOR);
48+
let result = context.call_public_function(on_behalf_of, is_valid_public_selector, [message_hash])[0];
3749
context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT);
3850
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
3951
}
@@ -43,17 +55,17 @@ pub fn assert_valid_authwit_public(context: &mut PublicContext, on_behalf_of: Az
4355
// Assert that `on_behalf_of` have authorized the current call in a public context
4456
pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress) {
4557
// message_hash = H(caller, contract_this, selector, args_hash)
46-
let message_hash = pedersen_hash([context.msg_sender(), context.this_address(), context.selector(), context.args_hash],
58+
let message_hash = pedersen_hash([context.msg_sender().to_field(), context.this_address().to_field(), context.selector().to_field(), context.args_hash],
4759
GENERATOR_INDEX__SIGNATURE_PAYLOAD);
4860
assert_valid_authwit_public(context, on_behalf_of, message_hash);
4961
}
5062
// docs:end:assert_current_call_valid_authwit_public
5163

5264
// docs:start:compute_authwit_message_hash
5365
// Compute the message hash to be used by an authentication witness
54-
pub fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field {
66+
pub fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: FunctionSelector, args: [Field; N]) -> Field {
5567
let args_hash = hash_args(args);
56-
pedersen_hash([caller.address, target.address, selector, args_hash],
68+
pedersen_hash([caller.to_field(), target.to_field(), selector.to_field(), args_hash],
5769
GENERATOR_INDEX__SIGNATURE_PAYLOAD)
5870
}
5971
// docs:end:compute_authwit_message_hash

yarn-project/aztec-nr/authwit/src/entrypoint.nr

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
use dep::aztec::abi;
22
use dep::aztec::types::vec::BoundedVec;
3-
use dep::aztec::hash::pedersen_hash;
43
use dep::aztec::context::PrivateContext;
5-
use dep::aztec::private_call_stack_item::PrivateCallStackItem;
6-
use dep::aztec::public_call_stack_item::PublicCallStackItem;
7-
use dep::protocol_types::constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD;
4+
use dep::protocol_types::{
5+
abis::{
6+
call_stack_item::{
7+
PrivateCallStackItem,
8+
PublicCallStackItem,
9+
},
10+
function_selector::FunctionSelector,
11+
},
12+
address::AztecAddress,
13+
constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD,
14+
hash::pedersen_hash,
15+
};
816

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

1523
struct FunctionCall {
1624
args_hash: Field,
17-
function_selector: Field,
18-
target_address: Field,
25+
function_selector: FunctionSelector,
26+
target_address: AztecAddress,
1927
is_public: bool,
2028
}
2129

2230
impl FunctionCall {
2331
fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {
24-
[self.args_hash, self.function_selector, self.target_address, self.is_public as Field]
32+
[self.args_hash, self.function_selector.to_field(), self.target_address.to_field(), self.is_public as Field]
2533
}
2634

2735
fn to_be_bytes(self) -> [u8; FUNCTION_CALL_SIZE_IN_BYTES] {
2836
let mut bytes: [u8; FUNCTION_CALL_SIZE_IN_BYTES] = [0; FUNCTION_CALL_SIZE_IN_BYTES];
2937
let args_hash_bytes = self.args_hash.to_be_bytes(32);
3038
for i in 0..32 { bytes[i] = args_hash_bytes[i]; }
31-
let function_selector_bytes = self.function_selector.to_be_bytes(32);
39+
let function_selector_bytes = self.function_selector.to_field().to_be_bytes(32);
3240
for i in 0..32 { bytes[i + 32] = function_selector_bytes[i]; }
33-
let target_address_bytes = self.target_address.to_be_bytes(32);
41+
let target_address_bytes = self.target_address.to_field().to_be_bytes(32);
3442
for i in 0..32 { bytes[i + 64] = target_address_bytes[i]; }
3543
bytes[96] = self.is_public as u8;
3644
bytes
@@ -42,6 +50,7 @@ global ENTRYPOINT_PAYLOAD_SIZE: Field = 17;
4250
// FUNCTION_CALL_SIZE_IN_BYTES * ACCOUNT_MAX_CALLS + 32
4351
global ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES: Field = 420;
4452

53+
// Note: If you change the following struct you have to update default_entrypoint.ts
4554
// docs:start:entrypoint-struct
4655
struct EntrypointPayload {
4756
function_calls: [FunctionCall; ACCOUNT_MAX_CALLS],
@@ -91,7 +100,7 @@ impl EntrypointPayload {
91100
// docs:start:entrypoint-execute-calls
92101
fn execute_calls(self, context: &mut PrivateContext) {
93102
for call in self.function_calls {
94-
if call.target_address != 0 {
103+
if !call.target_address.is_zero() {
95104
if call.is_public {
96105
context.call_public_function_with_packed_args(
97106
call.target_address, call.function_selector, call.args_hash

0 commit comments

Comments
 (0)