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