Skip to content

Commit

Permalink
note type id fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 8, 2025
1 parent 8ce17d0 commit 58da308
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/docs/aztec/smart_contracts/functions/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ impl CustomNote {
}

fn get_note_type_id() -> Field {
// Automatically generated unique ID based on Keccak hash of the struct name
0xd2de93eaab1d59abddf06134e737665f076f556feb7b6d3d72ca557b430b14d2
// Assigned by macros by incrementing a counter
2
}

fn get_header(note: CustomNote) -> aztec::note::note_header::NoteHeader {
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl NoteInterface<MOCK_NOTE_LENGTH> for MockNote {
}

fn get_note_type_id() -> Field {
// randomly chose note type id
4135
// randomly chosen note type id --> has to fit within 7 bits
76
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_LENGTH * 32 + 64] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
}

fn get_note_type_id() -> Field {
comptime
{
let bytes = "EcdsaPublicKeyNote".as_bytes();
let hash = aztec::protocol_types::hash::poseidon2_hash_bytes(bytes);
let hash_bytes = hash.to_be_bytes::<4>();
aztec::protocol_types::utils::field::field_from_bytes(hash_bytes, true)
}
// randomly chosen note type id --> has to fit within 7 bits
76
}

fn get_header(self) -> NoteHeader {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/abi/note_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NoteSelector extends Selector {
const reader = BufferReader.asReader(buffer);
const value = Number(toBigIntBE(reader.readBytes(Selector.SIZE)));
if (value >= 1 << 7) {
throw new Error('Invalid note selector');
throw new Error(`Invalid note selector: ${value}`);
}
return new NoteSelector(value);
}
Expand Down

0 comments on commit 58da308

Please sign in to comment.