From 08b85bd7dc9d4db369bc2f2273f595ed6a6ed976 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 22 Apr 2024 15:09:38 +0000 Subject: [PATCH] WIP --- noir-projects/aztec-nr/address-note/src/address_note.nr | 8 ++++---- noir-projects/aztec-nr/aztec/src/hash.nr | 4 ++-- noir-projects/aztec-nr/value-note/src/value_note.nr | 6 +++--- .../app_subscription_contract/src/subscription_note.nr | 6 +++--- .../docs_example_contract/src/types/card_note.nr | 6 +++--- .../ecdsa_account_contract/src/ecdsa_public_key_note.nr | 6 +++--- .../schnorr_account_contract/src/public_key_note.nr | 6 +++--- .../token_blacklist_contract/src/types/token_note.nr | 6 +++--- .../src/types/transparent_note.nr | 4 ++-- .../contracts/token_contract/src/types/token_note.nr | 6 +++--- .../token_contract/src/types/transparent_note.nr | 4 ++-- .../noir-protocol-circuits/crates/types/src/constants.nr | 3 ++- yarn-project/circuits.js/src/constants.gen.ts | 3 ++- yarn-project/circuits.js/src/hash/hash.ts | 2 +- .../simulator/src/client/private_execution.test.ts | 4 ++-- yarn-project/simulator/src/client/simulator.test.ts | 6 +++++- 16 files changed, 43 insertions(+), 37 deletions(-) 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 c940d8b404a1..982b9ba00530 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -2,7 +2,7 @@ use dep::aztec::log::emit_encrypted_log; // docs:end:encrypted_import use dep::aztec::{ - protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NULLIFIER}, + protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER}, note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption}, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, context::PrivateContext, hash::poseidon2_hash @@ -19,7 +19,7 @@ struct AddressNote { randomness: Field, } -impl NoteInterface for AddressNote { +impl NoteInterface for AddressNote { fn compute_nullifier(self, context: &mut PrivateContext) -> Field { let note_hash_for_nullify = compute_note_hash_for_consumption(self); @@ -27,7 +27,7 @@ impl NoteInterface for AddressNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } @@ -37,7 +37,7 @@ impl NoteInterface for AddressNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } diff --git a/noir-projects/aztec-nr/aztec/src/hash.nr b/noir-projects/aztec-nr/aztec/src/hash.nr index 8406cf8c2983..4b12c21ea756 100644 --- a/noir-projects/aztec-nr/aztec/src/hash.nr +++ b/noir-projects/aztec-nr/aztec/src/hash.nr @@ -1,7 +1,7 @@ use dep::protocol_types::{ address::{AztecAddress, EthAddress}, constants::{ - GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET, GENERATOR_INDEX__NULLIFIER, ARGS_HASH_CHUNK_COUNT, + GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET, GENERATOR_INDEX__MESSAGE_NULLIFIER, ARGS_HASH_CHUNK_COUNT, GENERATOR_INDEX__FUNCTION_ARGS, ARGS_HASH_CHUNK_LENGTH }, traits::Hash, hash::{pedersen_hash, poseidon2_hash, silo_nullifier, sha256_to_field} @@ -45,7 +45,7 @@ pub fn compute_message_hash( pub fn compute_message_nullifier(message_hash: Field, secret: Field, leaf_index: Field) -> Field { pedersen_hash( [message_hash, secret, leaf_index], - GENERATOR_INDEX__NULLIFIER + GENERATOR_INDEX__MESSAGE_NULLIFIER ) } 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 31d0fb7d6958..b67cd8a98dcb 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -1,7 +1,7 @@ use dep::aztec::{ protocol_types::{ address::AztecAddress, traits::{Deserialize, Serialize}, - constants::GENERATOR_INDEX__NULLIFIER + constants::GENERATOR_INDEX__NOTE_NULLIFIER }, note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption}, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, @@ -28,7 +28,7 @@ impl NoteInterface for ValueNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } @@ -40,7 +40,7 @@ impl NoteInterface for ValueNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 c24e8e6ee745..435f61191b3e 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 @@ -1,6 +1,6 @@ use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, emit_encrypted_log, NoteInterface}; use dep::aztec::{ - protocol_types::constants::GENERATOR_INDEX__NULLIFIER, note::utils::compute_note_hash_for_consumption, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key} }; @@ -23,7 +23,7 @@ impl NoteInterface for SubscriptionNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } @@ -33,7 +33,7 @@ impl NoteInterface for SubscriptionNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 c4ecfacc3239..efab4af48920 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 @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContex use dep::aztec::{ note::{utils::compute_note_hash_for_consumption}, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, - hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NULLIFIER}, + hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER}, }; // Shows how to create a custom note @@ -31,7 +31,7 @@ impl NoteInterface for CardNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } @@ -41,7 +41,7 @@ impl NoteInterface for CardNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 62a22e438d1c..b97ff8bad97f 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 @@ -6,7 +6,7 @@ use dep::aztec::prelude::{ use dep::aztec::{ note::utils::compute_note_hash_for_consumption, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, - hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NULLIFIER, + hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, }; global ECDSA_PUBLIC_KEY_NOTE_LEN: Field = 5; @@ -72,7 +72,7 @@ impl NoteInterface for EcdsaPublicKeyNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } @@ -82,7 +82,7 @@ impl NoteInterface for EcdsaPublicKeyNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 66c1b77ac268..c0031833c26c 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 @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContex use dep::aztec::{ note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, - protocol_types::constants::GENERATOR_INDEX__NULLIFIER, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, }; global PUBLIC_KEY_NOTE_LEN: Field = 3; @@ -23,7 +23,7 @@ impl NoteInterface for PublicKeyNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } @@ -33,7 +33,7 @@ impl NoteInterface for PublicKeyNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 3ac3081ba778..87ac609218c3 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 @@ -1,6 +1,6 @@ use dep::aztec::{ prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log}, - protocol_types::constants::GENERATOR_INDEX__NULLIFIER, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, }; @@ -33,7 +33,7 @@ impl NoteInterface for TokenNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } // docs:end:nullifier @@ -44,7 +44,7 @@ impl NoteInterface for TokenNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 9b4eb9ef23a5..d5cf7197cef6 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 @@ -2,7 +2,7 @@ use dep::aztec::{ note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption}, hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext}, - protocol_types::constants::GENERATOR_INDEX__NULLIFIER + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER }; global TRANSPARENT_NOTE_LEN: Field = 2; @@ -55,7 +55,7 @@ impl NoteInterface for TransparentNote { let note_hash_for_nullify = compute_note_hash_for_consumption(self); poseidon2_hash([ note_hash_for_nullify, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 3ac3081ba778..87ac609218c3 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 @@ -1,6 +1,6 @@ use dep::aztec::{ prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log}, - protocol_types::constants::GENERATOR_INDEX__NULLIFIER, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, }; @@ -33,7 +33,7 @@ impl NoteInterface for TokenNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } // docs:end:nullifier @@ -44,7 +44,7 @@ impl NoteInterface for TokenNote { poseidon2_hash([ note_hash_for_nullify, secret, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } 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 9b4eb9ef23a5..d5cf7197cef6 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 @@ -2,7 +2,7 @@ use dep::aztec::{ note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption}, hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext}, - protocol_types::constants::GENERATOR_INDEX__NULLIFIER + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER }; global TRANSPARENT_NOTE_LEN: Field = 2; @@ -55,7 +55,7 @@ impl NoteInterface for TransparentNote { let note_hash_for_nullify = compute_note_hash_for_consumption(self); poseidon2_hash([ note_hash_for_nullify, - GENERATOR_INDEX__NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field, ]) } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 7faf3c22c0e8..4e8887b4de35 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -199,7 +199,7 @@ global GENERATOR_INDEX__NOTE_HASH = 1; global GENERATOR_INDEX__NOTE_HASH_NONCE = 2; global GENERATOR_INDEX__UNIQUE_NOTE_HASH = 3; global GENERATOR_INDEX__SILOED_NOTE_HASH = 4; -global GENERATOR_INDEX__NULLIFIER = 5; +global GENERATOR_INDEX__MESSAGE_NULLIFIER = 5; global GENERATOR_INDEX__INITIALIZATION_NULLIFIER = 6; global GENERATOR_INDEX__OUTER_NULLIFIER = 7; global GENERATOR_INDEX__PUBLIC_DATA_READ = 8; @@ -242,3 +242,4 @@ global GENERATOR_INDEX__IVSK_M = 48; global GENERATOR_INDEX__OVSK_M = 49; global GENERATOR_INDEX__TSK_M = 50; global GENERATOR_INDEX__PUBLIC_KEYS_HASH = 51; +global GENERATOR_INDEX__NOTE_NULLIFIER = 52; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 4a8b78294c12..f36019aff279 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -163,7 +163,7 @@ export enum GeneratorIndex { NOTE_HASH_NONCE = 2, UNIQUE_NOTE_HASH = 3, SILOED_NOTE_HASH = 4, - NULLIFIER = 5, + MESSAGE_NULLIFIER = 5, INITIALIZATION_NULLIFIER = 6, OUTER_NULLIFIER = 7, PUBLIC_DATA_READ = 8, @@ -202,4 +202,5 @@ export enum GeneratorIndex { OVSK_M = 49, TSK_M = 50, PUBLIC_KEYS_HASH = 51, + NOTE_NULLIFIER = 52, } diff --git a/yarn-project/circuits.js/src/hash/hash.ts b/yarn-project/circuits.js/src/hash/hash.ts index b5496f757139..f06cbdbec561 100644 --- a/yarn-project/circuits.js/src/hash/hash.ts +++ b/yarn-project/circuits.js/src/hash/hash.ts @@ -171,6 +171,6 @@ export function computeL1ToL2MessageNullifier( secret: Fr, messageIndex: bigint, ) { - const innerMessageNullifier = pedersenHash([messageHash, secret, messageIndex], GeneratorIndex.NULLIFIER); + const innerMessageNullifier = pedersenHash([messageHash, secret, messageIndex], GeneratorIndex.MESSAGE_NULLIFIER); return siloNullifier(contract, innerMessageNullifier); } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 39b113f07fcd..370416c79c80 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -897,7 +897,7 @@ describe('Private Execution test suite', () => { const expectedNullifier = poseidon2Hash([ innerNoteHash, computeAppNullifierSecretKey(ownerMasterNullifierSecretKey, contractAddress), - GeneratorIndex.NULLIFIER, + GeneratorIndex.NOTE_NULLIFIER, ]); expect(nullifier.value).toEqual(expectedNullifier); }); @@ -968,7 +968,7 @@ describe('Private Execution test suite', () => { const expectedNullifier = poseidon2Hash([ innerNoteHash, computeAppNullifierSecretKey(ownerMasterNullifierSecretKey, contractAddress), - GeneratorIndex.NULLIFIER, + GeneratorIndex.NOTE_NULLIFIER, ]); expect(nullifier.value).toEqual(expectedNullifier); }); diff --git a/yarn-project/simulator/src/client/simulator.test.ts b/yarn-project/simulator/src/client/simulator.test.ts index 4e18033ec6ba..87ca2ef7fc4e 100644 --- a/yarn-project/simulator/src/client/simulator.test.ts +++ b/yarn-project/simulator/src/client/simulator.test.ts @@ -67,7 +67,11 @@ describe('Simulator', () => { const innerNoteHash = pedersenHash([storageSlot, tokenNoteHash]); const siloedNoteHash = siloNoteHash(contractAddress, innerNoteHash); const uniqueSiloedNoteHash = computeUniqueCommitment(nonce, siloedNoteHash); - const innerNullifier = poseidon2Hash([uniqueSiloedNoteHash, appNullifierSecretKey, GeneratorIndex.NULLIFIER]); + const innerNullifier = poseidon2Hash([ + uniqueSiloedNoteHash, + appNullifierSecretKey, + GeneratorIndex.NOTE_NULLIFIER, + ]); const result = await simulator.computeNoteHashAndNullifier(contractAddress, nonce, storageSlot, noteTypeId, note);