From 58639462eadb75b8f09639d6ef5333e8bb4d3c1c Mon Sep 17 00:00:00 2001 From: arnaucube Date: Fri, 25 Dec 2020 13:48:09 +0100 Subject: [PATCH] Update `mix` to match reference implementation ver Reference implementation: https://extgit.iaik.tugraz.at/krypto/hadeshash Tested with `sage code/poseidonperm_x5_254_3.sage` for inputs: `[1,2,0]`, equivalent to using `circomlib/poseidon.js` with inputs `[1,2]`, both return as result `11309872961022349216464221841186646423561022368884850929991258903497301047946` Tested with `sage code/poseidonperm_x5_254_5.sage` for inputs: `[1,2,3,4,0]`, equivalent to using `circomlib/poseidon.js` with inputs `[1,2,3,4]`, both return as result `18181515143627462196415302348515936346022476168236332098176009127325427112991` --- circuits/poseidon.circom | 2 +- src/poseidon.js | 2 +- src/poseidon_gencontract.js | 2 +- test/eddsa_js.js | 4 ++-- test/poseidoncircuit.js | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/circuits/poseidon.circom b/circuits/poseidon.circom index 70635dd..7d63105 100644 --- a/circuits/poseidon.circom +++ b/circuits/poseidon.circom @@ -30,7 +30,7 @@ template Mix(t, M) { for (var i=0; i - state.reduce((acc, a, j) => F.add(acc, F.mul(M[t - 2][j][i], a)), F.zero) + state.reduce((acc, a, j) => F.add(acc, F.mul(M[t - 2][i][j], a)), F.zero) ); } } diff --git a/src/poseidon_gencontract.js b/src/poseidon_gencontract.js index 3f896ab..970b608 100644 --- a/src/poseidon_gencontract.js +++ b/src/poseidon_gencontract.js @@ -29,7 +29,7 @@ function createCode(nInputs) { function saveM() { for (let i=0; i