From f8cd3fea1eb5664dd0f8b3e4b83ac6e0c0ba3371 Mon Sep 17 00:00:00 2001 From: poma Date: Sun, 3 Nov 2019 11:41:05 +0300 Subject: [PATCH] refactor loop --- circuits/merkleTree.circom | 11 +++-------- circuits/withdraw.circom | 4 +--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/circuits/merkleTree.circom b/circuits/merkleTree.circom index c93f131..bfd6016 100644 --- a/circuits/merkleTree.circom +++ b/circuits/merkleTree.circom @@ -1,6 +1,6 @@ include "../node_modules/circomlib/circuits/mimcsponge.circom"; -// Computes MiMC(left + right) +// Computes MiMC([left, right]) template HashLeftRight() { signal input left; signal input right; @@ -37,19 +37,14 @@ template MerkleTree(levels) { for (var i = 0; i < levels; i++) { selectors[i] = Mux(); - hashers[i] = HashLeftRight(); - + selectors[i].in[0] <== i == 0 ? leaf : hashers[i - 1].hash; selectors[i].in[1] <== pathElements[i]; selectors[i].s <== pathIndices[i]; + hashers[i] = HashLeftRight(); hashers[i].left <== selectors[i].out[0]; hashers[i].right <== selectors[i].out[1]; } - selectors[0].in[0] <== leaf; - for (var i = 1; i < levels; i++) { - selectors[i].in[0] <== hashers[i-1].hash; - } - root === hashers[levels - 1].hash; } diff --git a/circuits/withdraw.circom b/circuits/withdraw.circom index 1aee5e1..a4c4848 100644 --- a/circuits/withdraw.circom +++ b/circuits/withdraw.circom @@ -6,7 +6,6 @@ include "merkleTree.circom"; template CommitmentHasher() { signal private input nullifier; signal private input secret; - signal output commitment; signal output nullifierHash; @@ -42,8 +41,7 @@ template Withdraw(levels) { component hasher = CommitmentHasher(); hasher.nullifier <== nullifier; hasher.secret <== secret; - - nullifierHash === hasher.nullifierHash; + hasher.nullifierHash === nullifierHash; component tree = MerkleTree(levels); tree.leaf <== hasher.commitment;