From 58f758d5ada9672a5ca5282c88f051e25a4f0b09 Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Sun, 28 Apr 2019 12:03:15 +0100 Subject: [PATCH] Adapt the way to connect mimcs --- circuits/eddsamimc.circom | 1 + circuits/mimc.circom | 15 ++++++++------- circuits/smt/smthash.circom | 30 ++++++++++-------------------- src/eddsa.js | 2 +- src/mimc7.js | 21 ++++++++++++++++----- src/smt.js | 32 ++++++++++++++++---------------- test/eddsamimc.js | 2 +- 7 files changed, 53 insertions(+), 50 deletions(-) diff --git a/circuits/eddsamimc.circom b/circuits/eddsamimc.circom index 3bc870e..b3a6a77 100644 --- a/circuits/eddsamimc.circom +++ b/circuits/eddsamimc.circom @@ -58,6 +58,7 @@ template EdDSAMiMCVerifier() { hash.in[2] <== Ax; hash.in[3] <== Ay; hash.in[4] <== M; + hash.k <== 0; component h2bits = Num2Bits_strict(); h2bits.in <== hash.out; diff --git a/circuits/mimc.circom b/circuits/mimc.circom index ea2c274..9ab478e 100644 --- a/circuits/mimc.circom +++ b/circuits/mimc.circom @@ -137,18 +137,19 @@ template MiMC7(nrounds) { template MultiMiMC7(nInputs, nRounds) { signal input in[nInputs]; + signal input k; signal output out; + signal r[nInputs +1]; component mims[nInputs]; + + r[0] <== k; for (var i=0; i{ return F.affine(F.add(r, k)); }; -exports.multiHash = (arr) => { - let r = exports.getIV(); - for (let i=0; i { + let r; + if (typeof(key) === "undefined") { + r = F.zero; + } else { + r = key; } - return r; + for (let i=0; i=0; i--) { @@ -207,9 +207,9 @@ class SMT { if (mixed) { const oldSibling = resFind.siblings[i]; if (newKeyBits[i]) { - rtOld = mimc7.multiHash([oldSibling, rtOld]); + rtOld = mimc7.multiHash([oldSibling, rtOld], bigInt.zero); } else { - rtOld = mimc7.multiHash([rtOld, oldSibling]); + rtOld = mimc7.multiHash([rtOld, oldSibling], bigInt.zero); } dels.push(rtOld); } @@ -217,10 +217,10 @@ class SMT { let newRt; if (newKeyBits[i]) { - newRt = mimc7.multiHash([res.siblings[i], rt]); + newRt = mimc7.multiHash([res.siblings[i], rt], bigInt.zero); inserts.push([newRt,[res.siblings[i], rt]] ); } else { - newRt = mimc7.multiHash([rt, res.siblings[i]]); + newRt = mimc7.multiHash([rt, res.siblings[i]], bigInt.zero); inserts.push([newRt,[rt, res.siblings[i]]] ); } rt = newRt; diff --git a/test/eddsamimc.js b/test/eddsamimc.js index 9aec29a..97abcb3 100644 --- a/test/eddsamimc.js +++ b/test/eddsamimc.js @@ -9,7 +9,7 @@ const assert = chai.assert; const bigInt = snarkjs.bigInt; -describe("EdDSA test", function () { +describe("EdDSA MiMC test", function () { let circuit; this.timeout(100000);