Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 22, 2024
1 parent a08a49d commit 08b85bd
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 37 deletions.
8 changes: 4 additions & 4 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,15 +19,15 @@ struct AddressNote {
randomness: Field,
}

impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand All @@ -37,7 +37,7 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/hash.nr
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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
)
}

Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -28,7 +28,7 @@ impl NoteInterface<VALUE_NOTE_LEN> for ValueNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand All @@ -40,7 +40,7 @@ impl NoteInterface<VALUE_NOTE_LEN> for ValueNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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}
};
Expand All @@ -23,7 +23,7 @@ impl NoteInterface<SUBSCRIPTION_NOTE_LEN> for SubscriptionNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand All @@ -33,7 +33,7 @@ impl NoteInterface<SUBSCRIPTION_NOTE_LEN> for SubscriptionNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,7 +31,7 @@ impl NoteInterface<CARD_NOTE_LEN> for CardNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand All @@ -41,7 +41,7 @@ impl NoteInterface<CARD_NOTE_LEN> for CardNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand All @@ -82,7 +82,7 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +23,7 @@ impl NoteInterface<PUBLIC_KEY_NOTE_LEN> for PublicKeyNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand All @@ -33,7 +33,7 @@ impl NoteInterface<PUBLIC_KEY_NOTE_LEN> for PublicKeyNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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},
};
Expand Down Expand Up @@ -33,7 +33,7 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}
// docs:end:nullifier
Expand All @@ -44,7 +44,7 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN> 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,
])
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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},
};
Expand Down Expand Up @@ -33,7 +33,7 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}
// docs:end:nullifier
Expand All @@ -44,7 +44,7 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NULLIFIER as Field,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN> 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,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
3 changes: 2 additions & 1 deletion yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -202,4 +202,5 @@ export enum GeneratorIndex {
OVSK_M = 49,
TSK_M = 50,
PUBLIC_KEYS_HASH = 51,
NOTE_NULLIFIER = 52,
}
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/hash/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/simulator/src/client/simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 08b85bd

Please sign in to comment.