From 945fb8567708d33475c28c9daa86580d4fb1ff84 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 22 Apr 2024 10:44:12 +0000 Subject: [PATCH] WIP --- .../aztec-nr/address-note/src/address_note.nr | 4 ++-- .../aztec-nr/value-note/src/value_note.nr | 19 ++++++++------- .../src/subscription_note.nr | 23 ++++++++++--------- 3 files changed, 25 insertions(+), 21 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 891b5a2f734..c940d8b404a 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -2,10 +2,10 @@ use dep::aztec::log::emit_encrypted_log; // docs:end:encrypted_import use dep::aztec::{ - protocol_types::{address::AztecAddress, traits::Empty, hash::poseidon2_hash, constants::GENERATOR_INDEX__NULLIFIER}, + protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__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 + context::PrivateContext, hash::poseidon2_hash }; global ADDRESS_NOTE_LEN: Field = 3; 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 8875209b9de..31d0fb7d695 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -1,8 +1,11 @@ use dep::aztec::{ - protocol_types::{address::AztecAddress, traits::{Deserialize, Serialize}}, + protocol_types::{ + address::AztecAddress, traits::{Deserialize, Serialize}, + constants::GENERATOR_INDEX__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}, - log::emit_encrypted_log, hash::pedersen_hash, context::PrivateContext + log::emit_encrypted_log, hash::poseidon2_hash, context::PrivateContext }; global VALUE_NOTE_LEN: Field = 3; // 3 plus a header. @@ -22,11 +25,11 @@ impl NoteInterface for ValueNote { 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 @@ -34,11 +37,11 @@ impl NoteInterface for ValueNote { 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/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index dc984c37338..0b30b02b70e 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,7 @@ use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, emit_encrypted_log, NoteInterface}; use dep::aztec::{ - note::utils::compute_note_hash_for_consumption, hash::pedersen_hash, + 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} }; @@ -17,23 +18,23 @@ struct SubscriptionNote { impl NoteInterface for SubscriptionNote { 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.