Skip to content

Commit e3e0b6f

Browse files
authored
feat!: switch slot derivation to poseidon2 instead of pedersen (#8801)
1 parent 03280e9 commit e3e0b6f

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

noir-projects/noir-protocol-circuits/crates/types/src/storage/map.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::{hash::pedersen_hash, traits::ToField};
1+
use crate::{hash::poseidon2_hash, traits::ToField};
22

33
pub fn derive_storage_slot_in_map<K>(storage_slot: Field, key: K) -> Field where K: ToField {
4-
pedersen_hash([storage_slot, key.to_field()], 0)
4+
poseidon2_hash([storage_slot, key.to_field()])
55
}
66

77
mod test {
@@ -15,7 +15,7 @@ mod test {
1515
let slot = derive_storage_slot_in_map(map_slot, key);
1616

1717
// The following value was generated by `map_slot.test.ts`
18-
let slot_from_typescript = 0x2499880e2b1b831785c17286f99a0d5122fee784ce7b1c04e380c4a991da819a;
18+
let slot_from_typescript = 0x15b9fe39449affd8b377461263e9d2b610b9ad40580553500b4e41d9cbd887ac;
1919

2020
assert_eq(slot, slot_from_typescript);
2121
}

yarn-project/circuits.js/src/hash/map_slot.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Map slot', () => {
1212
const slot = deriveStorageSlotInMap(mapSlot, key);
1313

1414
expect(slot.toString()).toMatchInlineSnapshot(
15-
`"0x2499880e2b1b831785c17286f99a0d5122fee784ce7b1c04e380c4a991da819a"`,
15+
`"0x15b9fe39449affd8b377461263e9d2b610b9ad40580553500b4e41d9cbd887ac"`,
1616
);
1717

1818
// Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data

yarn-project/circuits.js/src/hash/map_slot.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pedersenHash } from '@aztec/foundation/crypto';
1+
import { poseidon2Hash } from '@aztec/foundation/crypto';
22
import { type Fr } from '@aztec/foundation/fields';
33

44
/**
@@ -14,5 +14,5 @@ export function deriveStorageSlotInMap(
1414
toField: () => Fr;
1515
},
1616
): Fr {
17-
return pedersenHash([mapSlot, key.toField()]);
17+
return poseidon2Hash([mapSlot, key.toField()]);
1818
}

yarn-project/sequencer-client/src/tx_validator/gas_validator.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Tx, mockTx } from '@aztec/circuit-types';
22
import { AztecAddress, Fr, FunctionSelector, GasSettings } from '@aztec/circuits.js';
3-
import { pedersenHash } from '@aztec/foundation/crypto';
3+
import { poseidon2Hash } from '@aztec/foundation/crypto';
44
import { FeeJuiceContract } from '@aztec/noir-contracts.js';
55
import { FeeJuiceAddress } from '@aztec/protocol-contracts/fee-juice';
66

@@ -37,7 +37,7 @@ describe('GasTxValidator', () => {
3737
inclusionFee: new Fr(TX_FEE),
3838
});
3939
payer = tx.data.feePayer;
40-
expectedBalanceSlot = pedersenHash([FeeJuiceContract.storage.balances.slot, payer]);
40+
expectedBalanceSlot = poseidon2Hash([FeeJuiceContract.storage.balances.slot, payer]);
4141

4242
expect(tx.data.constants.txContext.gasSettings.getFeeLimit()).toEqual(new Fr(TX_FEE));
4343
});

0 commit comments

Comments
 (0)