mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-02-14 21:10:43 +01:00
refactor loop
This commit is contained in:
parent
ec4508e81e
commit
f8cd3fea1e
@ -1,6 +1,6 @@
|
|||||||
include "../node_modules/circomlib/circuits/mimcsponge.circom";
|
include "../node_modules/circomlib/circuits/mimcsponge.circom";
|
||||||
|
|
||||||
// Computes MiMC(left + right)
|
// Computes MiMC([left, right])
|
||||||
template HashLeftRight() {
|
template HashLeftRight() {
|
||||||
signal input left;
|
signal input left;
|
||||||
signal input right;
|
signal input right;
|
||||||
@ -37,19 +37,14 @@ template MerkleTree(levels) {
|
|||||||
|
|
||||||
for (var i = 0; i < levels; i++) {
|
for (var i = 0; i < levels; i++) {
|
||||||
selectors[i] = Mux();
|
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].in[1] <== pathElements[i];
|
||||||
selectors[i].s <== pathIndices[i];
|
selectors[i].s <== pathIndices[i];
|
||||||
|
|
||||||
|
hashers[i] = HashLeftRight();
|
||||||
hashers[i].left <== selectors[i].out[0];
|
hashers[i].left <== selectors[i].out[0];
|
||||||
hashers[i].right <== selectors[i].out[1];
|
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;
|
root === hashers[levels - 1].hash;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ include "merkleTree.circom";
|
|||||||
template CommitmentHasher() {
|
template CommitmentHasher() {
|
||||||
signal private input nullifier;
|
signal private input nullifier;
|
||||||
signal private input secret;
|
signal private input secret;
|
||||||
|
|
||||||
signal output commitment;
|
signal output commitment;
|
||||||
signal output nullifierHash;
|
signal output nullifierHash;
|
||||||
|
|
||||||
@ -42,8 +41,7 @@ template Withdraw(levels) {
|
|||||||
component hasher = CommitmentHasher();
|
component hasher = CommitmentHasher();
|
||||||
hasher.nullifier <== nullifier;
|
hasher.nullifier <== nullifier;
|
||||||
hasher.secret <== secret;
|
hasher.secret <== secret;
|
||||||
|
hasher.nullifierHash === nullifierHash;
|
||||||
nullifierHash === hasher.nullifierHash;
|
|
||||||
|
|
||||||
component tree = MerkleTree(levels);
|
component tree = MerkleTree(levels);
|
||||||
tree.leaf <== hasher.commitment;
|
tree.leaf <== hasher.commitment;
|
||||||
|
Loading…
Reference in New Issue
Block a user