From 50a50693b085dc9cd071fae2cb82b455f11e6990 Mon Sep 17 00:00:00 2001 From: dbanks12 Date: Wed, 25 Sep 2024 21:13:21 +0000 Subject: [PATCH] DO NOT MERGE: switch slot derivation to poseidon2 instead of pedersen --- .../noir-protocol-circuits/crates/types/src/storage/map.nr | 6 +++--- yarn-project/circuits.js/src/hash/map_slot.test.ts | 2 +- yarn-project/circuits.js/src/hash/map_slot.ts | 4 ++-- .../sequencer-client/src/tx_validator/gas_validator.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/storage/map.nr b/noir-projects/noir-protocol-circuits/crates/types/src/storage/map.nr index 13a82bc58b58..3f20295d9bd2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/storage/map.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/storage/map.nr @@ -1,7 +1,7 @@ -use crate::{hash::pedersen_hash, traits::ToField}; +use crate::{hash::poseidon2_hash, traits::ToField}; pub fn derive_storage_slot_in_map(storage_slot: Field, key: K) -> Field where K: ToField { - pedersen_hash([storage_slot, key.to_field()], 0) + poseidon2_hash([storage_slot, key.to_field()]) } mod test { @@ -15,7 +15,7 @@ mod test { let slot = derive_storage_slot_in_map(map_slot, key); // The following value was generated by `map_slot.test.ts` - let slot_from_typescript = 0x2499880e2b1b831785c17286f99a0d5122fee784ce7b1c04e380c4a991da819a; + let slot_from_typescript = 0x15b9fe39449affd8b377461263e9d2b610b9ad40580553500b4e41d9cbd887ac; assert_eq(slot, slot_from_typescript); } diff --git a/yarn-project/circuits.js/src/hash/map_slot.test.ts b/yarn-project/circuits.js/src/hash/map_slot.test.ts index e43047d4b2d3..f21df688f33f 100644 --- a/yarn-project/circuits.js/src/hash/map_slot.test.ts +++ b/yarn-project/circuits.js/src/hash/map_slot.test.ts @@ -12,7 +12,7 @@ describe('Map slot', () => { const slot = deriveStorageSlotInMap(mapSlot, key); expect(slot.toString()).toMatchInlineSnapshot( - `"0x2499880e2b1b831785c17286f99a0d5122fee784ce7b1c04e380c4a991da819a"`, + `"0x15b9fe39449affd8b377461263e9d2b610b9ad40580553500b4e41d9cbd887ac"`, ); // Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data diff --git a/yarn-project/circuits.js/src/hash/map_slot.ts b/yarn-project/circuits.js/src/hash/map_slot.ts index d14b85b0ea9f..8ffed794039d 100644 --- a/yarn-project/circuits.js/src/hash/map_slot.ts +++ b/yarn-project/circuits.js/src/hash/map_slot.ts @@ -1,4 +1,4 @@ -import { pedersenHash } from '@aztec/foundation/crypto'; +import { poseidon2Hash } from '@aztec/foundation/crypto'; import { type Fr } from '@aztec/foundation/fields'; /** @@ -14,5 +14,5 @@ export function deriveStorageSlotInMap( toField: () => Fr; }, ): Fr { - return pedersenHash([mapSlot, key.toField()]); + return poseidon2Hash([mapSlot, key.toField()]); } diff --git a/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts b/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts index c14b8792083f..23f368a4dd93 100644 --- a/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts +++ b/yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts @@ -1,6 +1,6 @@ import { type Tx, mockTx } from '@aztec/circuit-types'; import { AztecAddress, Fr, FunctionSelector, GasSettings } from '@aztec/circuits.js'; -import { pedersenHash } from '@aztec/foundation/crypto'; +import { poseidon2Hash } from '@aztec/foundation/crypto'; import { FeeJuiceContract } from '@aztec/noir-contracts.js'; import { FeeJuiceAddress } from '@aztec/protocol-contracts/fee-juice'; @@ -37,7 +37,7 @@ describe('GasTxValidator', () => { inclusionFee: new Fr(TX_FEE), }); payer = tx.data.feePayer; - expectedBalanceSlot = pedersenHash([FeeJuiceContract.storage.balances.slot, payer]); + expectedBalanceSlot = poseidon2Hash([FeeJuiceContract.storage.balances.slot, payer]); expect(tx.data.constants.txContext.gasSettings.getFeeLimit()).toEqual(new Fr(TX_FEE)); });