From 7a3a9d9b0d560ccec6639ac721474e6582fa461d Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 22 Apr 2024 11:02:43 +0000 Subject: [PATCH] WIP --- .../src/subscription_note.nr | 2 +- .../src/types/card_note.nr | 12 +++++---- .../src/ecdsa_public_key_note.nr | 22 ++++++++-------- .../src/public_key_note.nr | 25 +++++++++--------- .../src/types/token_note.nr | 21 ++++++++------- .../src/types/transparent_note.nr | 12 +++++---- .../token_contract/src/types/token_note.nr | 26 +++++++++---------- .../src/types/transparent_note.nr | 12 +++++---- 8 files changed, 71 insertions(+), 61 deletions(-) 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 0b30b02b70e..c24e8e6ee74 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::{ - constants::GENERATOR_INDEX__NULLIFIER, note::utils::compute_note_hash_for_consumption, + protocol_types::constants::GENERATOR_INDEX__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} }; 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 617b24ef025..c4ecfacc323 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::pedersen_hash, protocol_types::traits::Empty + hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NULLIFIER}, }; // Shows how to create a custom note @@ -28,19 +28,21 @@ impl NoteInterface for CardNote { 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); - pedersen_hash([ + poseidon2_hash([ note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_app_nullifier_secret_key(self.owner); - pedersen_hash([ + poseidon2_hash([ note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // Broadcasts the note as an encrypted log on L1. 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 22144f965af..62a22e438d1 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::pedersen_hash + hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NULLIFIER, }; global ECDSA_PUBLIC_KEY_NOTE_LEN: Field = 5; @@ -67,23 +67,23 @@ impl NoteInterface for EcdsaPublicKeyNote { } fn compute_nullifier(self, context: &mut PrivateContext) -> Field { - let unique_siloed_note_hash = compute_note_hash_for_consumption(self); + let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_app_nullifier_secret_key(self.owner); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ - unique_siloed_note_hash, + poseidon2_hash([ + note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } fn compute_nullifier_without_context(self) -> Field { - let unique_siloed_note_hash = compute_note_hash_for_consumption(self); + let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_app_nullifier_secret_key(self.owner); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ - unique_siloed_note_hash, + poseidon2_hash([ + note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // Broadcasts the note as an encrypted log on L1. 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 39d25636db7..66c1b77ac26 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 @@ -1,7 +1,8 @@ use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log}; use dep::aztec::{ - note::utils::compute_note_hash_for_consumption, hash::pedersen_hash, - oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key} + 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, }; global PUBLIC_KEY_NOTE_LEN: Field = 3; @@ -17,23 +18,23 @@ struct PublicKeyNote { impl NoteInterface for PublicKeyNote { fn compute_nullifier(self, context: &mut PrivateContext) -> Field { - let unique_siloed_note_hash = compute_note_hash_for_consumption(self); + let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_app_nullifier_secret_key(self.owner); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ - unique_siloed_note_hash, + poseidon2_hash([ + note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } fn compute_nullifier_without_context(self) -> Field { - let unique_siloed_note_hash = compute_note_hash_for_consumption(self); + let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_app_nullifier_secret_key(self.owner); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ - unique_siloed_note_hash, + poseidon2_hash([ + note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // Broadcasts the note as an encrypted log on L1. 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 3bd6b23d854..3ac3081ba77 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,9 @@ -use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log}; -use dep::aztec::{note::utils::compute_note_hash_for_consumption, hash::pedersen_hash}; -use dep::aztec::oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}; +use dep::aztec::{ + prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log}, + protocol_types::constants::GENERATOR_INDEX__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}, +}; trait OwnedNote { fn new(amount: U128, owner: AztecAddress) -> Self; @@ -27,22 +30,22 @@ impl NoteInterface for TokenNote { 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); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ + poseidon2_hash([ note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // docs:end:nullifier fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_app_nullifier_secret_key(self.owner); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ + poseidon2_hash([ note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // Broadcasts the note as an encrypted log on L1. 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 3e722a207f8..9b4eb9ef23a 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 @@ -1,8 +1,8 @@ // docs:start:token_types_all -use dep::aztec::prelude::{NoteHeader, NoteInterface, PrivateContext}; use dep::aztec::{ note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption}, - hash::{compute_secret_hash, pedersen_hash} + hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext}, + protocol_types::constants::GENERATOR_INDEX__NULLIFIER }; global TRANSPARENT_NOTE_LEN: Field = 2; @@ -52,9 +52,11 @@ impl NoteInterface for TransparentNote { // circuit. // This achieves that the note can only be spent by the party that knows the secret. fn compute_nullifier_without_context(self) -> Field { - let siloed_note_hash = compute_note_hash_for_consumption(self); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([siloed_note_hash], 0) + let note_hash_for_nullify = compute_note_hash_for_consumption(self); + poseidon2_hash([ + note_hash_for_nullify, + GENERATOR_INDEX__NULLIFIER as Field, + ]) } fn broadcast(self, context: &mut PrivateContext, slot: 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 cd76d49659c..3ac3081ba77 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,9 +1,9 @@ -use dep::aztec::prelude::{ - AztecAddress, NoteInterface, NoteGetterOptions, NoteViewerOptions, NoteHeader, PrivateContext, - PrivateSet, Map, emit_encrypted_log +use dep::aztec::{ + prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log}, + protocol_types::constants::GENERATOR_INDEX__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}, }; -use dep::aztec::{note::utils::compute_note_hash_for_consumption, hash::pedersen_hash}; -use dep::aztec::oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}; trait OwnedNote { fn new(amount: U128, owner: AztecAddress) -> Self; @@ -30,22 +30,22 @@ impl NoteInterface for TokenNote { 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); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ + poseidon2_hash([ note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // docs:end:nullifier fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_app_nullifier_secret_key(self.owner); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ + poseidon2_hash([ note_hash_for_nullify, secret, - ],0) + GENERATOR_INDEX__NULLIFIER as Field, + ]) } // Broadcasts the note as an encrypted log on L1. @@ -63,7 +63,7 @@ impl NoteInterface for TokenNote { ); } } - } +} impl OwnedNote for TokenNote { fn new(amount: U128, owner: AztecAddress) -> Self { @@ -82,5 +82,5 @@ impl OwnedNote for TokenNote { fn get_owner(self) -> AztecAddress { self.owner } - + } 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 3e722a207f8..9b4eb9ef23a 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 @@ -1,8 +1,8 @@ // docs:start:token_types_all -use dep::aztec::prelude::{NoteHeader, NoteInterface, PrivateContext}; use dep::aztec::{ note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption}, - hash::{compute_secret_hash, pedersen_hash} + hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext}, + protocol_types::constants::GENERATOR_INDEX__NULLIFIER }; global TRANSPARENT_NOTE_LEN: Field = 2; @@ -52,9 +52,11 @@ impl NoteInterface for TransparentNote { // circuit. // This achieves that the note can only be spent by the party that knows the secret. fn compute_nullifier_without_context(self) -> Field { - let siloed_note_hash = compute_note_hash_for_consumption(self); - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([siloed_note_hash], 0) + let note_hash_for_nullify = compute_note_hash_for_consumption(self); + poseidon2_hash([ + note_hash_for_nullify, + GENERATOR_INDEX__NULLIFIER as Field, + ]) } fn broadcast(self, context: &mut PrivateContext, slot: Field) {