Skip to content

Commit

Permalink
feat: Sync from noir (#8526)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
AztecBot and TomAFrench authored Sep 13, 2024
1 parent ceda361 commit cb20e07
Show file tree
Hide file tree
Showing 213 changed files with 4,204 additions and 2,361 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21425dedcc31287431a4a25589d52d5397e974bc
9bf2dcbf166f9ffd97c369c0de3d95329c850d47
10 changes: 6 additions & 4 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {

fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field {
let secret = context.request_nsk_app(self.npk_m_hash);
poseidon2_hash_with_separator([
poseidon2_hash_with_separator(
[
note_hash_for_nullify,
secret
],
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field
)
}

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_nullify(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash_with_separator([
poseidon2_hash_with_separator(
[
note_hash_for_nullify,
secret
],
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field
)
}
}
Expand Down
25 changes: 11 additions & 14 deletions noir-projects/aztec-nr/authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@ struct AppPayload {
// docs:end:app-payload-struct

impl Serialize<APP_PAYLOAD_SIZE> for AppPayload {
// Serializes the entrypoint struct
fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, APP_PAYLOAD_SIZE> = BoundedVec::new();
for call in self.function_calls {
fields.extend_from_array(call.serialize());
// Serializes the entrypoint struct
fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, APP_PAYLOAD_SIZE> = BoundedVec::new();
for call in self.function_calls {
fields.extend_from_array(call.serialize());
}
fields.push(self.nonce);
fields.storage
}
fields.push(self.nonce);
fields.storage
}
}

impl Hash for AppPayload {
fn hash(self) -> Field {
poseidon2_hash_with_separator(
self.serialize(),
GENERATOR_INDEX__SIGNATURE_PAYLOAD
)
}
fn hash(self) -> Field {
poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__SIGNATURE_PAYLOAD)
}
}

impl AppPayload {
Expand Down
27 changes: 12 additions & 15 deletions noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,22 @@ struct FeePayload {
// docs:end:fee-payload-struct

impl Serialize<FEE_PAYLOAD_SIZE> for FeePayload {
// Serializes the entrypoint struct
fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, FEE_PAYLOAD_SIZE> = BoundedVec::new();
for i in 0..MAX_FEE_FUNCTION_CALLS {
fields.extend_from_array(self.function_calls[i].serialize());
// Serializes the entrypoint struct
fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] {
let mut fields: BoundedVec<Field, FEE_PAYLOAD_SIZE> = BoundedVec::new();
for i in 0..MAX_FEE_FUNCTION_CALLS {
fields.extend_from_array(self.function_calls[i].serialize());
}
fields.push(self.nonce);
fields.push(self.is_fee_payer as Field);
fields.storage
}
fields.push(self.nonce);
fields.push(self.is_fee_payer as Field);
fields.storage
}
}

impl Hash for FeePayload {
fn hash(self) -> Field {
poseidon2_hash_with_separator(
self.serialize(),
GENERATOR_INDEX__FEE_PAYLOAD
)
}
fn hash(self) -> Field {
poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__FEE_PAYLOAD)
}
}

impl FeePayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ struct FunctionCall {
}

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

impl FunctionCall {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Empty for PrivateContextInputs {
call_context: CallContext::empty(),
historical_header: Header::empty(),
tx_context: TxContext::empty(),
start_side_effect_counter: 0 as u32,
start_side_effect_counter: 0 as u32
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ struct PublicContextInputs {

impl Empty for PublicContextInputs {
fn empty() -> Self {
PublicContextInputs {
calldata_length: 0,
is_static_call: false
}
PublicContextInputs { calldata_length: 0, is_static_call: false }
}
}
50 changes: 34 additions & 16 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,37 @@ mod test {
1
}

fn get_header(self) -> NoteHeader { self.header}
fn get_header(self) -> NoteHeader {
self.header
}

fn set_header(&mut self, header: NoteHeader) {self.header = header; }
fn set_header(&mut self, header: NoteHeader) {
self.header = header;
}

fn compute_nullifier(_self: Self, _context: &mut PrivateContext, _note_hash_for_nullify: Field) -> Field {
fn compute_nullifier(
_self: Self,
_context: &mut PrivateContext,
_note_hash_for_nullify: Field
) -> Field {
1
}

fn compute_nullifier_without_context(_self: Self) -> Field {
1
}

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

fn deserialize_content(fields: [Field; ADDRESS_NOTE_LEN]) -> Self {
AddressNote { address: AztecAddress::from_field(fields[0]), owner: AztecAddress::from_field(fields[1]), randomness: fields[2], header: NoteHeader::empty() }
AddressNote {
address: AztecAddress::from_field(fields[0]),
owner: AztecAddress::from_field(fields[1]),
randomness: fields[2],
header: NoteHeader::empty()
}
}

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

impl EventInterface<TEST_EVENT_BYTES_LEN, TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS> for TestEvent {
fn get_event_type_id() -> EventSelector {
comptime { EventSelector::from_signature("TestEvent(Field,Field,Field)") }
comptime
{
EventSelector::from_signature("TestEvent(Field,Field,Field)")
}
}

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

fn to_be_bytes(self) -> [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] {
let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS];
let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS];

let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes();
let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes();

for i in 0..32 {
buffer[i] = event_type_id_bytes[i];
for i in 0..32 {
buffer[i] = event_type_id_bytes[i];
}

let serialized_event = self.serialize();
let serialized_event = self.serialize();

for i in 0..serialized_event.len() {
let bytes: [u8; 32] = serialized_event[i].to_be_bytes();
for j in 0..32 {
buffer[32 + i * 32 + j] = bytes[j];
for i in 0..serialized_event.len() {
let bytes: [u8; 32] = serialized_event[i].to_be_bytes();
for j in 0..32 {
buffer[32 + i * 32 + j] = bytes[j];
}
}

buffer
buffer
}

fn emit<Env>(self, _emit: fn[Env](Self) -> ()) {
Expand Down
10 changes: 2 additions & 8 deletions noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ trait ProveContractDeployment {
impl ProveContractDeployment for Header {
fn prove_contract_deployment(self, contract_address: AztecAddress) {
// Compute deployment nullifier
let nullifier = compute_siloed_nullifier(
DEPLOYER_CONTRACT_ADDRESS,
contract_address.to_field()
);
let nullifier = compute_siloed_nullifier(DEPLOYER_CONTRACT_ADDRESS, contract_address.to_field());

self.prove_nullifier_inclusion(nullifier);
}
Expand All @@ -26,10 +23,7 @@ trait ProveContractNonDeployment {
impl ProveContractNonDeployment for Header {
fn prove_contract_non_deployment(self, contract_address: AztecAddress) {
// Compute deployment nullifier
let nullifier = compute_siloed_nullifier(
DEPLOYER_CONTRACT_ADDRESS,
contract_address.to_field()
);
let nullifier = compute_siloed_nullifier(DEPLOYER_CONTRACT_ADDRESS, contract_address.to_field());

// docs:start:prove_nullifier_non_inclusion
self.prove_nullifier_non_inclusion(nullifier);
Expand Down
6 changes: 5 additions & 1 deletion noir-projects/aztec-nr/aztec/src/history/note_validity.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ trait ProveNoteValidity {
}

impl ProveNoteValidity for Header {
fn prove_note_validity<Note, N, M>(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface<N, M> {
fn prove_note_validity<Note, N, M>(
self,
note: Note,
context: &mut PrivateContext
) where Note: NoteInterface<N, M> {
self.prove_note_inclusion(note);
self.prove_note_not_nullified(note, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ trait ProveNoteIsNullified {

impl ProveNoteIsNullified for Header {
// docs:start:prove_note_is_nullified
fn prove_note_is_nullified<Note, N, M>(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface<N, M> {
fn prove_note_is_nullified<Note, N, M>(
self,
note: Note,
context: &mut PrivateContext
) where Note: NoteInterface<N, M> {
let nullifier = compute_siloed_nullifier(note, context);

self.prove_nullifier_inclusion(nullifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ trait ProveNoteNotNullified {

impl ProveNoteNotNullified for Header {
// docs:start:prove_note_not_nullified
fn prove_note_not_nullified<Note, N, M>(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface<N, M> {
fn prove_note_not_nullified<Note, N, M>(
self,
note: Note,
context: &mut PrivateContext
) where Note: NoteInterface<N, M> {
let nullifier = compute_siloed_nullifier(note, context);

self.prove_nullifier_non_inclusion(nullifier);
Expand Down
24 changes: 12 additions & 12 deletions noir-projects/aztec-nr/aztec/src/keys/public_keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ impl ToPoint for TpkM {
impl Empty for PublicKeys {
fn empty() -> Self {
PublicKeys {
npk_m : NpkM { inner: Point::empty() },
ivpk_m : IvpkM { inner: Point::empty() },
ovpk_m : OvpkM { inner: Point::empty() },
tpk_m : TpkM { inner: Point::empty() }
npk_m: NpkM { inner: Point::empty() },
ivpk_m: IvpkM { inner: Point::empty() },
ovpk_m: OvpkM { inner: Point::empty() },
tpk_m: TpkM { inner: Point::empty() }
}
}
}

impl Eq for PublicKeys {
fn eq(self, other: PublicKeys) -> bool {
( self.npk_m.inner == other.npk_m.inner ) &
( self.ivpk_m.inner == other.ivpk_m.inner ) &
( self.ovpk_m.inner == other.ovpk_m.inner ) &
( self.tpk_m.inner == other.tpk_m.inner )
(self.npk_m.inner == other.npk_m.inner)
& (self.ivpk_m.inner == other.ivpk_m.inner)
& (self.ovpk_m.inner == other.ovpk_m.inner)
& (self.tpk_m.inner == other.tpk_m.inner)
}
}

Expand Down Expand Up @@ -142,10 +142,10 @@ impl Serialize<PUBLIC_KEYS_LENGTH> for PublicKeys {
impl Deserialize<PUBLIC_KEYS_LENGTH> for PublicKeys {
fn deserialize(serialized: [Field; PUBLIC_KEYS_LENGTH]) -> PublicKeys {
PublicKeys {
npk_m: NpkM { inner: Point { x:serialized[0], y:serialized[1], is_infinite: serialized[2] as bool } },
ivpk_m: IvpkM { inner: Point { x:serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } },
ovpk_m: OvpkM { inner: Point { x:serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } },
tpk_m: TpkM { inner: Point { x:serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } }
npk_m: NpkM { inner: Point { x: serialized[0], y: serialized[1], is_infinite: serialized[2] as bool } },
ivpk_m: IvpkM { inner: Point { x: serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } },
ovpk_m: OvpkM { inner: Point { x: serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } },
tpk_m: TpkM { inner: Point { x: serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } }
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions noir-projects/aztec-nr/aztec/src/note/note_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ impl Empty for NoteHeader {

impl Eq for NoteHeader {
fn eq(self, other: Self) -> bool {
(self.contract_address == other.contract_address) &
(self.nonce == other.nonce) &
(self.storage_slot == other.storage_slot)&
(self.note_hash_counter == other.note_hash_counter)
(self.contract_address == other.contract_address)
& (self.nonce == other.nonce)
& (self.storage_slot == other.storage_slot)
& (self.note_hash_counter == other.note_hash_counter)
}
}

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

0 comments on commit cb20e07

Please sign in to comment.