diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index bde4e4fefab..65b50a5878b 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -34,14 +34,15 @@ impl NoteInterface for AddressNote { [note_hash_for_nullify, nullifier] } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index eae2bd8a76e..8335af8f0b2 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -70,7 +70,7 @@ mod test { [1, 1] } - fn compute_nullifier_without_context(self) -> Field {1} + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {[1,1]} fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { [self.address.to_field(), self.owner.to_field(), self.randomness]} diff --git a/noir-projects/aztec-nr/aztec/src/note/note_interface.nr b/noir-projects/aztec-nr/aztec/src/note/note_interface.nr index 904b0236360..655287584a6 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_interface.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_interface.nr @@ -6,7 +6,7 @@ use dep::protocol_types::grumpkin_point::GrumpkinPoint; trait NoteInterface { fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> [Field; 2]; - fn compute_nullifier_without_context(self) -> Field; + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2]; // Autogenerated by the #[aztec(note)] macro unless it is overridden by a custom implementation fn serialize_content(self) -> [Field; N]; diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index 6b0b1c5e799..ab85b335607 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -128,7 +128,7 @@ pub fn compute_note_hash_and_optionally_a_nullifier( let siloed_note_hash = compute_siloed_hash(note_header.contract_address, unique_note_hash); let inner_nullifier = if compute_nullifier { - note.compute_nullifier_without_context() + note.compute_note_hash_and_nullifier_without_context()[1] } else { 0 }; diff --git a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr index cdbd196eb63..86a61bf5894 100644 --- a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr +++ b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr @@ -43,8 +43,8 @@ impl NoteInterface for MockNote { [0, 0] } - fn compute_nullifier_without_context(self) -> Field { - 0 + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { + [0, 0] } fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_BYTES_LENGTH] { diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index 6cdacc151c1..e91a08c1df1 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -37,14 +37,15 @@ impl NoteInterface for ValueNote { // docs:end:nullifier - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index c4247574f3f..e2e2884e565 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -30,14 +30,15 @@ impl NoteInterface for Subsc [note_hash_for_nullify, nullifier] } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index 7d060488f06..c9a0a7c000f 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -41,14 +41,15 @@ impl NoteInterface for CardNote { [note_hash_for_nullify, nullifier] } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index 9c27e4c7245..ab1c50ca145 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -76,14 +76,15 @@ impl NoteInterface f [note_hash_for_nullify, nullifier] } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index 36a7bdaa2f9..a9f88c877b1 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -30,14 +30,15 @@ impl NoteInterface for PublicKey [note_hash_for_nullify, nullifier] } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr index aadc5ee6193..e3c2c703d3b 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr @@ -23,9 +23,9 @@ impl NoteInterface for TestNote { [0, 0] } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { // This note is expected to be shared between users and for this reason can't be nullified using a secret. - 0 + [0, 0] } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 0b1571bbd19..e745772a5a2 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -38,14 +38,15 @@ impl NoteInterface for TokenNote { } // docs:end:nullifier - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index ed264101f66..30718662304 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -42,8 +42,7 @@ impl NoteInterface for Transpa // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): Ensure nullifier collisions are prevented fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> [Field; 2] { - // TODO(benesjan): Can we really return 0 for note hash here? Try just asser(false) here. - [0, self.compute_nullifier_without_context()] + self.compute_note_hash_and_nullifier_without_context() } // Computing a nullifier in a transparent note is not guarded by making secret a part of the nullifier preimage (as @@ -54,12 +53,13 @@ impl NoteInterface for Transpa // 3) the "get_notes" oracle constrains that the secret hash in the returned note matches the one computed in // circuit. // This achieves that the note can only be spent by the party that knows the secret. - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index 0b1571bbd19..e745772a5a2 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -38,14 +38,15 @@ impl NoteInterface for TokenNote { } // docs:end:nullifier - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index a253ec8180a..30718662304 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -42,8 +42,7 @@ impl NoteInterface for Transpa // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): Ensure nullifier collisions are prevented fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> [Field; 2] { - // TODO(benesjan): Can we really return 0 for note hash here? - [0, self.compute_nullifier_without_context()] + self.compute_note_hash_and_nullifier_without_context() } // Computing a nullifier in a transparent note is not guarded by making secret a part of the nullifier preimage (as @@ -54,12 +53,13 @@ impl NoteInterface for Transpa // 3) the "get_notes" oracle constrains that the secret hash in the returned note matches the one computed in // circuit. // This achieves that the note can only be spent by the party that knows the secret. - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] { let note_hash_for_nullify = compute_note_hash_for_consumption(self); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + [note_hash_for_nullify, nullifier] } }