From dc769f26ca16527685916e6814b10f73c9b8b00c Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 23 Dec 2024 21:08:42 +0000 Subject: [PATCH] WIP --- cspell.json | 1 + .../aztec-nr/aztec/src/macros/notes/mod.nr | 31 ++++++++++--------- .../aztec-nr/aztec/src/note/note_type_id.nr | 1 - .../circuit-types/src/interfaces/pxe.ts | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) delete mode 100644 noir-projects/aztec-nr/aztec/src/note/note_type_id.nr diff --git a/cspell.json b/cspell.json index 3ed9bc44cf4..0002201c734 100644 --- a/cspell.json +++ b/cspell.json @@ -175,6 +175,7 @@ "noirc", "noirup", "nullifer", + "Nullifiable", "offchain", "onchain", "opentelemetry", 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 5d8aa114b09..584ee4ff8b4 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -19,19 +19,19 @@ comptime global NOTE_HEADER_TYPE: Type = type_of(NoteHeader::empty()); pub comptime mut global NOTES: UHashMap> = UHashMap::default(); -/// Computes a note type id by hashing a note name (e.g. `TokenNote`), getting the first 4 bytes of the hash -/// and returning it as a `Field`. -comptime fn compute_note_type_id(name: Quoted) -> Field { - let (name_as_str_quote, _) = name.as_str_quote(); +pub comptime mut global NOTE_TYPE_ID_COUNTER: u32 = 0; + +/// The note type id is set by enumerating the note types. +comptime fn get_next_note_type_id() -> Field { + // We assert that the note type id fits within 7 bits + assert( + NOTE_TYPE_ID_COUNTER < 128 as u32, + "A contract can contain at most 128 different note types", + ); - unquote!( - quote { - let bytes = $name_as_str_quote.as_bytes(); - let hash = protocol_types::hash::poseidon2_hash_bytes(bytes); - let hash_bytes = hash.to_be_bytes::<4>(); - protocol_types::utils::field::field_from_bytes(hash_bytes, true) - }, - ) + let note_type_id = NOTE_TYPE_ID_COUNTER as Field; + NOTE_TYPE_ID_COUNTER += 1; + note_type_id } /// Generates default `NoteInterface` implementation for a given note struct `s` and returns it as quote along with @@ -123,6 +123,7 @@ comptime fn generate_note_interface( let mut buffer: [u8; $content_len * 32 + 64] = [0; $content_len * 32 + 64]; 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] = $name::get_note_type_id().to_be_bytes(); for i in 0..32 { @@ -871,7 +872,7 @@ pub comptime fn partial_note(s: StructDefinition, nullable_fields: [Quoted]) -> inject_note_header(s); let note_properties = generate_note_properties(s); - let note_type_id = compute_note_type_id(s.name()); + let note_type_id = get_next_note_type_id(); let (setup_payload_impl, setup_payload_name) = generate_setup_payload(s, indexed_fixed_fields, indexed_nullable_fields); let (finalization_payload_impl, finalization_payload_name) = @@ -914,7 +915,7 @@ pub comptime fn note(s: StructDefinition) -> Quoted { inject_note_header(s); let note_properties = generate_note_properties(s); - let note_type_id = compute_note_type_id(s.name()); + let note_type_id = get_next_note_type_id(); let (note_interface_impl, note_serialized_len) = generate_note_interface( s, note_type_id, @@ -944,7 +945,7 @@ pub comptime fn note_custom_interface(s: StructDefinition) -> Quoted { inject_note_header(s); let note_properties = generate_note_properties(s); - let note_type_id = compute_note_type_id(s.name()); + let note_type_id = get_next_note_type_id(); let serialized_len_type = fresh_type_variable(); let note_interface_impl = s.as_type().get_trait_impl( quote { crate::note::note_interface::NoteInterface<$serialized_len_type> } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_type_id.nr b/noir-projects/aztec-nr/aztec/src/note/note_type_id.nr deleted file mode 100644 index 8b137891791..00000000000 --- a/noir-projects/aztec-nr/aztec/src/note/note_type_id.nr +++ /dev/null @@ -1 +0,0 @@ - diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index d70216ef15c..13fd3dbe8b1 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -388,7 +388,7 @@ export interface PXE { isContractInitialized(address: AztecAddress): Promise; /** - * Returns the enctypred events given search parameters. + * Returns the encrypted events given search parameters. * @param eventMetadata - Metadata of the event. This should be the class generated from the contract. e.g. Contract.events.Event * @param from - The block number to search from. * @param limit - The amount of blocks to search.