Skip to content

Commit

Permalink
poseidon test
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed May 3, 2024
1 parent bbeda07 commit 03241cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crypto/poseidon.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ checkTestVectors(testPoseidonKimchiFp.test_vectors, Poseidon.hash);

checkTestVectors(testPoseidonLegacyFp.test_vectors, PoseidonLegacy.hash);

// calling update() subsequently on size-2 chunks is the same as calling hash() on the full input

test(Random.array(Random.field, 5), (xs) => {
let h1 = Poseidon.hash(xs);

let state = Poseidon.initialState();
state = Poseidon.update(state, [xs[0], xs[1]]);
state = Poseidon.update(state, [xs[2], xs[3]]);
state = Poseidon.update(state, [xs[4]]);
let h2 = state[0];
expect(h1).toEqual(h2);
});

console.log('poseidon implementation matches the test vectors! 🎉');

test(Random.array(Random.field, Random.nat(20)), (xs) => {
Expand Down

0 comments on commit 03241cd

Please sign in to comment.