From f5f44ed2cafebb5c5eae24ea0c80145a8a1a606c Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 26 Feb 2025 11:59:21 +0000 Subject: [PATCH] refactor: renaming Note generic as NOTE --- .../default_aes128/note.nr | 36 ++++++------ .../aztec/src/history/note_inclusion.nr | 10 ++-- .../aztec/src/history/note_validity.nr | 12 ++-- .../aztec/src/history/nullifier_inclusion.nr | 12 ++-- .../src/history/nullifier_non_inclusion.nr | 12 ++-- .../aztec-nr/aztec/src/note/lifecycle.nr | 24 ++++---- .../aztec-nr/aztec/src/note/note_emission.nr | 18 +++--- .../aztec/src/note/note_getter/mod.nr | 56 +++++++++---------- .../aztec/src/note/note_getter_options.nr | 30 +++++----- .../aztec/src/note/note_viewer_options.nr | 8 +-- .../aztec-nr/aztec/src/note/utils.nr | 22 ++++---- .../aztec-nr/aztec/src/oracle/notes.nr | 10 ++-- .../aztec/src/state_vars/private_immutable.nr | 20 +++---- .../aztec/src/state_vars/private_mutable.nr | 24 ++++---- .../aztec/src/state_vars/private_set.nr | 28 +++++----- .../src/test/helpers/test_environment.nr | 10 ++-- .../spam_contract/src/types/balance_set.nr | 34 +++++------ .../src/types/balances_map.nr | 34 +++++------ 18 files changed, 200 insertions(+), 200 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/log_assembly_strategies/default_aes128/note.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/log_assembly_strategies/default_aes128/note.nr index 7143c544338..eba774c5687 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/log_assembly_strategies/default_aes128/note.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/log_assembly_strategies/default_aes128/note.nr @@ -213,19 +213,19 @@ fn assert_note_exists(context: PrivateContext, note_hash_counter: u3 /// note_id and the storage_slot) to be converted into bytes, because the aes function /// operates on bytes; not fields. /// NB: The extra `+ 64` bytes is for the note_id and the storage_slot of the note: -fn compute_note_plaintext_for_this_strategy( - note: Note, +fn compute_note_plaintext_for_this_strategy( + note: NOTE, storage_slot: Field, ) -> [u8; N * 32 + 64] where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { let packed_note = note.pack(); let storage_slot_bytes: [u8; 32] = storage_slot.to_be_bytes(); // TODO(#10952): The following can be reduced to 7 bits - let note_type_id_bytes: [u8; 32] = Note::get_id().to_be_bytes(); + let note_type_id_bytes: [u8; 32] = NOTE::get_id().to_be_bytes(); // We combine all the bytes into plaintext_bytes: let mut plaintext_bytes: [u8; N * 32 + 64] = [0; N * 32 + 64]; @@ -244,15 +244,15 @@ where plaintext_bytes } -fn compute_log( +fn compute_log( context: PrivateContext, - note: Note, + note: NOTE, storage_slot: Field, recipient: AztecAddress, sender: AztecAddress, ) -> [Field; PRIVATE_LOG_SIZE_IN_FIELDS] where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { // ***************************************************************************** // Compute the shared secret @@ -408,15 +408,15 @@ where final_log } -unconstrained fn compute_log_unconstrained( +unconstrained fn compute_log_unconstrained( context: PrivateContext, - note: Note, + note: NOTE, storage_slot: Field, recipient: AztecAddress, sender: AztecAddress, ) -> [Field; PRIVATE_LOG_SIZE_IN_FIELDS] where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { compute_log(context, note, storage_slot, recipient, sender) } @@ -424,16 +424,16 @@ where // This function seems to be affected by the following Noir bug: // https://github.com/noir-lang/noir/issues/5771 // If you get weird behavior it might be because of it. -pub fn encode_and_encrypt_note( +pub fn encode_and_encrypt_note( context: &mut PrivateContext, recipient: AztecAddress, // We need this because to compute a tagging secret, we require a sender: sender: AztecAddress, -) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission) -> () +) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission) -> () where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { - |e: NoteEmission| { + |e: NoteEmission| { let note = e.note; let storage_slot = e.storage_slot; let note_hash_counter = e.note_hash_counter; @@ -447,16 +447,16 @@ where // Important note: this function -- although called "unconstrained" -- the // function is not labelled as `unconstrained`, because we pass a reference to the // context. -pub fn encode_and_encrypt_note_unconstrained( +pub fn encode_and_encrypt_note_unconstrained( context: &mut PrivateContext, recipient: AztecAddress, // We need this because to compute a tagging secret, we require a sender: sender: AztecAddress, -) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission) -> () +) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission) -> () where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { - |e: NoteEmission| { + |e: NoteEmission| { let note = e.note; let storage_slot = e.storage_slot; let note_hash_counter = e.note_hash_counter; diff --git a/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr index cf2cb4da0d1..42a0cb43997 100644 --- a/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr @@ -10,19 +10,19 @@ use crate::{ }; trait ProveNoteInclusion { - fn prove_note_inclusion( + fn prove_note_inclusion( header: BlockHeader, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, ) where - Note: NoteHash; + NOTE: NoteHash; } impl ProveNoteInclusion for BlockHeader { - fn prove_note_inclusion(self, retrieved_note: RetrievedNote, storage_slot: Field) + fn prove_note_inclusion(self, retrieved_note: RetrievedNote, storage_slot: Field) where - Note: NoteHash, + NOTE: NoteHash, { let note_hash = compute_note_hash_for_nullify(retrieved_note, storage_slot); diff --git a/noir-projects/aztec-nr/aztec/src/history/note_validity.nr b/noir-projects/aztec-nr/aztec/src/history/note_validity.nr index 50e0be5bcf4..46398d14295 100644 --- a/noir-projects/aztec-nr/aztec/src/history/note_validity.nr +++ b/noir-projects/aztec-nr/aztec/src/history/note_validity.nr @@ -6,25 +6,25 @@ use crate::{ use dep::protocol_types::block_header::BlockHeader; trait ProveNoteValidity { - fn prove_note_validity( + fn prove_note_validity( header: BlockHeader, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) where - Note: NoteHash; + NOTE: NoteHash; } impl ProveNoteValidity for BlockHeader { - fn prove_note_validity( + fn prove_note_validity( self, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) where - Note: NoteHash, + NOTE: NoteHash, { self.prove_note_inclusion(retrieved_note, storage_slot); self.prove_note_not_nullified(retrieved_note, storage_slot, context); diff --git a/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr index 5d14bf624af..ee2870a88e3 100644 --- a/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr @@ -42,26 +42,26 @@ impl ProveNullifierInclusion for BlockHeader { } trait ProveNoteIsNullified { - fn prove_note_is_nullified( + fn prove_note_is_nullified( header: BlockHeader, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) where - Note: NoteHash; + NOTE: NoteHash; } impl ProveNoteIsNullified for BlockHeader { // docs:start:prove_note_is_nullified - fn prove_note_is_nullified( + fn prove_note_is_nullified( self, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) where - Note: NoteHash, + NOTE: NoteHash, { let nullifier = compute_siloed_note_nullifier(retrieved_note, storage_slot, context); diff --git a/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr index 2c2e88abdc0..5cc2d95b52f 100644 --- a/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr @@ -55,26 +55,26 @@ impl ProveNullifierNonInclusion for BlockHeader { } trait ProveNoteNotNullified { - fn prove_note_not_nullified( + fn prove_note_not_nullified( header: BlockHeader, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) where - Note: NoteHash; + NOTE: NoteHash; } impl ProveNoteNotNullified for BlockHeader { // docs:start:prove_note_not_nullified - fn prove_note_not_nullified( + fn prove_note_not_nullified( self, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) where - Note: NoteHash, + NOTE: NoteHash, { let nullifier = compute_siloed_note_nullifier(retrieved_note, storage_slot, context); diff --git a/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr b/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr index f4569bcef91..18097d5ffe7 100644 --- a/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr +++ b/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr @@ -8,22 +8,22 @@ use crate::note::{ use crate::oracle::notes::notify_created_note; use protocol_types::traits::Packable; -pub fn create_note( +pub fn create_note( context: &mut PrivateContext, storage_slot: Field, - note: Note, -) -> NoteEmission + note: NOTE, +) -> NoteEmission where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { let note_hash_counter = context.side_effect_counter; let note_hash = note.compute_note_hash(storage_slot); - let packed_note = Note::pack(note); + let packed_note = NOTE::pack(note); notify_created_note( storage_slot, - Note::get_id(), + NOTE::get_id(), packed_note, note_hash, note_hash_counter, @@ -35,13 +35,13 @@ where } // Note: This function is currently totally unused. -pub fn destroy_note( +pub fn destroy_note( context: &mut PrivateContext, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, storage_slot: Field, ) where - Note: NoteHash, + NOTE: NoteHash, { let note_hash_for_read_request = compute_note_hash_for_read_request(retrieved_note, storage_slot); @@ -49,13 +49,13 @@ where destroy_note_unsafe(context, retrieved_note, note_hash_for_read_request) } -pub fn destroy_note_unsafe( +pub fn destroy_note_unsafe( context: &mut PrivateContext, - retrieved_note: RetrievedNote, + retrieved_note: RetrievedNote, note_hash_for_read_request: Field, ) where - Note: NoteHash, + NOTE: NoteHash, { let note_hash_for_nullify = compute_note_hash_for_nullify_from_read_request(retrieved_note, note_hash_for_read_request); diff --git a/noir-projects/aztec-nr/aztec/src/note/note_emission.nr b/noir-projects/aztec-nr/aztec/src/note/note_emission.nr index 6f92bfbc95f..289e27b791d 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_emission.nr @@ -2,14 +2,14 @@ * A note emission struct containing the information required for emitting a note. * The exact `emit` logic is passed in by the application code */ -pub struct NoteEmission { - pub note: Note, +pub struct NoteEmission { + pub note: NOTE, pub storage_slot: Field, pub note_hash_counter: u32, // a note_hash_counter of 0 means settled } -impl NoteEmission { - pub fn new(note: Note, storage_slot: Field, note_hash_counter: u32) -> Self { +impl NoteEmission { + pub fn new(note: NOTE, storage_slot: Field, note_hash_counter: u32) -> Self { Self { note, storage_slot, note_hash_counter } } @@ -28,16 +28,16 @@ impl NoteEmission { * and this allows us to keep the same API for emission in both cases (e.g. inserting * a change note in a token's transfer function only when there is "change" left). */ -pub struct OuterNoteEmission { - emission: Option>, +pub struct OuterNoteEmission { + emission: Option>, } -impl OuterNoteEmission { - pub fn new(emission: Option>) -> Self { +impl OuterNoteEmission { + pub fn new(emission: Option>) -> Self { Self { emission } } - pub fn emit(self, _emit: fn[Env](NoteEmission) -> ()) { + pub fn emit(self, _emit: fn[Env](NoteEmission) -> ()) { if self.emission.is_some() { _emit(self.emission.unwrap()); } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr index 54d8e8b47bd..6323e946e6e 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr @@ -71,16 +71,16 @@ fn check_notes_order( } } -pub fn get_note( +pub fn get_note( context: &mut PrivateContext, storage_slot: Field, -) -> (RetrievedNote, Field) +) -> (RetrievedNote, Field) where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { // Safety: Constraining that we got a valid note from the oracle is fairly straightforward: all we need to do // is check that the metadata is correct, and that the note exists. - let retrieved_note = unsafe { get_note_internal::(storage_slot) }; + let retrieved_note = unsafe { get_note_internal::(storage_slot) }; // For settled notes, the contract address is implicitly checked since the hash returned from // `compute_note_hash_for_read_request` is siloed and kernels verify the siloing during note read request @@ -99,13 +99,13 @@ where (retrieved_note, note_hash_for_read_request) } -pub fn get_notes( +pub fn get_notes( context: &mut PrivateContext, storage_slot: Field, - options: NoteGetterOptions, - ) -> (BoundedVec, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL>, BoundedVec) + options: NoteGetterOptions, + ) -> (BoundedVec, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL>, BoundedVec) where - Note: NoteType + NoteHash + Eq + Packable, + NOTE: NoteType + NoteHash + Eq + Packable, { // Safety: The notes are constrained below. let opt_notes = unsafe { get_notes_internal(storage_slot, options) }; @@ -115,22 +115,22 @@ where constrain_get_notes_internal(context, storage_slot, opt_notes, options) } -unconstrained fn apply_preprocessor( - notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], - preprocessor: fn([Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], +unconstrained fn apply_preprocessor( + notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + preprocessor: fn([Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], preprocessor_args: PREPROCESSOR_ARGS, -) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] { +) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] { preprocessor(notes, preprocessor_args) } -fn constrain_get_notes_internal( +fn constrain_get_notes_internal( context: &mut PrivateContext, storage_slot: Field, - opt_notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], - options: NoteGetterOptions, - ) -> (BoundedVec, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL>, BoundedVec) + opt_notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + options: NoteGetterOptions, + ) -> (BoundedVec, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL>, BoundedVec) where - Note: NoteType + NoteHash + Eq + Packable, + NOTE: NoteType + NoteHash + Eq + Packable, { // The filter is applied first to avoid pushing note read requests for notes we're not interested in. Note that // while the filter function can technically mutate the notes (as opposed to simply removing some), the private @@ -140,7 +140,7 @@ where let filter_args = options.filter_args; let filtered_notes = filter_fn(opt_notes, filter_args); - let notes: BoundedVec, 16> = crate::utils::array::collapse(filtered_notes); + let notes: BoundedVec, 16> = crate::utils::array::collapse(filtered_notes); let mut note_hashes: BoundedVec = BoundedVec::new(); @@ -181,9 +181,9 @@ where (notes, note_hashes) } -unconstrained fn get_note_internal(storage_slot: Field) -> RetrievedNote +unconstrained fn get_note_internal(storage_slot: Field) -> RetrievedNote where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { let placeholder_note = [Option::none()]; let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH]; @@ -210,12 +210,12 @@ where .expect(f"Failed to get a note") // Notice: we don't allow dummies to be returned from get_note (singular). } -unconstrained fn get_notes_internal( +unconstrained fn get_notes_internal( storage_slot: Field, - options: NoteGetterOptions, -) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] + options: NoteGetterOptions, +) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { // This function simply performs some transformations from NoteGetterOptions into the types required by the oracle. let (num_selects, select_by_indexes, select_by_offsets, select_by_lengths, select_values, select_comparators, sort_by_indexes, sort_by_offsets, sort_by_lengths, sort_order) = @@ -247,12 +247,12 @@ where apply_preprocessor(opt_notes, options.preprocessor, options.preprocessor_args) } -pub unconstrained fn view_notes( +pub unconstrained fn view_notes( storage_slot: Field, - options: NoteViewerOptions, -) -> BoundedVec + options: NoteViewerOptions, +) -> BoundedVec where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { let (num_selects, select_by_indexes, select_by_offsets, select_by_lengths, select_values, select_comparators, sort_by_indexes, sort_by_offsets, sort_by_lengths, sort_order) = flatten_options(options.selects, options.sorts); diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr index e161da90621..4dcc0eb8ae6 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter_options.nr @@ -55,24 +55,24 @@ pub global NoteStatus: NoteStatusEnum = NoteStatusEnum { }; // This is the default filter and preprocessor, which does nothing -fn return_all_notes( - notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], +fn return_all_notes( + notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], _p: Field, -) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] { +) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] { notes } // docs:start:NoteGetterOptions -pub struct NoteGetterOptions { +pub struct NoteGetterOptions { pub selects: BoundedVec, N>, pub sorts: BoundedVec, N>, pub limit: u32, pub offset: u32, // Preprocessor and filter functions are used to filter notes. The preprocessor is applied before the filter and // unlike filter it is applied in an unconstrained context. - pub preprocessor: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + pub preprocessor: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], pub preprocessor_args: PREPROCESSOR_ARGS, - pub filter: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + pub filter: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], pub filter_args: FILTER_ARGS, pub status: u8, } @@ -84,7 +84,7 @@ pub struct NoteGetterOptions { // `selects` to specify fields, `sorts` to establish sorting criteria, `offset` to skip items, and `limit` to cap // the result size. // And finally, a custom preprocessor and filter to refine the outcome further. -impl NoteGetterOptions { +impl NoteGetterOptions { // This method adds a `Select` criterion to the options. // It takes a property_selector indicating which field to select, // a value representing the specific value to match in that field, and @@ -135,9 +135,9 @@ impl NoteGetterOptions NoteGetterOptions +impl NoteGetterOptions where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { // This function initializes a NoteGetterOptions that simply returns the maximum number of notes allowed in a call. pub fn new() -> Self { @@ -155,15 +155,15 @@ where } } -impl NoteGetterOptions +impl NoteGetterOptions where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { // This function initializes a NoteGetterOptions with a preprocessor, which takes the notes returned from // the database and preprocessor_args as its parameters. // `preprocessor_args` allows you to provide additional data or context to the custom preprocessor. pub fn with_preprocessor( - preprocessor: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + preprocessor: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], preprocessor_args: PREPROCESSOR_ARGS, ) -> Self { Self { @@ -180,15 +180,15 @@ where } } -impl NoteGetterOptions +impl NoteGetterOptions where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { // This function initializes a NoteGetterOptions with a filter, which takes // the notes returned from the database and filter_args as its parameters. // `filter_args` allows you to provide additional data or context to the custom filter. pub fn with_filter( - filter: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + filter: fn([Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], filter_args: FILTER_ARGS, ) -> Self { Self { diff --git a/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr b/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr index 5150e528472..2c10b3b5b09 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr @@ -5,7 +5,7 @@ use dep::protocol_types::traits::{Packable, ToField}; use std::option::Option; // docs:start:NoteViewerOptions -pub struct NoteViewerOptions { +pub struct NoteViewerOptions { pub selects: BoundedVec, N>, pub sorts: BoundedVec, N>, pub limit: u32, @@ -14,10 +14,10 @@ pub struct NoteViewerOptions { } // docs:end:NoteViewerOptions -impl NoteViewerOptions { - pub fn new() -> NoteViewerOptions +impl NoteViewerOptions { + pub fn new() -> NoteViewerOptions where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { NoteViewerOptions { selects: BoundedVec::new(), diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index a8bc843dfd9..5b86dcfcec2 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -8,12 +8,12 @@ use dep::protocol_types::hash::{ }; /// Returns the note hash that must be used to issue a private kernel read request for a note. -pub fn compute_note_hash_for_read_request( - retrieved_note: RetrievedNote, +pub fn compute_note_hash_for_read_request( + retrieved_note: RetrievedNote, storage_slot: Field, ) -> Field where - Note: NoteHash, + NOTE: NoteHash, { let note_hash = retrieved_note.note.compute_note_hash(storage_slot); @@ -34,12 +34,12 @@ where } /// Returns the note hash that must be used to compute a note's nullifier. -pub fn compute_note_hash_for_nullify( - retrieved_note: RetrievedNote, +pub fn compute_note_hash_for_nullify( + retrieved_note: RetrievedNote, storage_slot: Field, ) -> Field where - Note: NoteHash, + NOTE: NoteHash, { compute_note_hash_for_nullify_from_read_request( retrieved_note, @@ -50,8 +50,8 @@ where /// Same as `compute_note_hash_for_nullify`, except it takes the note hash used in a read request (i.e. what /// `compute_note_hash_for_read_request` would return). This is useful in scenarios where that hash has already been /// computed to reduce constraints by reusing this value. -pub fn compute_note_hash_for_nullify_from_read_request( - retrieved_note: RetrievedNote, +pub fn compute_note_hash_for_nullify_from_read_request( + retrieved_note: RetrievedNote, note_hash_for_read_request: Field, ) -> Field { // There is just one instance in which the note hash for nullification does not match the note hash used for a read @@ -74,13 +74,13 @@ pub fn compute_note_hash_for_nullify_from_read_request( } /// Computes a note's siloed nullifier, i.e. the one that will be inserted into the nullifier tree. -pub fn compute_siloed_note_nullifier( - retrieved_note: RetrievedNote, +pub fn compute_siloed_note_nullifier( + retrieved_note: RetrievedNote, storage_slot: Field, context: &mut PrivateContext, ) -> Field where - Note: NoteHash, + NOTE: NoteHash, { let note_hash_for_nullify = compute_note_hash_for_nullify(retrieved_note, storage_slot); let inner_nullifier = retrieved_note.note.compute_nullifier(context, note_hash_for_nullify); diff --git a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr index ec91033854a..50d9e8411e8 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr @@ -146,7 +146,7 @@ unconstrained fn get_notes_oracle_wrapper( ) } -pub unconstrained fn get_notes( +pub unconstrained fn get_notes( storage_slot: Field, num_selects: u8, select_by_indexes: [u8; M], @@ -161,12 +161,12 @@ pub unconstrained fn get_notes>; S], // TODO: Remove it and use `limit` to initialize the note array. + mut placeholder_opt_notes: [Option>; S], // TODO: Remove it and use `limit` to initialize the note array. placeholder_fields: [Field; NS], // TODO: Remove it and use `limit` to initialize the note array. _placeholder_note_length: [Field; N], // Turbofish hack? Compiler breaks calculating read_offset unless we add this parameter TODO(benesjan): try removing this. -) -> [Option>; S] +) -> [Option>; S] where - Note: NoteType + Packable, + NOTE: NoteType + Packable, { let fields = get_notes_oracle_wrapper( storage_slot, @@ -198,7 +198,7 @@ where let maybe_note_hash_counter = fields[read_offset + 1] as u32; let packed_note = array::subarray(fields, read_offset + 2); - let note = Note::unpack(packed_note); + let note = NOTE::unpack(packed_note); let retrieved_note = RetrievedNote { note, contract_address, diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr index da9da820e68..9bc4eb39468 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr @@ -15,7 +15,7 @@ use crate::oracle::notes::check_nullifier_exists; use crate::state_vars::storage::Storage; // docs:start:struct -pub struct PrivateImmutable { +pub struct PrivateImmutable { context: Context, storage_slot: Field, } @@ -30,7 +30,7 @@ where } } -impl PrivateImmutable { +impl PrivateImmutable { // docs:start:new pub fn new(context: Context, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); @@ -52,11 +52,11 @@ impl PrivateImmutable { } } -impl PrivateImmutable { +impl PrivateImmutable { // docs:start:initialize - pub fn initialize(self, note: Note) -> NoteEmission + pub fn initialize(self, note: NOTE) -> NoteEmission where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { // Nullify the storage slot. let nullifier = self.compute_initialization_nullifier(); @@ -67,9 +67,9 @@ impl PrivateImmutable { // docs:end:initialize // docs:start:get_note - pub fn get_note(self) -> Note + pub fn get_note(self) -> NOTE where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { let storage_slot = self.storage_slot; let retrieved_note = get_note(self.context, storage_slot).0; @@ -82,7 +82,7 @@ impl PrivateImmutable { // docs:end:get_note } -impl PrivateImmutable { +impl PrivateImmutable { // docs:start:is_initialized pub unconstrained fn is_initialized(self) -> bool { let nullifier = self.compute_initialization_nullifier(); @@ -92,9 +92,9 @@ impl PrivateImmutable { // view_note does not actually use the context, but it calls oracles that are only available in private // docs:start:view_note - pub unconstrained fn view_note(self) -> Note + pub unconstrained fn view_note(self) -> NOTE where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { let mut options = NoteViewerOptions::new(); view_notes(self.storage_slot, options.set_limit(1)).get(0) diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr index 01a2d40aea7..fc2ba99bc23 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr @@ -16,7 +16,7 @@ use crate::oracle::notes::check_nullifier_exists; use crate::state_vars::storage::Storage; // docs:start:struct -pub struct PrivateMutable { +pub struct PrivateMutable { context: Context, storage_slot: Field, } @@ -33,7 +33,7 @@ where } } -impl PrivateMutable { +impl PrivateMutable { // docs:start:new pub fn new(context: Context, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); @@ -57,12 +57,12 @@ impl PrivateMutable { } } -impl PrivateMutable +impl PrivateMutable where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { // docs:start:initialize - pub fn initialize(self, note: Note) -> NoteEmission { + pub fn initialize(self, note: NOTE) -> NoteEmission { // Nullify the storage slot. let nullifier = self.compute_initialization_nullifier(); self.context.push_nullifier(nullifier); @@ -72,8 +72,8 @@ where // docs:end:initialize // docs:start:replace - pub fn replace(self, new_note: Note) -> NoteEmission { - let (prev_retrieved_note, note_hash_for_read_request): (RetrievedNote, Field) = + pub fn replace(self, new_note: NOTE) -> NoteEmission { + let (prev_retrieved_note, note_hash_for_read_request): (RetrievedNote, Field) = get_note(self.context, self.storage_slot); // Nullify previous note. @@ -88,7 +88,7 @@ where } // docs:end:replace - pub fn initialize_or_replace(self, note: Note) -> NoteEmission { + pub fn initialize_or_replace(self, note: NOTE) -> NoteEmission { // Safety: `check_nullifier_exists` is an unconstrained function - we can constrain a true value // by providing an inclusion proof of the nullifier, but cannot constrain a false value since // a non-inclusion proof would only be valid if done in public. @@ -111,7 +111,7 @@ where } // docs:start:get_note - pub fn get_note(self) -> NoteEmission { + pub fn get_note(self) -> NoteEmission { let mut (retrieved_note, note_hash_for_read_request) = get_note(self.context, self.storage_slot); @@ -125,9 +125,9 @@ where // docs:end:get_note } -impl PrivateMutable +impl PrivateMutable where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { pub unconstrained fn is_initialized(self) -> bool { let nullifier = self.compute_initialization_nullifier(); @@ -135,7 +135,7 @@ where } // docs:start:view_note - pub unconstrained fn view_note(self) -> Note { + pub unconstrained fn view_note(self) -> NOTE { let mut options = NoteViewerOptions::new(); view_notes(self.storage_slot, options.set_limit(1)).get(0) } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr index 7188f4a7b6f..993a9634f6a 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr @@ -17,7 +17,7 @@ use dep::protocol_types::{ }; // docs:start:struct -pub struct PrivateSet { +pub struct PrivateSet { pub context: Context, pub storage_slot: Field, } @@ -32,7 +32,7 @@ where } } -impl PrivateSet { +impl PrivateSet { // docs:start:new pub fn new(context: Context, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); @@ -41,20 +41,20 @@ impl PrivateSet { // docs:end:new } -impl PrivateSet +impl PrivateSet where - Note: NoteType + NoteHash + Eq + Packable, + NOTE: NoteType + NoteHash + Eq + Packable, { // docs:start:insert - pub fn insert(self, note: Note) -> NoteEmission { + pub fn insert(self, note: NOTE) -> NoteEmission { create_note(self.context, self.storage_slot, note) } // docs:end:insert pub fn pop_notes( self, - options: NoteGetterOptions, - ) -> BoundedVec { + options: NoteGetterOptions, + ) -> BoundedVec { let (retrieved_notes, note_hashes) = get_notes(self.context, self.storage_slot, options); // We iterate in a range 0..options.limit instead of 0..notes.len() because options.limit is known at compile // time and hence will result in less constraints when set to a lower value than @@ -76,7 +76,7 @@ where /// Note that if you obtained the note via `get_notes` it's much better to use `pop_notes` as `pop_notes` results /// in significantly less constrains due to avoiding an extra hash and read request check. - pub fn remove(self, retrieved_note: RetrievedNote) { + pub fn remove(self, retrieved_note: RetrievedNote) { let note_hash = compute_note_hash_for_read_request(retrieved_note, self.storage_slot); let has_been_read = self.context.note_hash_read_requests.any(|r: ReadRequest| r.value == note_hash); @@ -89,21 +89,21 @@ where /// in significantly less constrains due to avoiding 1 read request check. pub fn get_notes( self, - options: NoteGetterOptions, - ) -> BoundedVec, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL> { + options: NoteGetterOptions, + ) -> BoundedVec, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL> { get_notes(self.context, self.storage_slot, options).0 } } -impl PrivateSet +impl PrivateSet where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { // docs:start:view_notes pub unconstrained fn view_notes( self, - options: NoteViewerOptions, - ) -> BoundedVec { + options: NoteViewerOptions, + ) -> BoundedVec { view_notes(self.storage_slot, options) } // docs:end:view_notes diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr index 85a32eee87b..33dc9491a31 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -151,24 +151,24 @@ impl TestEnvironment { /// Manually adds a note to TXE. This needs to be called if you want to work with a note in your test with the note /// not having an encrypted log emitted. - pub unconstrained fn add_note( + pub unconstrained fn add_note( _self: Self, - note: Note, + note: NOTE, storage_slot: Field, contract_address: AztecAddress, ) where - Note: NoteType + NoteHash + Packable, + NOTE: NoteType + NoteHash + Packable, { let original_contract_address = get_contract_address(); cheatcodes::set_contract_address(contract_address); let note_hash_counter = cheatcodes::get_side_effects_counter(); let note_hash = note.compute_note_hash(storage_slot); - let packed_note = Note::pack(note); + let packed_note = NOTE::pack(note); notify_created_note( storage_slot, - Note::get_id(), + NOTE::get_id(), packed_note, note_hash, note_hash_counter, diff --git a/noir-projects/noir-contracts/contracts/spam_contract/src/types/balance_set.nr b/noir-projects/noir-contracts/contracts/spam_contract/src/types/balance_set.nr index a83c92df7d3..578db5f3434 100644 --- a/noir-projects/noir-contracts/contracts/spam_contract/src/types/balance_set.nr +++ b/noir-projects/noir-contracts/contracts/spam_contract/src/types/balance_set.nr @@ -11,28 +11,28 @@ use dep::aztec::prelude::{ NoteGetterOptions, NoteHash, NoteType, NoteViewerOptions, PrivateSet, RetrievedNote, }; -pub struct BalanceSet { - set: PrivateSet, +pub struct BalanceSet { + set: PrivateSet, } -impl BalanceSet { +impl BalanceSet { pub fn new(context: Context, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); Self { set: PrivateSet::new(context, storage_slot) } } } -impl BalanceSet { +impl BalanceSet { pub unconstrained fn balance_of(self: Self) -> u128 where - Note: NoteType + NoteHash + OwnedNote + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Packable, { self.balance_of_with_offset(0) } pub unconstrained fn balance_of_with_offset(self: Self, offset: u32) -> u128 where - Note: NoteType + NoteHash + OwnedNote + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Packable, { let mut balance = 0 as u128; // docs:start:view_notes @@ -52,15 +52,15 @@ impl BalanceSet { } } -impl BalanceSet { - pub fn add(self: Self, owner: AztecAddress, addend: u128) -> OuterNoteEmission +impl BalanceSet { + pub fn add(self: Self, owner: AztecAddress, addend: u128) -> OuterNoteEmission where - Note: NoteType + NoteHash + OwnedNote + Eq + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Eq + Packable, { if addend == 0 as u128 { OuterNoteEmission::new(Option::none()) } else { - let mut addend_note = Note::new(addend, owner); + let mut addend_note = NOTE::new(addend, owner); // docs:start:insert OuterNoteEmission::new(Option::some(self.set.insert(addend_note))) @@ -68,9 +68,9 @@ impl BalanceSet { } } - pub fn sub(self: Self, owner: AztecAddress, amount: u128) -> OuterNoteEmission + pub fn sub(self: Self, owner: AztecAddress, amount: u128) -> OuterNoteEmission where - Note: NoteType + NoteHash + OwnedNote + Eq + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Eq + Packable, { let subtracted = self.try_sub(amount, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL); @@ -91,7 +91,7 @@ impl BalanceSet { // `try_sub` subtracting an amount smaller than `target_amount`. pub fn try_sub(self: Self, target_amount: u128, max_notes: u32) -> u128 where - Note: NoteType + NoteHash + OwnedNote + Eq + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Eq + Packable, { // We are using a preprocessor here (filter applied in an unconstrained context) instead of a filter because // we do not need to prove correct execution of the preprocessor. @@ -119,12 +119,12 @@ impl BalanceSet { // The preprocessor (a filter applied in an unconstrained context) does not check if total sum is larger or equal to // 'min_sum' - all it does is remove extra notes if it does reach that value. // Note that proper usage of this preprocessor requires for notes to be sorted in descending order. -pub fn preprocess_notes_min_sum( - notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], +pub fn preprocess_notes_min_sum( + notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], min_sum: u128, -) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] +) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where - Note: NoteType + NoteHash + OwnedNote, + NOTE: NoteType + NoteHash + OwnedNote, { let mut selected = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; let mut sum = 0 as u128; diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr index c9e43a93a28..6f20c70f491 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr @@ -9,11 +9,11 @@ use dep::aztec::prelude::{ RetrievedNote, }; -pub struct BalancesMap { - map: Map, Context>, +pub struct BalancesMap { + map: Map, Context>, } -impl BalancesMap { +impl BalancesMap { pub fn new(context: Context, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); Self { @@ -26,10 +26,10 @@ impl BalancesMap { } } -impl BalancesMap { +impl BalancesMap { pub unconstrained fn balance_of(self: Self, owner: AztecAddress) -> u128 where - Note: NoteType + NoteHash + OwnedNote + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Packable, { self.balance_of_with_offset(owner, 0) } @@ -40,7 +40,7 @@ impl BalancesMap { offset: u32, ) -> u128 where - Note: NoteType + NoteHash + OwnedNote + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Packable, { let mut balance = 0 as u128; // docs:start:view_notes @@ -60,16 +60,16 @@ impl BalancesMap { } } -impl BalancesMap { +impl BalancesMap { - pub fn add(self: Self, owner: AztecAddress, addend: u128) -> OuterNoteEmission + pub fn add(self: Self, owner: AztecAddress, addend: u128) -> OuterNoteEmission where - Note: NoteType + NoteHash + OwnedNote + Eq + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Eq + Packable, { if addend == 0 as u128 { OuterNoteEmission::new(Option::none()) } else { - let addend_note = Note::new(addend, owner); + let addend_note = NOTE::new(addend, owner); // docs:start:insert OuterNoteEmission::new(Option::some(self.map.at(owner).insert(addend_note))) @@ -81,9 +81,9 @@ impl BalancesMap { self: Self, owner: AztecAddress, subtrahend: u128, - ) -> OuterNoteEmission + ) -> OuterNoteEmission where - Note: NoteType + NoteHash + OwnedNote + Eq + Packable, + NOTE: NoteType + NoteHash + OwnedNote + Eq + Packable, { let options = NoteGetterOptions::with_filter(filter_notes_min_sum, subtrahend); let notes = self.map.at(owner).pop_notes(options); @@ -91,7 +91,7 @@ impl BalancesMap { let mut minuend: u128 = 0 as u128; for i in 0..options.limit { if i < notes.len() { - let note: Note = notes.get_unchecked(i); + let note: NOTE = notes.get_unchecked(i); minuend = minuend + note.get_amount(); } } @@ -105,12 +105,12 @@ impl BalancesMap { } } -pub fn filter_notes_min_sum( - retrieved_notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], +pub fn filter_notes_min_sum( + retrieved_notes: [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], min_sum: u128, -) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] +) -> [Option>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where - Note: NoteType + OwnedNote, + NOTE: NoteType + OwnedNote, { let mut selected = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; let mut sum = 0 as u128;