Skip to content

Commit

Permalink
feat: poseidon separator
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 12, 2024
1 parent 6399855 commit 1659214
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 2 additions & 4 deletions yarn-project/foundation/src/crypto/poseidon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import { type Fieldable, serializeToFields } from '../../serialize/serialize.js'
* @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 poseidonHash(input: Fieldable[], _index = 0): Fr {
const inputFields = serializeToFields(input);
export function poseidonHash(input: Fieldable[], index = 0): Fr {
const inputFields = serializeToFields([input, index]);
return Fr.fromBuffer(
Buffer.from(
BarretenbergSync.getSingleton()
.poseidonHash(
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
11 changes: 5 additions & 6 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,28 +15,27 @@ describe('NewTestKeyStore', () => {

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

// 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(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
`"0x0973bac244e49c0ff1456f1b443c15ffe232effa2ac739d4807ffac9d3ea965a07a4b477bb3ec87e2ca493f4bc74b58b066d8792011f3b31d6f8f1220d54235d"`,
);

const masterIncomingViewingPublicKey = await keyStore.getMasterIncomingViewingPublicKey(accountAddress);
expect(masterIncomingViewingPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
`"0x162b109d74fcc35431c885f65934e71e64d0bbcf259f5bdd313e6311d133215b13759399852fce54fc116f7f4315193c1cb2ca37febac4dafb8736a28aa8c718"`,
);

const masterOutgoingViewingPublicKey = await keyStore.getMasterOutgoingViewingPublicKey(accountAddress);
expect(masterOutgoingViewingPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
`"0x1fc2ae4095793a53f80fa63f5606a27daf9d60038ddd000baf3dc9bed659bc8e08ed599ecd88190f75e3b16b0bee0ba3e67a9aa318d76e19444c56274ebbf3ba"`,
);

const masterTaggingPublicKey = await keyStore.getMasterTaggingPublicKey(accountAddress);
expect(masterTaggingPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
`"0x1949d883bb8af455a71219d9753739772d01968f5921dc09fe5db2d5f3d782d51fe3f92bfffda9c265630ebaaa9a1ddfae27c2b821bcafa074f530d7f4f06b61"`,
);
});
});

0 comments on commit 1659214

Please sign in to comment.