From 8086573145e275d89fc43c1598beb83744217e9e Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 20 Jun 2024 10:57:10 +0000 Subject: [PATCH 1/3] refactor: compute_note_hash_for_read_request optimization --- noir-projects/aztec-nr/aztec/src/note/utils.nr | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index 6c00104d611..5c95bb2b8cc 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -70,10 +70,14 @@ pub fn compute_note_hash_for_insertion(note: Note) -> Field where No pub fn compute_note_hash_for_read_request(note: Note) -> Field where Note: NoteInterface { let header = note.get_header(); - if (header.nonce != 0) { - compute_unique_note_hash(note) + let inner_note_hash = compute_inner_note_hash(note); + + // TODO(#1386): This if-else can be nuked once we have nonces injected from public + if (header.nonce == 0) { + // If nonce is zero, that means we are reading a public note. + inner_note_hash } else { - compute_inner_note_hash(note) + compute_unique_hash(header.nonce, inner_note_hash) } } From 81a58df7147a9e96278ca666a13c461a3a546d9d Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 20 Jun 2024 11:10:26 +0000 Subject: [PATCH 2/3] addressing old TODO --- noir-projects/aztec-nr/aztec/src/note/utils.nr | 3 +-- noir-projects/noir-protocol-circuits/crates/types/src/hash.nr | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index 5c95bb2b8cc..3512f3b4ff9 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -116,8 +116,7 @@ pub fn compute_note_hash_and_optionally_a_nullifier( serialized_note: [Field; S] // docs:end:compute_note_hash_and_optionally_a_nullifier_args ) -> [Field; 4] where T: NoteInterface { let mut note = deserialize_content(arr_copy_slice(serialized_note, [0; N], 0)); - // TODO: change this to note.set_header(header) once https://github.com/noir-lang/noir/issues/4095 is fixed - T::set_header((&mut note), note_header); + note.set_header(note_header); let inner_note_hash = compute_inner_note_hash(note); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index 890d1ee3a60..416d3f123b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -45,6 +45,8 @@ pub fn compute_note_hash_nonce(first_nullifier: Field, note_hash_index: u32) -> ) } +// TODO(benesjan): some of these functions seem to be duplicate to the ones in +// noir-projects/aztec-nr/aztec/src/note/utils.nr NUKE! fn compute_unique_note_hash(nonce: Field, note_hash: Field) -> Field { pedersen_hash( [ From 41e7fe7c128642a08fa4df3c28e7721b3b21e27e Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 20 Jun 2024 11:20:59 +0000 Subject: [PATCH 3/3] optimization 2 --- noir-projects/aztec-nr/aztec/src/note/utils.nr | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index 3512f3b4ff9..cd587c1a643 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -38,17 +38,9 @@ fn compute_unique_note_hash(note_with_header: Note) -> Field where N } fn compute_siloed_note_hash(note_with_header: Note) -> Field where Note: NoteInterface { - let header = note_with_header.get_header(); - - let unique_note_hash = if (header.nonce == 0) { - // If nonce is zero, that means we are reading a public note. - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) - // Remove this once notes added from public also include nonces. - compute_inner_note_hash(note_with_header) - } else { - compute_unique_note_hash(note_with_header) - }; + let unique_note_hash = compute_note_hash_for_read_request(note_with_header); + let header = note_with_header.get_header(); compute_siloed_hash(header.contract_address, unique_note_hash) }