Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 12, 2024
1 parent 393fbee commit c2f8c68
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions barretenberg/ts/src/barretenberg/poseidon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('poseidon sync', () => {
});

it('poseidonHash', () => {
const result = api.poseidonHash([new Fr(4n), new Fr(8n)], 7);
const result = api.poseidonHash([new Fr(4n), new Fr(8n)]);
expect(result).toMatchSnapshot();
});

Expand All @@ -19,7 +19,7 @@ describe('poseidon sync', () => {
const fields = Array.from({ length: loops * 2 }).map(() => Fr.random());
const t = new Timer();
for (let i = 0; i < loops; ++i) {
api.poseidonHash([fields[i * 2], fields[i * 2 + 1]], 0);
api.poseidonHash([fields[i * 2], fields[i * 2 + 1]]);
}
const us = t.us() / loops;
console.log(`Executed ${loops} hashes at an average ${us}us / hash`);
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/ts/src/barretenberg_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ export class BarretenbergApiSync {
return out[0];
}

poseidonHash(inputsBuffer: Fr[], hashIndex: number): Fr {
const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable);
poseidonHash(inputsBuffer: Fr[]): Fr {
const inArgs = [inputsBuffer].map(serializeBufferable);
const outTypes: OutputType[] = [Fr];
const result = this.wasm.callWasmExport(
'poseidon_hash',
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/foundation/src/crypto/poseidon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ 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: enable index once the barretenberg API supports it
*/
export function poseidonHash(input: Fieldable[], index = 0): Fr {
export function poseidonHash(input: Fieldable[], _index = 0): Fr {
const inputFields = serializeToFields(input);
return Fr.fromBuffer(
Buffer.from(
BarretenbergSync.getSingleton()
.poseidonHash(
inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
index,
// index, // TODO: enable once the barretenberg API supports it
)
.toBuffer(),
),
Expand Down

0 comments on commit c2f8c68

Please sign in to comment.