/
utils.circom
45 lines (34 loc) · 1.2 KB
/
utils.circom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
pragma circom 2.1.0;
include "../node_modules/circomlib/circuits/poseidon.circom";
include "../node_modules/circomlib/circuits/mux1.circom";
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/comparators.circom";
template MerkleTreeInclusionProof(DEPTH) {
signal input leaf;
signal input pathIndex[DEPTH];
signal input pathElements[DEPTH];
signal output root;
signal mux[DEPTH][2];
signal levelHashes[DEPTH + 1];
levelHashes[0] <== leaf;
for (var i = 0; i < DEPTH; i++) {
pathIndex[i] * (pathIndex[i] - 1) === 0;
mux[i] <== MultiMux1(2)(
[
[levelHashes[i], pathElements[i]],
[pathElements[i], levelHashes[i]]
],
pathIndex[i]
);
levelHashes[i + 1] <== Poseidon(2)([mux[i][0], mux[i][1]]);
}
root <== levelHashes[DEPTH];
}
template RangeCheck(LIMIT_BIT_SIZE) {
assert(LIMIT_BIT_SIZE < 253);
signal input messageId;
signal input limit;
signal bitCheck[LIMIT_BIT_SIZE] <== Num2Bits(LIMIT_BIT_SIZE)(messageId);
signal rangeCheck <== LessThan(LIMIT_BIT_SIZE)([messageId, limit]);
rangeCheck === 1;
}