refactor loop

This commit is contained in:
poma 2019-11-03 11:41:05 +03:00
parent ec4508e81e
commit f8cd3fea1e
2 changed files with 4 additions and 11 deletions

View File

@ -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;
}

View File

@ -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;