Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: note hashing gate optimizations #7130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address this one in follow-up PR.

fn compute_unique_note_hash(nonce: Field, note_hash: Field) -> Field {
pedersen_hash(
[
Expand Down
Loading