46 lines
1.0 KiB
Plaintext
46 lines
1.0 KiB
Plaintext
pragma circom 2.0.0;
|
|
|
|
//based on Semaphore code
|
|
|
|
include "../node_modules/circomlib/circuits/poseidon.circom";
|
|
include "../node_modules/circomlib/circuits/mux1.circom";
|
|
|
|
template MerkleTreeInclusionProof(nLevels) {
|
|
signal input leaf;
|
|
signal input pathIndices[nLevels];
|
|
signal input siblings[nLevels];
|
|
|
|
signal output root;
|
|
|
|
component hashers[nLevels];
|
|
component mux[nLevels];
|
|
|
|
signal hashes[nLevels + 1];
|
|
hashes[0] <== leaf;
|
|
|
|
for (var i = 0; i < nLevels; i++) {
|
|
pathIndices[i] * (1 - pathIndices[i]) === 0;
|
|
|
|
hashers[i] = Poseidon(2);
|
|
mux[i] = MultiMux1(2);
|
|
|
|
mux[i].c[0][0] <== hashes[i];
|
|
mux[i].c[0][1] <== siblings[i];
|
|
|
|
mux[i].c[1][0] <== siblings[i];
|
|
mux[i].c[1][1] <== hashes[i];
|
|
|
|
mux[i].s <== pathIndices[i];
|
|
|
|
hashers[i].inputs[0] <== mux[i].out[0];
|
|
hashers[i].inputs[1] <== mux[i].out[1];
|
|
|
|
hashes[i + 1] <== hashers[i].out;
|
|
}
|
|
|
|
root <== hashes[nLevels];
|
|
}
|
|
|
|
//component main {public [leaf]} = MerkleTreeInclusionProof(10);
|
|
|