diff --git a/boxes/token/src/contracts/src/types/transparent_note.nr b/boxes/token/src/contracts/src/types/transparent_note.nr index deb2bcdf6f1..361413bc82b 100644 --- a/boxes/token/src/contracts/src/types/transparent_note.nr +++ b/boxes/token/src/contracts/src/types/transparent_note.nr @@ -3,7 +3,7 @@ use dep::aztec::{ note::{ note_header::NoteHeader, note_interface::NoteInterface, - utils::compute_siloed_note_hash, + utils::compute_note_hash_for_read_or_nullify, }, hash::{compute_secret_hash, pedersen_hash}, context::PrivateContext, @@ -75,8 +75,7 @@ impl TransparentNote { } pub fn compute_nullifier_without_context(self) -> Field { - // TODO(#1386): should use `compute_note_hash_for_read_or_nullify` once public functions inject nonce! - let siloed_note_hash = compute_siloed_note_hash(TransparentNoteMethods, self); + let siloed_note_hash = compute_note_hash_for_read_or_nullify(TransparentNoteMethods, self); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([self.secret, siloed_note_hash],0) } diff --git a/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr b/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr index d156618d326..61e1541e820 100644 --- a/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr +++ b/yarn-project/aztec-nr/aztec/src/history/note_inclusion.nr @@ -3,7 +3,7 @@ use dep::std::merkle::compute_merkle_root; use crate::{ context::PrivateContext, note::{ - utils::compute_unique_siloed_note_hash, + utils::compute_note_hash_for_read_or_nullify, note_header::NoteHeader, note_interface::NoteInterface, }, @@ -35,7 +35,7 @@ pub fn prove_note_inclusion( block_number: u32, // The block at which we'll prove that the note exists context: PrivateContext ) { - let note_commitment = compute_unique_siloed_note_hash(note_interface, note_with_header); + let note_commitment = compute_note_hash_for_read_or_nullify(note_interface, note_with_header); prove_note_commitment_inclusion(note_commitment, block_number, context); } diff --git a/yarn-project/aztec-nr/aztec/src/note.nr b/yarn-project/aztec-nr/aztec/src/note.nr index 5df51e71dd4..b457a126b2d 100644 --- a/yarn-project/aztec-nr/aztec/src/note.nr +++ b/yarn-project/aztec-nr/aztec/src/note.nr @@ -1,7 +1,6 @@ mod lifecycle; mod note_getter; mod note_getter_options; -mod note_hash; mod note_header; mod note_interface; mod note_viewer_options; diff --git a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr index ec741e6dbae..d91154e72d8 100644 --- a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr +++ b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr @@ -6,7 +6,7 @@ use crate::context::{ use crate::note::{ note_header::NoteHeader, note_interface::NoteInterface, - utils::compute_inner_note_hash, + utils::compute_note_hash_for_read_or_nullify, }; use crate::oracle::notes::{notify_created_note, notify_nullified_note}; @@ -22,7 +22,8 @@ pub fn create_note( let header = NoteHeader { contract_address, storage_slot, nonce: 0, is_transient: true }; let set_header = note_interface.set_header; set_header(note, header); - let inner_note_hash = compute_inner_note_hash(note_interface, *note); + // As `is_transient` is true, this will compute the inner note hsah + let inner_note_hash = compute_note_hash_for_read_or_nullify(note_interface, *note); let serialize = note_interface.serialize; let serialized_note = serialize(*note); @@ -47,7 +48,7 @@ pub fn create_note_hash_from_public( let header = NoteHeader { contract_address, storage_slot, nonce: 0, is_transient: true }; let set_header = note_interface.set_header; set_header(note, header); - let inner_note_hash = compute_inner_note_hash(note_interface, *note); + let inner_note_hash = compute_note_hash_for_read_or_nullify(note_interface, *note); context.push_new_note_hash(inner_note_hash); } @@ -72,7 +73,7 @@ pub fn destroy_note( // just siloes and forwards the nullifier to its output. if (header.is_transient) { // TODO(1718): Can we reuse the note commitment computed in `compute_nullifier`? - nullified_commitment = compute_inner_note_hash(note_interface, note); + nullified_commitment = compute_note_hash_for_read_or_nullify(note_interface, note); } assert(notify_nullified_note(nullifier, nullified_commitment) == 0); diff --git a/yarn-project/aztec-nr/aztec/src/note/note_hash.nr b/yarn-project/aztec-nr/aztec/src/note/note_hash.nr deleted file mode 100644 index 8f0abd7d3db..00000000000 --- a/yarn-project/aztec-nr/aztec/src/note/note_hash.nr +++ /dev/null @@ -1,23 +0,0 @@ -use dep::protocol_types::{ - address::AztecAddress, - constants::{ - GENERATOR_INDEX__UNIQUE_COMMITMENT, - GENERATOR_INDEX__SILOED_COMMITMENT, - }, - hash::pedersen_hash, -}; - -pub fn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field { - // TODO(#1205) Do we need a generator index here? - pedersen_hash([storage_slot, note_hash], 0) -} - -pub fn compute_siloed_hash(contract_address: AztecAddress, inner_note_hash: Field) -> Field { - let inputs = [contract_address.to_field(), inner_note_hash]; - pedersen_hash(inputs, GENERATOR_INDEX__SILOED_COMMITMENT) -} - -pub fn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field { - let inputs = [nonce, siloed_note_hash]; - pedersen_hash(inputs, GENERATOR_INDEX__UNIQUE_COMMITMENT) -} diff --git a/yarn-project/aztec-nr/aztec/src/note/utils.nr b/yarn-project/aztec-nr/aztec/src/note/utils.nr index 5d88d904a77..e38a141e6cd 100644 --- a/yarn-project/aztec-nr/aztec/src/note/utils.nr +++ b/yarn-project/aztec-nr/aztec/src/note/utils.nr @@ -1,18 +1,38 @@ -use dep::protocol_types::{ - constants::GENERATOR_INDEX__OUTER_NULLIFIER, - hash::pedersen_hash, -}; use crate::{ context::PrivateContext, note::{ - note_hash::{compute_inner_hash, compute_siloed_hash, compute_unique_hash}, note_header::NoteHeader, note_interface::NoteInterface, }, utils::arr_copy_slice, }; -pub fn compute_inner_note_hash(note_interface: NoteInterface, note: Note) -> Field { +use dep::protocol_types::{ + address::AztecAddress, + constants::{ + GENERATOR_INDEX__OUTER_NULLIFIER, + GENERATOR_INDEX__UNIQUE_COMMITMENT, + GENERATOR_INDEX__SILOED_COMMITMENT, + }, + hash::pedersen_hash, +}; + +fn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field { + // TODO(#1205) Do we need a generator index here? + pedersen_hash([storage_slot, note_hash], 0) +} + +fn compute_siloed_hash(contract_address: AztecAddress, inner_note_hash: Field) -> Field { + let inputs = [contract_address.to_field(), inner_note_hash]; + pedersen_hash(inputs, GENERATOR_INDEX__SILOED_COMMITMENT) +} + +fn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field { + let inputs = [nonce, siloed_note_hash]; + pedersen_hash(inputs, GENERATOR_INDEX__UNIQUE_COMMITMENT) +} + +fn compute_inner_note_hash(note_interface: NoteInterface, note: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note); @@ -22,7 +42,7 @@ pub fn compute_inner_note_hash(note_interface: NoteInterface, compute_inner_hash(header.storage_slot, note_hash) } -pub fn compute_siloed_note_hash(note_interface: NoteInterface, note_with_header: Note) -> Field { +fn compute_siloed_note_hash(note_interface: NoteInterface, note_with_header: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note_with_header); @@ -31,7 +51,7 @@ pub fn compute_siloed_note_hash(note_interface: NoteInterface, compute_siloed_hash(header.contract_address, inner_note_hash) } -pub fn compute_unique_siloed_note_hash(note_interface: NoteInterface, note_with_header: Note) -> Field { +fn compute_unique_siloed_note_hash(note_interface: NoteInterface, note_with_header: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note_with_header); diff --git a/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index 779c8debecc..d02320b5ea8 100644 --- a/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/yarn-project/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -3,7 +3,7 @@ use dep::aztec::{ note::{ note_header::NoteHeader, note_interface::NoteInterface, - utils::compute_unique_siloed_note_hash, + utils::compute_note_hash_for_read_or_nullify, }, oracle::{ nullifier_key::get_nullifier_secret_key, @@ -61,7 +61,7 @@ impl EcdsaPublicKeyNote { } pub fn compute_nullifier(self, context: &mut PrivateContext) -> Field { - let unique_siloed_note_hash = compute_unique_siloed_note_hash(EcdsaPublicKeyNoteInterface, self); + let unique_siloed_note_hash = compute_note_hash_for_read_or_nullify(EcdsaPublicKeyNoteInterface, self); let secret = context.request_nullifier_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([ @@ -72,7 +72,7 @@ impl EcdsaPublicKeyNote { } pub fn compute_nullifier_without_context(self) -> Field { - let unique_siloed_note_hash = compute_unique_siloed_note_hash(EcdsaPublicKeyNoteInterface, self); + let unique_siloed_note_hash = compute_note_hash_for_read_or_nullify(EcdsaPublicKeyNoteInterface, self); let secret = get_nullifier_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([ diff --git a/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index 2db16db6be3..82330325d1a 100644 --- a/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/yarn-project/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -2,7 +2,7 @@ use dep::aztec::{ note::{ note_header::NoteHeader, note_interface::NoteInterface, - utils::compute_unique_siloed_note_hash, + utils::compute_note_hash_for_read_or_nullify, }, hash::pedersen_hash, oracle::{ @@ -41,7 +41,7 @@ impl PublicKeyNote { } pub fn compute_nullifier(self, context: &mut PrivateContext) -> Field { - let unique_siloed_note_hash = compute_unique_siloed_note_hash(PublicKeyNoteMethods, self); + let unique_siloed_note_hash = compute_note_hash_for_read_or_nullify(PublicKeyNoteMethods, self); let secret = context.request_nullifier_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([ @@ -52,7 +52,7 @@ impl PublicKeyNote { } pub fn compute_nullifier_without_context(self) -> Field { - let unique_siloed_note_hash = compute_unique_siloed_note_hash(PublicKeyNoteMethods, self); + let unique_siloed_note_hash = compute_note_hash_for_read_or_nullify(PublicKeyNoteMethods, self); let secret = get_nullifier_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([ diff --git a/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index 98867d1225c..36658d459cc 100644 --- a/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/yarn-project/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -3,7 +3,7 @@ use dep::aztec::{ note::{ note_header::NoteHeader, note_interface::NoteInterface, - utils::compute_siloed_note_hash, + utils::compute_note_hash_for_read_or_nullify, }, hash::{compute_secret_hash, pedersen_hash}, context::PrivateContext, @@ -75,8 +75,7 @@ impl TransparentNote { } pub fn compute_nullifier_without_context(self) -> Field { - // TODO(#1386): should use `compute_note_hash_for_read_or_nullify` once public functions inject nonce! - let siloed_note_hash = compute_siloed_note_hash(TransparentNoteMethods, self); + let siloed_note_hash = compute_note_hash_for_read_or_nullify(TransparentNoteMethods, self); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([self.secret, siloed_note_hash],0) } diff --git a/yarn-project/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/yarn-project/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index deb2bcdf6f1..361413bc82b 100644 --- a/yarn-project/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/yarn-project/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -3,7 +3,7 @@ use dep::aztec::{ note::{ note_header::NoteHeader, note_interface::NoteInterface, - utils::compute_siloed_note_hash, + utils::compute_note_hash_for_read_or_nullify, }, hash::{compute_secret_hash, pedersen_hash}, context::PrivateContext, @@ -75,8 +75,7 @@ impl TransparentNote { } pub fn compute_nullifier_without_context(self) -> Field { - // TODO(#1386): should use `compute_note_hash_for_read_or_nullify` once public functions inject nonce! - let siloed_note_hash = compute_siloed_note_hash(TransparentNoteMethods, self); + let siloed_note_hash = compute_note_hash_for_read_or_nullify(TransparentNoteMethods, self); // TODO(#1205) Should use a non-zero generator index. pedersen_hash([self.secret, siloed_note_hash],0) }