docs and minor changes

This commit is contained in:
poma 2019-07-10 15:35:46 +03:00
parent 5db6595c61
commit 9d75637b8c
5 changed files with 37 additions and 14 deletions

View file

@ -1,6 +1,7 @@
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/mimcsponge.circom";
// Computes MiMC(left + right)
template HashLeftRight(rounds) {
signal input left;
signal input right;
@ -15,6 +16,8 @@ template HashLeftRight(rounds) {
hash <== hasher.outs[0];
}
// if pathIndex == 0 returns (left = inputElement, right = pathElement)
// if pathIndex == 1 returns (left = pathElement, right = inputElement)
template Selector() {
signal input inputElement;
signal input pathElement;
@ -39,13 +42,14 @@ template Selector() {
right <== rightSelector1 + rightSelector2;
}
// Verifies that merkle proof is correct for given merkle root and a leaf
// pathIndex input is an array of 0/1 selectors telling whether given pathElement is on the left or right side of merkle path
template MerkleTree(levels, rounds) {
signal input leaf;
signal input root;
signal private input pathElements[levels];
signal private input pathIndex[levels];
signal output root;
component selectors[levels];
component hashers[levels];
@ -66,5 +70,5 @@ template MerkleTree(levels, rounds) {
selectors[i].inputElement <== hashers[i-1].hash;
}
root <== hashers[levels - 1].hash;
root === hashers[levels - 1].hash;
}

View file

@ -2,6 +2,7 @@ include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/pedersen.circom";
include "merkleTree.circom";
// computes Pedersen(nullifier + secret)
template CommitmentHasher() {
signal input nullifier;
signal private input secret;
@ -21,6 +22,7 @@ template CommitmentHasher() {
hash <== commitment.out[0];
}
// Verifies that commitment that corresponds to given secret and nullifier is included in the merkle tree of deposits
template Withdraw(levels, rounds) {
signal input root;
signal input nullifier;
@ -36,10 +38,11 @@ template Withdraw(levels, rounds) {
component tree = MerkleTree(levels, rounds);
tree.leaf <== hasher.hash;
tree.pathElements <== pathElements;
tree.pathIndex <== pathIndex;
root === tree.root;
tree.root <== root;
for (var i = 0; i < levels; i++) {
tree.pathElements[i] <== pathElements[i];
tree.pathIndex[i] <== pathIndex[i];
}
// TODO: Check if we need some kind of explicit constraints or something
fee === fee;