Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: switch slot derivation to poseidon2 instead of pedersen #8801

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<K>(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 {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/hash/map_slot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/hash/map_slot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pedersenHash } from '@aztec/foundation/crypto';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { type Fr } from '@aztec/foundation/fields';

/**
Expand All @@ -14,5 +14,5 @@ export function deriveStorageSlotInMap(
toField: () => Fr;
},
): Fr {
return pedersenHash([mapSlot, key.toField()]);
return poseidon2Hash([mapSlot, key.toField()]);
}
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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));
});
Expand Down
Loading