diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr index 095f870193b5..73497221da43 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr @@ -6,7 +6,7 @@ use dep::aztec::macros::aztec; #[aztec] contract CardGame { use dep::aztec::protocol_types::address::AztecAddress; - use dep::aztec::{hash::pedersen_hash, state_vars::{Map, PublicMutable}}; + use dep::aztec::{hash::poseidon2_hash, state_vars::{Map, PublicMutable}}; use dep::aztec::note::constants::MAX_NOTES_PER_PAGE; @@ -99,7 +99,7 @@ contract CardGame { let mut collection = storage.collections.at(player); let _inserted_cards = collection.add_cards(cards, player); - CardGame::at(context.this_address()).on_cards_claimed(game, player, pedersen_hash(cards_fields, 0)).enqueue(&mut context); + CardGame::at(context.this_address()).on_cards_claimed(game, player, poseidon2_hash(cards_fields)).enqueue(&mut context); } #[public] @@ -111,7 +111,7 @@ contract CardGame { assert(!game_data.claimed, "Already claimed"); game_data.claimed = true; - assert_eq(cards_hash, pedersen_hash(game_data.rounds_cards.map(|card: Card| card.to_field()), 0)); + assert_eq(cards_hash, poseidon2_hash(game_data.rounds_cards.map(|card: Card| card.to_field()))); let winner = game_data.winner(); assert(player.eq(winner.address), "Not the winner"); diff --git a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr index 55539d9e4b5c..1e641dd0c077 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr @@ -5,7 +5,7 @@ contract EasyPrivateVoting { // docs:start:imports use dep::aztec::prelude::{AztecAddress, Map, PublicMutable, SharedImmutable}; use dep::aztec::{ - keys::getters::get_public_keys, + hash::poseidon2_hash, keys::getters::get_public_keys, macros::{storage::storage, functions::{public, initializer, private, internal}} }; // docs:end:imports @@ -35,7 +35,7 @@ contract EasyPrivateVoting { let msg_sender_npk_m_hash = get_public_keys(context.msg_sender()).npk_m.hash(); let secret = context.request_nsk_app(msg_sender_npk_m_hash); // get secret key of caller of function - let nullifier = std::hash::pedersen_hash([context.msg_sender().to_field(), secret]); // derive nullifier from sender and secret + let nullifier = poseidon2_hash([context.msg_sender().to_field(), secret]); // derive nullifier from sender and secret context.push_nullifier(nullifier); EasyPrivateVoting::at(context.this_address()).add_to_tally_public(candidate).enqueue(&mut context); } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/helpers.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/helpers.nr index c5e537e88edb..b7af91950be8 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/helpers.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/helpers.nr @@ -1,4 +1,4 @@ -use dep::aztec::hash::pedersen_hash; +use dep::aztec::hash::poseidon2_hash; // Utility used to easily get a "id" for a private user that sits in the same // "space" as the public users. @@ -7,7 +7,7 @@ pub fn compute_identifier(secret: Field, on_behalf_of: Field, self: Field) -> Fi // EITHER secret OR on_behalf_of MUST be set. But not both assert(!((secret == 0) as bool & (on_behalf_of == 0) as bool)); if (secret != 0) { - pedersen_hash([self, secret], 0) + poseidon2_hash([self, secret]) } else { on_behalf_of } diff --git a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr index cb72da92eecf..6b2319f1c076 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr @@ -10,17 +10,17 @@ contract NFT { use dep::compressed_string::FieldCompressedString; use dep::aztec::{ prelude::{NoteGetterOptions, NoteViewerOptions, Map, PublicMutable, SharedImmutable, PrivateSet, AztecAddress}, - encrypted_logs::{encrypted_note_emission::encode_and_encrypt_note}, hash::pedersen_hash, - keys::getters::get_public_keys, note::constants::MAX_NOTES_PER_PAGE, - protocol_types::traits::is_empty, utils::comparison::Comparator, - protocol_types::{point::Point, traits::Serialize}, + encrypted_logs::{encrypted_note_emission::encode_and_encrypt_note}, + hash::poseidon2_hash_with_separator, keys::getters::get_public_keys, + note::constants::MAX_NOTES_PER_PAGE, protocol_types::traits::is_empty, + utils::comparison::Comparator, protocol_types::{point::Point, traits::Serialize}, macros::{storage::storage, events::event, functions::{private, public, view, internal, initializer}} }; use dep::authwit::auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public, compute_authwit_nullifier}; use std::{embedded_curve_ops::EmbeddedCurvePoint, meta::derive}; use crate::types::nft_note::NFTNote; - global TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX = 3; + global TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX = 3; // TODO(#8467): Rename this to Transfer - calling this NFTTransfer to avoid export conflict with the Transfer event // in the Token contract. @@ -153,15 +153,15 @@ contract NFT { // We make the msg_sender/transfer_preparer part of the slot preimage to ensure he cannot interfere with // non-sender's slots - let transfer_preparer_storage_slot_commitment: Field = pedersen_hash( + let transfer_preparer_storage_slot_commitment: Field = poseidon2_hash_with_separator( [context.msg_sender().to_field(), transient_storage_slot_randomness], - TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX + TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX ); // Then we hash the transfer preparer storage slot commitment with `from` and use that as the final slot // --> by hashing it with a `from` we ensure that `from` cannot interfere with slots not assigned to him. - let slot: Field = pedersen_hash( + let slot: Field = poseidon2_hash_with_separator( [from.to_field(), transfer_preparer_storage_slot_commitment], - TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX + TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX ); NFT::at(context.this_address())._store_point_in_transient_storage(hiding_point.inner, slot).enqueue(&mut context); @@ -192,9 +192,9 @@ contract NFT { // Derive the slot from the transfer preparer storage slot commitment and the `from` address (declared // as `from` in this function) - let hiding_point_slot = pedersen_hash( + let hiding_point_slot = poseidon2_hash_with_separator( [from.to_field(), transfer_preparer_storage_slot_commitment], - TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX + TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX ); // Read the hiding point from "transient" storage and check it's not empty to ensure the transfer was prepared diff --git a/noir-projects/noir-contracts/contracts/nft_contract/src/test/transfer_to_private.nr b/noir-projects/noir-contracts/contracts/nft_contract/src/test/transfer_to_private.nr index 51350ae3adfe..b2cdae262ae5 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/test/transfer_to_private.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/test/transfer_to_private.nr @@ -1,7 +1,8 @@ use crate::test::utils; use dep::aztec::{ - hash::pedersen_hash, keys::getters::get_public_keys, prelude::{AztecAddress, NoteHeader}, - oracle::unsafe_rand::unsafe_rand, protocol_types::storage::map::derive_storage_slot_in_map + hash::poseidon2_hash_with_separator, keys::getters::get_public_keys, + prelude::{AztecAddress, NoteHeader}, oracle::unsafe_rand::unsafe_rand, + protocol_types::storage::map::derive_storage_slot_in_map }; use crate::{types::nft_note::NFTNote, NFT}; @@ -28,9 +29,9 @@ unconstrained fn transfer_to_private_to_a_different_account() { let note_randomness = unsafe_rand(); let transient_storage_slot_randomness = unsafe_rand(); // Sender will be the msg_sender/transfer_preparer in prepare_transfer_to_private - let transfer_preparer_storage_slot_commitment = pedersen_hash( + let transfer_preparer_storage_slot_commitment = poseidon2_hash_with_separator( [sender.to_field(), transient_storage_slot_randomness], - NFT::TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX + NFT::TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX ); // We prepare the transfer @@ -90,9 +91,9 @@ unconstrained fn transfer_to_private_finalizing_from_incorrect_sender() { let note_randomness = unsafe_rand(); let transient_storage_slot_randomness = unsafe_rand(); // Sender will be the msg_sender/transfer_preparer in prepare_transfer_to_private - let transfer_preparer_storage_slot_commitment = pedersen_hash( + let transfer_preparer_storage_slot_commitment = poseidon2_hash_with_separator( [correct_sender.to_field(), transient_storage_slot_randomness], - NFT::TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX + NFT::TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX ); // We prepare the transfer diff --git a/noir-projects/noir-contracts/contracts/nft_contract/src/test/utils.nr b/noir-projects/noir-contracts/contracts/nft_contract/src/test/utils.nr index 7b95f3efda39..641a5e1753e8 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/test/utils.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/test/utils.nr @@ -1,6 +1,6 @@ use dep::aztec::{ - hash::pedersen_hash, keys::getters::get_public_keys, prelude::{AztecAddress, NoteHeader}, - test::helpers::{cheatcodes, test_environment::TestEnvironment}, + hash::poseidon2_hash_with_separator, keys::getters::get_public_keys, + prelude::{AztecAddress, NoteHeader}, test::helpers::{cheatcodes, test_environment::TestEnvironment}, protocol_types::storage::map::derive_storage_slot_in_map, oracle::{execution::{get_block_number, get_contract_address}, unsafe_rand::unsafe_rand, storage::storage_read} }; @@ -52,9 +52,9 @@ unconstrained pub fn setup_mint_and_transfer_to_private(with_account_contracts: let note_randomness = unsafe_rand(); let transient_storage_slot_randomness = unsafe_rand(); - let transfer_preparer_storage_slot_commitment = pedersen_hash( + let transfer_preparer_storage_slot_commitment = poseidon2_hash_with_separator( [owner.to_field(), transient_storage_slot_randomness], - NFT::TRANSIENT_STORAGE_SLOT_PEDERSEN_INDEX + NFT::TRANSIENT_STORAGE_SLOT_POSEIDON_INDEX ); // We prepare the transfer with user being both the sender and the recipient (classical "shield" flow) diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index e0df663feaa4..023f91ad5b97 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -19,7 +19,7 @@ contract Test { use dep::aztec::keys::getters::get_public_keys; use dep::aztec::{ - hash::{pedersen_hash, compute_secret_hash, ArgsHasher}, keys::public_keys::IvpkM, + hash::{poseidon2_hash, compute_secret_hash, ArgsHasher}, keys::public_keys::IvpkM, note::{ lifecycle::{create_note, destroy_note_unsafe}, note_getter::{get_notes, view_notes}, note_getter_options::NoteStatus @@ -466,7 +466,7 @@ contract Test { } fn get_commitment(self) -> Field { - pedersen_hash([self.amount, self.secret_hash], 0) + poseidon2_hash([self.amount, self.secret_hash]) } }