Skip to content

Commit

Permalink
refactor: note hashing gate optimizations (#7130)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jun 20, 2024
1 parent 14917d3 commit 81a2580
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 10 additions & 15 deletions noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ fn compute_unique_note_hash<Note, N, M>(note_with_header: Note) -> Field where N
}

fn compute_siloed_note_hash<Note, N, M>(note_with_header: Note) -> Field where Note: NoteInterface<N, M> {
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)
}

Expand All @@ -70,10 +62,14 @@ pub fn compute_note_hash_for_insertion<Note, N, M>(note: Note) -> Field where No
pub fn compute_note_hash_for_read_request<Note, N, M>(note: Note) -> Field where Note: NoteInterface<N, M> {
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)
}
}

Expand Down Expand Up @@ -112,8 +108,7 @@ pub fn compute_note_hash_and_optionally_a_nullifier<T, N, M, S>(
serialized_note: [Field; S] // docs:end:compute_note_hash_and_optionally_a_nullifier_args
) -> [Field; 4] where T: NoteInterface<N, M> {
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);

Expand Down
2 changes: 2 additions & 0 deletions noir-projects/noir-protocol-circuits/crates/types/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down

0 comments on commit 81a2580

Please sign in to comment.