Skip to content

Commit e612a53

Browse files
AztecBotTomAFrench
authored and
AztecBot
committed
feat: Sync from noir (#8526)
Automated pull of development from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE feat: implement LSP code action "Implement missing members" (noir-lang/noir#6020) fix: use module name as line after which we'll insert auto-import (noir-lang/noir#6025) feat: let `has_named_attribute` work for built-in attributes (noir-lang/noir#6024) feat: impl Hash and Eq on more comptime types (noir-lang/noir#6022) fix: Correctly print string tokens (noir-lang/noir#6021) chore: Remove RC tracking in mem2reg (noir-lang/noir#6019) feat: Add `Module::structs` (noir-lang/noir#6017) feat: format trait impl functions (noir-lang/noir#6016) fix: Try to move constant terms to one side for arithmetic generics (noir-lang/noir#6008) END_COMMIT_OVERRIDE --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
1 parent 2cee0fc commit e612a53

22 files changed

+286
-171
lines changed

address-note/src/address_note.nr

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,24 @@ impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
2727

2828
fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field {
2929
let secret = context.request_nsk_app(self.npk_m_hash);
30-
poseidon2_hash_with_separator([
30+
poseidon2_hash_with_separator(
31+
[
3132
note_hash_for_nullify,
3233
secret
3334
],
34-
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
35+
GENERATOR_INDEX__NOTE_NULLIFIER as Field
3536
)
3637
}
3738

3839
fn compute_nullifier_without_context(self) -> Field {
3940
let note_hash_for_nullify = compute_note_hash_for_nullify(self);
4041
let secret = get_nsk_app(self.npk_m_hash);
41-
poseidon2_hash_with_separator([
42+
poseidon2_hash_with_separator(
43+
[
4244
note_hash_for_nullify,
4345
secret
4446
],
45-
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
47+
GENERATOR_INDEX__NOTE_NULLIFIER as Field
4648
)
4749
}
4850
}

authwit/src/entrypoint/app.nr

+11-14
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,21 @@ struct AppPayload {
2222
// docs:end:app-payload-struct
2323

2424
impl Serialize<APP_PAYLOAD_SIZE> for AppPayload {
25-
// Serializes the entrypoint struct
26-
fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] {
27-
let mut fields: BoundedVec<Field, APP_PAYLOAD_SIZE> = BoundedVec::new();
28-
for call in self.function_calls {
29-
fields.extend_from_array(call.serialize());
25+
// Serializes the entrypoint struct
26+
fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] {
27+
let mut fields: BoundedVec<Field, APP_PAYLOAD_SIZE> = BoundedVec::new();
28+
for call in self.function_calls {
29+
fields.extend_from_array(call.serialize());
30+
}
31+
fields.push(self.nonce);
32+
fields.storage
3033
}
31-
fields.push(self.nonce);
32-
fields.storage
33-
}
3434
}
3535

3636
impl Hash for AppPayload {
37-
fn hash(self) -> Field {
38-
poseidon2_hash_with_separator(
39-
self.serialize(),
40-
GENERATOR_INDEX__SIGNATURE_PAYLOAD
41-
)
42-
}
37+
fn hash(self) -> Field {
38+
poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__SIGNATURE_PAYLOAD)
39+
}
4340
}
4441

4542
impl AppPayload {

authwit/src/entrypoint/fee.nr

+12-15
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,22 @@ struct FeePayload {
2222
// docs:end:fee-payload-struct
2323

2424
impl Serialize<FEE_PAYLOAD_SIZE> for FeePayload {
25-
// Serializes the entrypoint struct
26-
fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] {
27-
let mut fields: BoundedVec<Field, FEE_PAYLOAD_SIZE> = BoundedVec::new();
28-
for i in 0..MAX_FEE_FUNCTION_CALLS {
29-
fields.extend_from_array(self.function_calls[i].serialize());
25+
// Serializes the entrypoint struct
26+
fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] {
27+
let mut fields: BoundedVec<Field, FEE_PAYLOAD_SIZE> = BoundedVec::new();
28+
for i in 0..MAX_FEE_FUNCTION_CALLS {
29+
fields.extend_from_array(self.function_calls[i].serialize());
30+
}
31+
fields.push(self.nonce);
32+
fields.push(self.is_fee_payer as Field);
33+
fields.storage
3034
}
31-
fields.push(self.nonce);
32-
fields.push(self.is_fee_payer as Field);
33-
fields.storage
34-
}
3535
}
3636

3737
impl Hash for FeePayload {
38-
fn hash(self) -> Field {
39-
poseidon2_hash_with_separator(
40-
self.serialize(),
41-
GENERATOR_INDEX__FEE_PAYLOAD
42-
)
43-
}
38+
fn hash(self) -> Field {
39+
poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__FEE_PAYLOAD)
40+
}
4441
}
4542

4643
impl FeePayload {

authwit/src/entrypoint/function_call.nr

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ struct FunctionCall {
1414
}
1515

1616
impl Serialize<FUNCTION_CALL_SIZE> for FunctionCall {
17-
fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {
18-
[self.args_hash, self.function_selector.to_field(), self.target_address.to_field(), self.is_public as Field, self.is_static as Field]
19-
}
17+
fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {
18+
[
19+
self.args_hash, self.function_selector.to_field(), self.target_address.to_field(), self.is_public as Field, self.is_static as Field
20+
]
21+
}
2022
}
2123

2224
impl FunctionCall {

aztec/src/context/inputs/private_context_inputs.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Empty for PrivateContextInputs {
1616
call_context: CallContext::empty(),
1717
historical_header: Header::empty(),
1818
tx_context: TxContext::empty(),
19-
start_side_effect_counter: 0 as u32,
19+
start_side_effect_counter: 0 as u32
2020
}
2121
}
2222
}

aztec/src/context/inputs/public_context_inputs.nr

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ struct PublicContextInputs {
99

1010
impl Empty for PublicContextInputs {
1111
fn empty() -> Self {
12-
PublicContextInputs {
13-
calldata_length: 0,
14-
is_static_call: false
15-
}
12+
PublicContextInputs { calldata_length: 0, is_static_call: false }
1613
}
1714
}

aztec/src/encrypted_logs/incoming_body.nr

+34-16
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,37 @@ mod test {
6767
1
6868
}
6969

70-
fn get_header(self) -> NoteHeader { self.header}
70+
fn get_header(self) -> NoteHeader {
71+
self.header
72+
}
7173

72-
fn set_header(&mut self, header: NoteHeader) {self.header = header; }
74+
fn set_header(&mut self, header: NoteHeader) {
75+
self.header = header;
76+
}
7377

74-
fn compute_nullifier(_self: Self, _context: &mut PrivateContext, _note_hash_for_nullify: Field) -> Field {
78+
fn compute_nullifier(
79+
_self: Self,
80+
_context: &mut PrivateContext,
81+
_note_hash_for_nullify: Field
82+
) -> Field {
7583
1
7684
}
7785

7886
fn compute_nullifier_without_context(_self: Self) -> Field {
7987
1
8088
}
8189

82-
fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { [self.address.to_field(), self.owner.to_field(), self.randomness]}
90+
fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] {
91+
[self.address.to_field(), self.owner.to_field(), self.randomness]
92+
}
8393

8494
fn deserialize_content(fields: [Field; ADDRESS_NOTE_LEN]) -> Self {
85-
AddressNote { address: AztecAddress::from_field(fields[0]), owner: AztecAddress::from_field(fields[1]), randomness: fields[2], header: NoteHeader::empty() }
95+
AddressNote {
96+
address: AztecAddress::from_field(fields[0]),
97+
owner: AztecAddress::from_field(fields[1]),
98+
randomness: fields[2],
99+
header: NoteHeader::empty()
100+
}
86101
}
87102

88103
fn to_be_bytes(self, storage_slot: Field) -> [u8; ADDRESS_NOTE_BYTES_LEN] {
@@ -177,7 +192,10 @@ mod test {
177192

178193
impl EventInterface<TEST_EVENT_BYTES_LEN, TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS> for TestEvent {
179194
fn get_event_type_id() -> EventSelector {
180-
comptime { EventSelector::from_signature("TestEvent(Field,Field,Field)") }
195+
comptime
196+
{
197+
EventSelector::from_signature("TestEvent(Field,Field,Field)")
198+
}
181199
}
182200

183201
fn private_to_be_bytes(self, randomness: Field) -> [u8; TEST_EVENT_BYTES_LEN] {
@@ -204,24 +222,24 @@ mod test {
204222
}
205223

206224
fn to_be_bytes(self) -> [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] {
207-
let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS];
225+
let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS];
208226

209-
let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes();
227+
let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes();
210228

211-
for i in 0..32 {
212-
buffer[i] = event_type_id_bytes[i];
229+
for i in 0..32 {
230+
buffer[i] = event_type_id_bytes[i];
213231
}
214232

215-
let serialized_event = self.serialize();
233+
let serialized_event = self.serialize();
216234

217-
for i in 0..serialized_event.len() {
218-
let bytes: [u8; 32] = serialized_event[i].to_be_bytes();
219-
for j in 0..32 {
220-
buffer[32 + i * 32 + j] = bytes[j];
235+
for i in 0..serialized_event.len() {
236+
let bytes: [u8; 32] = serialized_event[i].to_be_bytes();
237+
for j in 0..32 {
238+
buffer[32 + i * 32 + j] = bytes[j];
221239
}
222240
}
223241

224-
buffer
242+
buffer
225243
}
226244

227245
fn emit<Env>(self, _emit: fn[Env](Self) -> ()) {

aztec/src/history/contract_inclusion.nr

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ trait ProveContractDeployment {
1010
impl ProveContractDeployment for Header {
1111
fn prove_contract_deployment(self, contract_address: AztecAddress) {
1212
// Compute deployment nullifier
13-
let nullifier = compute_siloed_nullifier(
14-
DEPLOYER_CONTRACT_ADDRESS,
15-
contract_address.to_field()
16-
);
13+
let nullifier = compute_siloed_nullifier(DEPLOYER_CONTRACT_ADDRESS, contract_address.to_field());
1714

1815
self.prove_nullifier_inclusion(nullifier);
1916
}
@@ -26,10 +23,7 @@ trait ProveContractNonDeployment {
2623
impl ProveContractNonDeployment for Header {
2724
fn prove_contract_non_deployment(self, contract_address: AztecAddress) {
2825
// Compute deployment nullifier
29-
let nullifier = compute_siloed_nullifier(
30-
DEPLOYER_CONTRACT_ADDRESS,
31-
contract_address.to_field()
32-
);
26+
let nullifier = compute_siloed_nullifier(DEPLOYER_CONTRACT_ADDRESS, contract_address.to_field());
3327

3428
// docs:start:prove_nullifier_non_inclusion
3529
self.prove_nullifier_non_inclusion(nullifier);

aztec/src/history/note_validity.nr

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ trait ProveNoteValidity {
77
}
88

99
impl ProveNoteValidity for Header {
10-
fn prove_note_validity<Note, N, M>(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface<N, M> {
10+
fn prove_note_validity<Note, N, M>(
11+
self,
12+
note: Note,
13+
context: &mut PrivateContext
14+
) where Note: NoteInterface<N, M> {
1115
self.prove_note_inclusion(note);
1216
self.prove_note_not_nullified(note, context);
1317
}

aztec/src/history/nullifier_inclusion.nr

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ trait ProveNoteIsNullified {
3737

3838
impl ProveNoteIsNullified for Header {
3939
// docs:start:prove_note_is_nullified
40-
fn prove_note_is_nullified<Note, N, M>(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface<N, M> {
40+
fn prove_note_is_nullified<Note, N, M>(
41+
self,
42+
note: Note,
43+
context: &mut PrivateContext
44+
) where Note: NoteInterface<N, M> {
4145
let nullifier = compute_siloed_nullifier(note, context);
4246

4347
self.prove_nullifier_inclusion(nullifier);

aztec/src/history/nullifier_non_inclusion.nr

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ trait ProveNoteNotNullified {
4646

4747
impl ProveNoteNotNullified for Header {
4848
// docs:start:prove_note_not_nullified
49-
fn prove_note_not_nullified<Note, N, M>(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface<N, M> {
49+
fn prove_note_not_nullified<Note, N, M>(
50+
self,
51+
note: Note,
52+
context: &mut PrivateContext
53+
) where Note: NoteInterface<N, M> {
5054
let nullifier = compute_siloed_nullifier(note, context);
5155

5256
self.prove_nullifier_non_inclusion(nullifier);

aztec/src/keys/public_keys.nr

+12-12
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ impl ToPoint for TpkM {
9191
impl Empty for PublicKeys {
9292
fn empty() -> Self {
9393
PublicKeys {
94-
npk_m : NpkM { inner: Point::empty() },
95-
ivpk_m : IvpkM { inner: Point::empty() },
96-
ovpk_m : OvpkM { inner: Point::empty() },
97-
tpk_m : TpkM { inner: Point::empty() }
94+
npk_m: NpkM { inner: Point::empty() },
95+
ivpk_m: IvpkM { inner: Point::empty() },
96+
ovpk_m: OvpkM { inner: Point::empty() },
97+
tpk_m: TpkM { inner: Point::empty() }
9898
}
9999
}
100100
}
101101

102102
impl Eq for PublicKeys {
103103
fn eq(self, other: PublicKeys) -> bool {
104-
( self.npk_m.inner == other.npk_m.inner ) &
105-
( self.ivpk_m.inner == other.ivpk_m.inner ) &
106-
( self.ovpk_m.inner == other.ovpk_m.inner ) &
107-
( self.tpk_m.inner == other.tpk_m.inner )
104+
(self.npk_m.inner == other.npk_m.inner)
105+
& (self.ivpk_m.inner == other.ivpk_m.inner)
106+
& (self.ovpk_m.inner == other.ovpk_m.inner)
107+
& (self.tpk_m.inner == other.tpk_m.inner)
108108
}
109109
}
110110

@@ -142,10 +142,10 @@ impl Serialize<PUBLIC_KEYS_LENGTH> for PublicKeys {
142142
impl Deserialize<PUBLIC_KEYS_LENGTH> for PublicKeys {
143143
fn deserialize(serialized: [Field; PUBLIC_KEYS_LENGTH]) -> PublicKeys {
144144
PublicKeys {
145-
npk_m: NpkM { inner: Point { x:serialized[0], y:serialized[1], is_infinite: serialized[2] as bool } },
146-
ivpk_m: IvpkM { inner: Point { x:serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } },
147-
ovpk_m: OvpkM { inner: Point { x:serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } },
148-
tpk_m: TpkM { inner: Point { x:serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } }
145+
npk_m: NpkM { inner: Point { x: serialized[0], y: serialized[1], is_infinite: serialized[2] as bool } },
146+
ivpk_m: IvpkM { inner: Point { x: serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } },
147+
ovpk_m: OvpkM { inner: Point { x: serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } },
148+
tpk_m: TpkM { inner: Point { x: serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } }
149149
}
150150
}
151151
}

aztec/src/note/note_header.nr

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ impl Empty for NoteHeader {
1717

1818
impl Eq for NoteHeader {
1919
fn eq(self, other: Self) -> bool {
20-
(self.contract_address == other.contract_address) &
21-
(self.nonce == other.nonce) &
22-
(self.storage_slot == other.storage_slot)&
23-
(self.note_hash_counter == other.note_hash_counter)
20+
(self.contract_address == other.contract_address)
21+
& (self.nonce == other.nonce)
22+
& (self.storage_slot == other.storage_slot)
23+
& (self.note_hash_counter == other.note_hash_counter)
2424
}
2525
}
2626

@@ -38,6 +38,8 @@ impl Serialize<NOTE_HEADER_LENGTH> for NoteHeader {
3838
// Note: If you change this function don't forget to update implementations of Serialize trait for notes.
3939
// (Serialize trait needs to be implemented for a note when it's passed as an argument to a contract function
4040
// --> then it's used when computing args hash.)
41-
[self.contract_address.to_field(), self.nonce, self.storage_slot, self.note_hash_counter as Field]
41+
[
42+
self.contract_address.to_field(), self.nonce, self.storage_slot, self.note_hash_counter as Field
43+
]
4244
}
4345
}

0 commit comments

Comments
 (0)