2019-07-09 09:05:30 -04:00
|
|
|
include "../node_modules/circomlib/circuits/bitify.circom";
|
|
|
|
include "../node_modules/circomlib/circuits/pedersen.circom";
|
|
|
|
include "merkleTree.circom";
|
|
|
|
|
2019-07-10 08:35:46 -04:00
|
|
|
// computes Pedersen(nullifier + secret)
|
2019-07-09 09:05:30 -04:00
|
|
|
template CommitmentHasher() {
|
2019-07-19 12:37:38 -04:00
|
|
|
signal private input nullifier;
|
2019-07-09 09:05:30 -04:00
|
|
|
signal private input secret;
|
|
|
|
|
2019-07-19 12:37:38 -04:00
|
|
|
signal output commitment;
|
|
|
|
signal output nullifierHash;
|
2019-07-09 09:05:30 -04:00
|
|
|
|
2019-08-01 10:49:34 -04:00
|
|
|
component commitmentHasher = Pedersen(496);
|
|
|
|
component nullifierHasher = Pedersen(248);
|
|
|
|
component nullifierBits = Num2Bits(248);
|
|
|
|
component secretBits = Num2Bits(248);
|
2019-07-09 09:05:30 -04:00
|
|
|
nullifierBits.in <== nullifier;
|
|
|
|
secretBits.in <== secret;
|
2019-08-01 10:49:34 -04:00
|
|
|
for (var i = 0; i < 248; i++) {
|
2019-07-19 12:37:38 -04:00
|
|
|
nullifierHasher.in[i] <== nullifierBits.out[i];
|
|
|
|
commitmentHasher.in[i] <== nullifierBits.out[i];
|
2019-08-01 10:49:34 -04:00
|
|
|
commitmentHasher.in[i + 248] <== secretBits.out[i];
|
2019-07-09 09:05:30 -04:00
|
|
|
}
|
|
|
|
|
2019-07-19 12:37:38 -04:00
|
|
|
commitment <== commitmentHasher.out[0];
|
|
|
|
nullifierHash <== nullifierHasher.out[0];
|
2019-07-09 09:05:30 -04:00
|
|
|
}
|
|
|
|
|
2019-07-10 08:35:46 -04:00
|
|
|
// Verifies that commitment that corresponds to given secret and nullifier is included in the merkle tree of deposits
|
2019-07-09 09:05:30 -04:00
|
|
|
template Withdraw(levels, rounds) {
|
|
|
|
signal input root;
|
2019-07-19 12:37:38 -04:00
|
|
|
signal input nullifierHash;
|
2019-07-16 12:34:46 -04:00
|
|
|
// TODO: Check if we need some kind of explicit constraints or something for those 2 inputs
|
2019-07-09 09:05:30 -04:00
|
|
|
signal input receiver; // not taking part in any computations
|
|
|
|
signal input fee; // not taking part in any computations
|
2019-07-19 12:37:38 -04:00
|
|
|
signal private input nullifier;
|
2019-07-09 09:05:30 -04:00
|
|
|
signal private input secret;
|
|
|
|
signal private input pathElements[levels];
|
|
|
|
signal private input pathIndex[levels];
|
|
|
|
|
|
|
|
component hasher = CommitmentHasher();
|
|
|
|
hasher.nullifier <== nullifier;
|
|
|
|
hasher.secret <== secret;
|
|
|
|
|
2019-07-19 12:37:38 -04:00
|
|
|
nullifierHash === hasher.nullifierHash;
|
|
|
|
|
2019-07-09 09:05:30 -04:00
|
|
|
component tree = MerkleTree(levels, rounds);
|
2019-07-19 12:37:38 -04:00
|
|
|
tree.leaf <== hasher.commitment;
|
2019-07-10 08:35:46 -04:00
|
|
|
tree.root <== root;
|
|
|
|
for (var i = 0; i < levels; i++) {
|
|
|
|
tree.pathElements[i] <== pathElements[i];
|
|
|
|
tree.pathIndex[i] <== pathIndex[i];
|
|
|
|
}
|
2019-07-09 09:05:30 -04:00
|
|
|
}
|
|
|
|
|
2019-07-16 12:34:46 -04:00
|
|
|
component main = Withdraw(16, 220);
|