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: poseidon separator #5717

Merged
merged 3 commits into from
Apr 12, 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
5 changes: 1 addition & 4 deletions yarn-project/foundation/src/crypto/poseidon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ import { type Fieldable, serializeToFields } from '../../serialize/serialize.js'
/**
* Create a poseidon hash (field) from an array of input fields.
* @param input - The input fields to hash.
* @param index - The separator index to use for the hash.
* @returns The poseidon hash.
* TODO(#5714): enable index once barretenberg API supports it
*/
export function poseidon2Hash(input: Fieldable[], _index = 0): Fr {
export function poseidon2Hash(input: Fieldable[]): Fr {
const inputFields = serializeToFields(input);
return Fr.fromBuffer(
Buffer.from(
BarretenbergSync.getSingleton()
.poseidon2Hash(
inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
// index, // TODO: enable once the barretenberg API supports it
)
.toBuffer(),
),
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/key-store/src/new_test_key_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ describe('NewTestKeyStore', () => {

const accountAddress = await keyStore.addAccount(sk, partialAddress);
expect(accountAddress.toString()).toMatchInlineSnapshot(
`"0x2e34847ad9019320ac89a6ec9b42fec90f94ef4162fdfdd7f5b7668e32d82655"`,
`"0x0ba7834252d19c4f09d29303c269f303f40ae3d2043f921ed0bf8c0709926d4e"`,
);

// TODO(#5714): The keys are currently the same here because separator is currently ignored in poseidon
const masterNullifierPublicKey = await keyStore.getMasterNullifierPublicKey(accountAddress);
expect(masterNullifierPublicKey.toString()).toMatchInlineSnapshot(
`"0x2ef5d15dd65d29546680ab72846fb071f41cb9f2a0212215e6c560e29df4ff650ce764818364b376be92dc2f49577fe440e64a16012584f7c4ee94f7edbc323a"`,
Expand Down
16 changes: 7 additions & 9 deletions yarn-project/key-store/src/new_test_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,18 @@ export class NewTestKeyStore implements NewKeyStore {
const masterTaggingPublicKey = this.curve.mul(this.curve.generator(), masterTaggingSecretKey);

// We hash the public keys to get the public keys hash
const publicKeysHash = poseidon2Hash(
[
masterNullifierPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey,
masterTaggingPublicKey,
],
const publicKeysHash = poseidon2Hash([
masterNullifierPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey,
masterTaggingPublicKey,
GeneratorIndex.PUBLIC_KEYS_HASH,
);
]);

// We hash the partial address and the public keys hash to get the account address
// TODO(#5726): Should GeneratorIndex.CONTRACT_ADDRESS be removed given that we introduced CONTRACT_ADDRESS_V1?
// TODO(#5726): Move the following line to AztecAddress class?
const accountAddressFr = poseidon2Hash([partialAddress, publicKeysHash], GeneratorIndex.CONTRACT_ADDRESS_V1);
const accountAddressFr = poseidon2Hash([partialAddress, publicKeysHash, GeneratorIndex.CONTRACT_ADDRESS_V1]);
const accountAddress = AztecAddress.fromField(accountAddressFr);

// We store the keys in the database
Expand Down
Loading