From 4c34f911fc57cd52382474fd406b385d7f2bd68f Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 09:01:26 +0000 Subject: [PATCH 1/8] feat: nullable note fields info in ABI --- noir-projects/aztec-nr/aztec/src/macros/mod.nr | 7 +++++++ noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index 76d136fe3ba2..f467dbf2beb0 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -15,6 +15,10 @@ use dispatch::generate_public_dispatch; /// Marks a contract as an Aztec contract, generating the interfaces for its functions and notes, as well as injecting /// the `compute_note_hash_and_optionally_a_nullifier` function PXE requires in order to validate notes. +/// +/// Note: This is a module annotation, so the returned quote gets injected inside the module (contract) itself. +/// The difference between a module and a regular struct or functionn annotation is that module annotations inject +/// the code inside the module instead of directly below the annotated element. pub comptime fn aztec(m: Module) -> Quoted { let interface = generate_contract_interface(m); let unconstrained_functions = m.functions().filter( @@ -155,8 +159,11 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { } } +// here it actually generates the struct comptime fn generate_note_exports() -> Quoted { let notes = NOTES.values(); + // Second value in each tuple is `note_serialized_len` and that is ignored here because it's only used whne + // generating the `compute_note_hash_and_optionally_a_nullifier` function. notes.map( | (s, _, note_type_id): (StructDefinition, u32, Field) | { generate_note_export(s, note_type_id) diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index fd8777873a1a..1d37ea290630 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -149,6 +149,7 @@ pub(crate) comptime fn generate_note_export(s: StructDefinition, note_type_id: F let global_export_name = f"{name}_EXPORTS".quoted_contents(); let note_name_as_str = name.as_str_quote(); let note_name_str_len = unquote!(quote { $note_name_as_str.as_bytes().len() }); + // the #[abi( tag below seems to result in the note being exported to the ABI quote { #[abi(notes)] global $global_export_name: (Field, str<$note_name_str_len>) = ($note_type_id,$note_name_as_str); @@ -287,9 +288,13 @@ comptime fn generate_partial_note_impl(s: StructDefinition, hiding_point_name: Q } comptime fn register_note(note: StructDefinition, note_serialized_len: u32, note_type_id: Field) { + // Here you need to insert the info about the partial fields, we need to NOTES.insert(note.as_type(), (note, note_serialized_len, note_type_id)); } +/// Separates note struct members into fixed and nullable ones. It also stores the index of where each struct member +/// starts in the serialized note. Note that each struct member can occupy multiple fields (as in Field type). +/// An example of a struct member occupying multiple fields is `amount` in `TokenNote` that uses `U128` type. comptime fn index_note_fields( s: StructDefinition, nullable_fields: [Quoted] @@ -307,6 +312,7 @@ comptime fn index_note_fields( } } let (flattened, _) = flatten_to_fields(name, typ, &[]); + // Each struct member can occupy multiple fields so we need to increment the counter accordingly counter+=flattened.len(); } (indexed_fixed_fields, indexed_nullable_fields) From 36f7ffa90fba5756b2e741e886e1d6577476a968 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 09:54:58 +0000 Subject: [PATCH 2/8] WIP --- .../aztec-nr/aztec/src/macros/mod.nr | 9 ++-- .../aztec-nr/aztec/src/macros/notes/mod.nr | 51 ++++++++++++++++--- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index f467dbf2beb0..48f20c560f0c 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -110,14 +110,14 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { let mut max_note_length: u32 = 0; let notes = NOTES.entries(); let body = if notes.len() > 0 { - max_note_length = notes.fold(0, | acc, (_, (_, len, _)): (Type, (StructDefinition, u32, Field)) | { + max_note_length = notes.fold(0, | acc, (_, (_, len, _, _, _)): (Type, (StructDefinition, u32, Field, [(Quoted, u32)], [(Quoted, u32)])) | { acc + len }); let mut if_statements_list = &[]; for i in 0..notes.len() { - let (typ, (_, _, _)) = notes[i]; + let (typ, (_, _, _, _, _)) = notes[i]; let if_or_else_if = if i == 0 { quote { if } } else { @@ -159,13 +159,12 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { } } -// here it actually generates the struct comptime fn generate_note_exports() -> Quoted { let notes = NOTES.values(); - // Second value in each tuple is `note_serialized_len` and that is ignored here because it's only used whne + // Second value in each tuple is `note_serialized_len` and that is ignored because it's only used when // generating the `compute_note_hash_and_optionally_a_nullifier` function. notes.map( - | (s, _, note_type_id): (StructDefinition, u32, Field) | { + | (s, _, note_type_id, _, _): (StructDefinition, u32, Field, [(Quoted, u32)], [(Quoted, u32)]) | { generate_note_export(s, note_type_id) } ).join(quote {}) diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index 1d37ea290630..a2cdabfb0515 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -7,7 +7,10 @@ use crate::note::{note_header::NoteHeader, note_getter_options::PropertySelector comptime global NOTE_HEADER_TYPE = type_of(NoteHeader::empty()); -comptime mut global NOTES: UHashMap> = UHashMap::default(); +// A map from note type to (note_struct_definition, serialized_note_length, note_type_id, fixed_fields, nullable_fields). +// The fixed and nullable fields contain the name of the struct member and the index of where it starts in +// the serialized note. +comptime mut global NOTES: UHashMap> = UHashMap::default(); comptime fn compute_note_type_id(name: Quoted) -> Field { let name_as_str_quote = name.as_str_quote(); @@ -287,9 +290,22 @@ comptime fn generate_partial_note_impl(s: StructDefinition, hiding_point_name: Q } } -comptime fn register_note(note: StructDefinition, note_serialized_len: u32, note_type_id: Field) { - // Here you need to insert the info about the partial fields, we need to - NOTES.insert(note.as_type(), (note, note_serialized_len, note_type_id)); +comptime fn register_note( + note: StructDefinition, + note_serialized_len: u32, + note_type_id: Field, + fixed_fields: [(Quoted, Type, u32)], + nullable_fields: [(Quoted, Type, u32)] +) { + // We omit the Type as we don't need it in the ABI. In the ABI we only care about the name and the start index + // in the serialized note array. + let fixed_fields_without_type = fixed_fields.map(| (name, _, index): (Quoted, Type, u32) | (name, index)); + let nullable_fields_without_type = nullable_fields.map(| (name, _, index): (Quoted, Type, u32) | (name, index)); + + NOTES.insert( + note.as_type(), + (note, note_serialized_len, note_type_id, fixed_fields_without_type, nullable_fields_without_type) + ); } /// Separates note struct members into fixed and nullable ones. It also stores the index of where each struct member @@ -335,6 +351,8 @@ comptime fn common_note_annotation(s: StructDefinition) -> (Quoted, Field) { #[varargs] pub comptime fn partial_note(s: StructDefinition, nullable_fields: [Quoted]) -> Quoted { + // We separate struct members into fixed ones and nullable ones and we store info about the start index of each + // member in the serialized note array. let (indexed_fixed_fields, indexed_nullable_fields) = index_note_fields(s, nullable_fields); let (common, note_type_id) = common_note_annotation(s); @@ -347,7 +365,13 @@ pub comptime fn partial_note(s: StructDefinition, nullable_fields: [Quoted]) -> indexed_nullable_fields ); let partial_note_impl = generate_partial_note_impl(s, hiding_point_name); - register_note(s, note_serialized_len, note_type_id); + register_note( + s, + note_serialized_len, + note_type_id, + indexed_fixed_fields, + indexed_nullable_fields + ); quote { $common @@ -368,7 +392,13 @@ pub comptime fn note(s: StructDefinition) -> Quoted { indexed_fixed_fields, indexed_nullable_fields ); - register_note(s, note_serialized_len, note_type_id); + register_note( + s, + note_serialized_len, + note_type_id, + indexed_fixed_fields, + indexed_nullable_fields + ); quote { $common @@ -385,7 +415,14 @@ pub comptime fn note_custom_interface(s: StructDefinition) -> Quoted { let note_serialized_len = note_interface_impl.expect(f"Note {name} must implement NoteInterface trait").trait_generic_args()[0].as_constant().unwrap(); - register_note(s, note_serialized_len, note_type_id); + let (indexed_fixed_fields, indexed_nullable_fields) = index_note_fields(s, &[]); + register_note( + s, + note_serialized_len, + note_type_id, + indexed_fixed_fields, + indexed_nullable_fields + ); quote { $common From 6a395b6432d3e41d3134d92c189f76f2d0774bba Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 10:06:42 +0000 Subject: [PATCH 3/8] foxes --- noir-projects/aztec-nr/aztec/src/macros/mod.nr | 6 +++--- .../aztec-nr/aztec/src/macros/notes/mod.nr | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index 48f20c560f0c..fc4447fc612b 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -110,14 +110,14 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { let mut max_note_length: u32 = 0; let notes = NOTES.entries(); let body = if notes.len() > 0 { - max_note_length = notes.fold(0, | acc, (_, (_, len, _, _, _)): (Type, (StructDefinition, u32, Field, [(Quoted, u32)], [(Quoted, u32)])) | { + max_note_length = notes.fold(0, | acc, (_, (_, len, _, _)): (Type, (StructDefinition, u32, Field, [(Quoted, u32, bool)])) | { acc + len }); let mut if_statements_list = &[]; for i in 0..notes.len() { - let (typ, (_, _, _, _, _)) = notes[i]; + let (typ, (_, _, _, _)) = notes[i]; let if_or_else_if = if i == 0 { quote { if } } else { @@ -164,7 +164,7 @@ comptime fn generate_note_exports() -> Quoted { // Second value in each tuple is `note_serialized_len` and that is ignored because it's only used when // generating the `compute_note_hash_and_optionally_a_nullifier` function. notes.map( - | (s, _, note_type_id, _, _): (StructDefinition, u32, Field, [(Quoted, u32)], [(Quoted, u32)]) | { + | (s, _, note_type_id, _): (StructDefinition, u32, Field, [(Quoted, u32, bool)]) | { generate_note_export(s, note_type_id) } ).join(quote {}) diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index a2cdabfb0515..be2967565320 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -10,7 +10,7 @@ comptime global NOTE_HEADER_TYPE = type_of(NoteHeader::empty()); // A map from note type to (note_struct_definition, serialized_note_length, note_type_id, fixed_fields, nullable_fields). // The fixed and nullable fields contain the name of the struct member and the index of where it starts in // the serialized note. -comptime mut global NOTES: UHashMap> = UHashMap::default(); +comptime mut global NOTES: UHashMap> = UHashMap::default(); comptime fn compute_note_type_id(name: Quoted) -> Field { let name_as_str_quote = name.as_str_quote(); @@ -152,7 +152,6 @@ pub(crate) comptime fn generate_note_export(s: StructDefinition, note_type_id: F let global_export_name = f"{name}_EXPORTS".quoted_contents(); let note_name_as_str = name.as_str_quote(); let note_name_str_len = unquote!(quote { $note_name_as_str.as_bytes().len() }); - // the #[abi( tag below seems to result in the note being exported to the ABI quote { #[abi(notes)] global $global_export_name: (Field, str<$note_name_str_len>) = ($note_type_id,$note_name_as_str); @@ -297,14 +296,19 @@ comptime fn register_note( fixed_fields: [(Quoted, Type, u32)], nullable_fields: [(Quoted, Type, u32)] ) { - // We omit the Type as we don't need it in the ABI. In the ABI we only care about the name and the start index - // in the serialized note array. - let fixed_fields_without_type = fixed_fields.map(| (name, _, index): (Quoted, Type, u32) | (name, index)); - let nullable_fields_without_type = nullable_fields.map(| (name, _, index): (Quoted, Type, u32) | (name, index)); + let mut fields = &[]; + for field in fixed_fields { + let (name, _, index) = field; + fields = fields.push_back((name, index, false)); + } + for field in nullable_fields { + let (name, _, index) = field; + fields = fields.push_back((name, index, true)); + } NOTES.insert( note.as_type(), - (note, note_serialized_len, note_type_id, fixed_fields_without_type, nullable_fields_without_type) + (note, note_serialized_len, note_type_id, fields) ); } From 8e0b84cf9633ee6eca11db362e262ed1eb0a2b07 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 11:27:54 +0000 Subject: [PATCH 4/8] WIP --- .../aztec-nr/aztec/src/macros/mod.nr | 4 +-- .../aztec-nr/aztec/src/macros/notes/mod.nr | 26 +++++++++++++++++-- .../aztec-nr/aztec/src/macros/storage/mod.nr | 3 +++ noir-projects/aztec-nr/aztec/src/note/mod.nr | 1 + .../aztec-nr/aztec/src/note/note_field.nr | 4 +++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 noir-projects/aztec-nr/aztec/src/note/note_field.nr diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index fc4447fc612b..1b8f44e2315b 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -164,8 +164,8 @@ comptime fn generate_note_exports() -> Quoted { // Second value in each tuple is `note_serialized_len` and that is ignored because it's only used when // generating the `compute_note_hash_and_optionally_a_nullifier` function. notes.map( - | (s, _, note_type_id, _): (StructDefinition, u32, Field, [(Quoted, u32, bool)]) | { - generate_note_export(s, note_type_id) + | (s, _, note_type_id, fields): (StructDefinition, u32, Field, [(Quoted, u32, bool)]) | { + generate_note_export(s, note_type_id, fields) } ).join(quote {}) } diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index be2967565320..c4b0644eaf4e 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -147,14 +147,36 @@ comptime fn generate_note_properties(s: StructDefinition) -> Quoted { } } -pub(crate) comptime fn generate_note_export(s: StructDefinition, note_type_id: Field) -> Quoted { +/// Generates note export for a given note struct. The export is a global variable that contains the note type id, +/// the note name and information about note fields. +pub(crate) comptime fn generate_note_export( + s: StructDefinition, + note_type_id: Field, + fields: [(Quoted, u32, bool)] +) -> Quoted { let name = s.name(); let global_export_name = f"{name}_EXPORTS".quoted_contents(); let note_name_as_str = name.as_str_quote(); let note_name_str_len = unquote!(quote { $note_name_as_str.as_bytes().len() }); + + let mut note_fields = &[]; + let mut note_field_constructors = &[]; + for field in fields { + let (name, index, nullable) = field; + note_fields = note_fields.push_back(quote { $name: aztec::note::note_field::NoteField }); + note_field_constructors = note_field_constructors.push_back(quote { aztec::note::note_field::NoteField { index: $index, nullable: $nullable }}); + } + + let note_fields = note_fields.join(quote {,}); + let note_field_constructors = note_field_constructors.join(quote {,}); + quote { + struct NoteFields { + $note_fields + } + #[abi(notes)] - global $global_export_name: (Field, str<$note_name_str_len>) = ($note_type_id,$note_name_as_str); + global $global_export_name: (Field, str<$note_name_str_len>, NoteFields) = ($note_type_id,$note_name_as_str, NoteFields { $note_field_constructors }); } } diff --git a/noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr index 63085332c84a..391f6cc874b9 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr @@ -30,6 +30,9 @@ pub comptime fn storage(s: StructDefinition) -> Quoted { let (name, typ) = field; let (storage_field_constructor, serialized_size) = generate_storage_field_constructor(typ, quote { $slot }, false); storage_vars_constructors = storage_vars_constructors.push_back(quote { $name: $storage_field_constructor }); + // We have `Storable` in a separate `.nr` file instead of defining it in the last quote of this function + // because that way a dev gets a more reasonable error if he defines a struct with the same name in + // a contract. storage_layout_fields = storage_layout_fields.push_back(quote { $name: dep::aztec::prelude::Storable }); storage_layout_constructors = storage_layout_constructors.push_back(quote { $name: dep::aztec::prelude::Storable { slot: $slot } }); //let with_context_generic = add_context_generic(typ, context_generic); diff --git a/noir-projects/aztec-nr/aztec/src/note/mod.nr b/noir-projects/aztec-nr/aztec/src/note/mod.nr index 670b340735ee..c076bf8ed1b8 100644 --- a/noir-projects/aztec-nr/aztec/src/note/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/note/mod.nr @@ -7,3 +7,4 @@ mod note_interface; mod note_viewer_options; mod utils; mod note_emission; +mod note_field; diff --git a/noir-projects/aztec-nr/aztec/src/note/note_field.nr b/noir-projects/aztec-nr/aztec/src/note/note_field.nr new file mode 100644 index 000000000000..e5feb8e81056 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/note/note_field.nr @@ -0,0 +1,4 @@ +pub struct NoteField { + index: u32, + nullable: bool +} From 6ea10cb4df05513fd5d2283fe71e880c622be81d Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 11:39:43 +0000 Subject: [PATCH 5/8] WIP --- noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index c4b0644eaf4e..94b23a1a4c6a 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -164,7 +164,7 @@ pub(crate) comptime fn generate_note_export( for field in fields { let (name, index, nullable) = field; note_fields = note_fields.push_back(quote { $name: aztec::note::note_field::NoteField }); - note_field_constructors = note_field_constructors.push_back(quote { aztec::note::note_field::NoteField { index: $index, nullable: $nullable }}); + note_field_constructors = note_field_constructors.push_back(quote { $name: aztec::note::note_field::NoteField { index: $index, nullable: $nullable }}); } let note_fields = note_fields.join(quote {,}); From fb1d313f3ede54fc7b20caf299a1753774fd8af0 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 11:47:24 +0000 Subject: [PATCH 6/8] fix --- noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index 94b23a1a4c6a..d7e28f5d9f6c 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -156,6 +156,7 @@ pub(crate) comptime fn generate_note_export( ) -> Quoted { let name = s.name(); let global_export_name = f"{name}_EXPORTS".quoted_contents(); + let note_fields_name = f"{name}Fields".quoted_contents(); let note_name_as_str = name.as_str_quote(); let note_name_str_len = unquote!(quote { $note_name_as_str.as_bytes().len() }); @@ -171,12 +172,12 @@ pub(crate) comptime fn generate_note_export( let note_field_constructors = note_field_constructors.join(quote {,}); quote { - struct NoteFields { + struct $note_fields_name { $note_fields } #[abi(notes)] - global $global_export_name: (Field, str<$note_name_str_len>, NoteFields) = ($note_type_id,$note_name_as_str, NoteFields { $note_field_constructors }); + global $global_export_name: (Field, str<$note_name_str_len>, $note_fields_name) = ($note_type_id,$note_name_as_str, $note_fields_name { $note_field_constructors }); } } From 7eb98435a5616b2c9264bc37b0f5ddd56a36e81e Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 11:56:16 +0000 Subject: [PATCH 7/8] cleanup --- noir-projects/aztec-nr/aztec/src/macros/mod.nr | 2 +- noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr | 11 ++++++----- noir-projects/aztec-nr/aztec/src/note/note_field.nr | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index 1b8f44e2315b..257ce405cde3 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -161,7 +161,7 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { comptime fn generate_note_exports() -> Quoted { let notes = NOTES.values(); - // Second value in each tuple is `note_serialized_len` and that is ignored because it's only used when + // Second value in each tuple is `note_serialized_len` and that is ignored here because it's only used when // generating the `compute_note_hash_and_optionally_a_nullifier` function. notes.map( | (s, _, note_type_id, fields): (StructDefinition, u32, Field, [(Quoted, u32, bool)]) | { diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index d7e28f5d9f6c..21a852b56045 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -7,9 +7,10 @@ use crate::note::{note_header::NoteHeader, note_getter_options::PropertySelector comptime global NOTE_HEADER_TYPE = type_of(NoteHeader::empty()); -// A map from note type to (note_struct_definition, serialized_note_length, note_type_id, fixed_fields, nullable_fields). -// The fixed and nullable fields contain the name of the struct member and the index of where it starts in -// the serialized note. +// A map from note type to (note_struct_definition, serialized_note_length, note_type_id, fields). +// `fields` is an array of tuples where each tuple contains the name of the field/struct member (e.g. `amount` +// in `TokenNote`), the index of where the serialized member starts in the serialized note and a flag indicating +// whether the field is nullable or not. comptime mut global NOTES: UHashMap> = UHashMap::default(); comptime fn compute_note_type_id(name: Quoted) -> Field { @@ -147,8 +148,8 @@ comptime fn generate_note_properties(s: StructDefinition) -> Quoted { } } -/// Generates note export for a given note struct. The export is a global variable that contains the note type id, -/// the note name and information about note fields. +/// Generates note export for a given note struct. The export is a global variable that contains note type id, +/// note name and information about note fields (field name, index and whether the field is nullable or not). pub(crate) comptime fn generate_note_export( s: StructDefinition, note_type_id: Field, diff --git a/noir-projects/aztec-nr/aztec/src/note/note_field.nr b/noir-projects/aztec-nr/aztec/src/note/note_field.nr index e5feb8e81056..35e7fbc282a6 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_field.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_field.nr @@ -1,3 +1,4 @@ +// Used by macros when generating note export. pub struct NoteField { index: u32, nullable: bool From 352f8a13894eb69b0619b56788426a306fd581fd Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 13:24:28 +0000 Subject: [PATCH 8/8] less verbose comment --- noir-projects/aztec-nr/aztec/src/macros/mod.nr | 2 -- 1 file changed, 2 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index 257ce405cde3..677d0af070b2 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -17,8 +17,6 @@ use dispatch::generate_public_dispatch; /// the `compute_note_hash_and_optionally_a_nullifier` function PXE requires in order to validate notes. /// /// Note: This is a module annotation, so the returned quote gets injected inside the module (contract) itself. -/// The difference between a module and a regular struct or functionn annotation is that module annotations inject -/// the code inside the module instead of directly below the annotated element. pub comptime fn aztec(m: Module) -> Quoted { let interface = generate_contract_interface(m); let unconstrained_functions = m.functions().filter(