Skip to content

Commit e4f3b36

Browse files
authored
Merge pull request #50 from webb-tools/akilesh-tornPoolCircuits
Joinsplit - Pool circuits and contracts
2 parents 5f86d8c + 4b31fed commit e4f3b36

File tree

142 files changed

+6444
-183885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+6444
-183885
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
with:
2727
node-version: ${{ matrix.node-version }}
2828
cache: 'yarn'
29+
- run: git submodule update --init --recursive
2930
- run: yarn install --production=false
3031
- run: yarn compile
3132
- run: yarn build:hashers

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "protocol-solidity-fixtures"]
2+
path = protocol-solidity-fixtures
3+
url = https://github.com/webb-tools/protocol-solidity-fixtures

circuits/bridge/manyMerkleTree.circom

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
11
pragma circom 2.0.0;
22

33
include "../poseidon/hasher.circom";
4-
5-
// Set membership gadget is handled with a multiplicative trick.
6-
//
7-
// For a given set of elements, a prover first computes the difference between
8-
// each element in the set and the element they are proving knowledge of. We
9-
// constrain this operation accordingly. We then multiply all differences and constrain
10-
// this value by zero. If the prover actually knows an element in the set then for that
11-
// element, it must hold that the difference is 0. Therefore, the product of 0 and
12-
// anything else should be 0. The prove can't lie by adding a zero into the diffs set
13-
// because we constrain those to match all elements in the set respectively.
14-
template SetMembership(length) {
15-
signal input element;
16-
signal input set[length];
17-
signal input diffs[length];
18-
19-
signal product[length + 1];
20-
product[0] <== element;
21-
for (var i = 0; i < length; i++) {
22-
set[i] === diffs[i] + element;
23-
product[i + 1] <== product[i] * diffs[i];
24-
}
25-
26-
product[length] === 0;
27-
}
4+
include "../set/membership.circom";
285

296
// if s == 0 returns [in[0], in[1]]
307
// if s == 1 returns [in[1], in[0]]

circuits/semaphore/semaphore-base.circom

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pragma circom 2.0.0;
22

33
include "../../node_modules/circomlib/circuits/poseidon.circom";
44
include "../../node_modules/circomlib/circuits/babyjub.circom";
5+
include "../set/membership.circom";
56
include "./tree.circom";
67

78

@@ -41,30 +42,6 @@ template CalculateNullifierHash() {
4142
out <== hasher.out;
4243
}
4344

44-
// Set membership gadget is handled with a multiplicative trick.
45-
//
46-
// For a given set of elements, a prover first computes the difference between
47-
// each element in the set and the element they are proving knowledge of. We
48-
// constrain this operation accordingly. We then multiply all differences and constrain
49-
// this value by zero. If the prover actually knows an element in the set then for that
50-
// element, it must hold that the difference is 0. Therefore, the product of 0 and
51-
// anything else should be 0. The prove can't lie by adding a zero into the diffs set
52-
// because we constrain those to match all elements in the set respectively.
53-
template SetMembership(length) {
54-
signal input element;
55-
signal input set[length];
56-
signal input diffs[length];
57-
58-
signal product[length + 1];
59-
product[0] <== element;
60-
for (var i = 0; i < length; i++) {
61-
set[i] === diffs[i] + element;
62-
product[i + 1] <== product[i] * diffs[i];
63-
}
64-
65-
product[length] === 0;
66-
}
67-
6845
// n_levels must be < 32
6946
template Semaphore(n_levels, length) {
7047

circuits/set/membership.circom

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@ pragma circom 2.0.0;
22

33
include "../../node_modules/circomlib/circuits/comparators.circom";
44

5+
// Set membership gadget is handled with a multiplicative trick.
6+
//
7+
// For a given set of elements, a prover first computes the difference between
8+
// each element in the set and the element they are proving knowledge of. We
9+
// constrain this operation accordingly. We then multiply all differences and constrain
10+
// this value by zero. If the prover actually knows an element in the set then for that
11+
// element, it must hold that the difference is 0. Therefore, the product of 0 and
12+
// anything else should be 0. The prove can't lie by adding a zero into the diffs set
13+
// because we constrain those to match all elements in the set respectively.
514
template SetMembership(length) {
6-
signal input element;
7-
signal input set[length];
8-
9-
signal product[length + 1];
10-
product[0] <== 1;
11-
12-
component isEqualChecker[length];
13-
component isZeroChecker[length];
14-
15-
for(var i = 0; i < length; i++) {
16-
isEqualChecker[i] = IsEqual();
17-
isZeroChecker[i] = IsZero();
18-
19-
isEqualChecker[i].in[0] <== element;
20-
isEqualChecker[i].in[1] <== set[i];
21-
22-
isZeroChecker[i].in <== isEqualChecker[i].out;
23-
24-
product[i + 1] <== product[i] * isZeroChecker[i].out;
25-
}
26-
27-
product[length] === 0;
28-
}
15+
signal input element;
16+
signal input set[length];
17+
signal input diffs[length];
18+
19+
signal product[length + 1];
20+
product[0] <== element;
21+
for (var i = 0; i < length; i++) {
22+
set[i] === diffs[i] + element;
23+
product[i + 1] <== product[i] * diffs[i];
24+
}
25+
26+
product[length] === 0;
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pragma circom 2.0.0;
2+
3+
include "../../node_modules/circomlib/circuits/comparators.circom";
4+
5+
// Set membership gadget is handled with a multiplicative trick.
6+
//
7+
// For a given set of elements, a prover first computes the difference between
8+
// each element in the set and the element they are proving knowledge of. We
9+
// constrain this operation accordingly. We then multiply all differences and constrain
10+
// this value by zero. If the prover actually knows an element in the set then for that
11+
// element, it must hold that the difference is 0. Therefore, the product of 0 and
12+
// anything else should be 0. The prove can't lie by adding a zero into the diffs set
13+
// because we constrain those to match all elements in the set respectively.
14+
template ForceSetMembershipIfEnabled(length) {
15+
signal input element;
16+
signal input set[length];
17+
signal input diffs[length];
18+
signal input enabled;
19+
20+
signal product[length + 1];
21+
22+
product[0] <== element;
23+
24+
for (var i = 0; i < length; i++) {
25+
(set[i] - diffs[i] - element) * enabled === 0;
26+
product[i + 1] <== product[i] * diffs[i];
27+
}
28+
29+
product[length]*enabled === 0;
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pragma circom 2.0.0;
2+
3+
include "../../node_modules/circomlib/circuits/comparators.circom";
4+
5+
template SetMembership(length) {
6+
signal input element;
7+
signal input set[length];
8+
9+
signal product[length + 1];
10+
product[0] <== 1;
11+
12+
component isEqualChecker[length];
13+
component isZeroChecker[length];
14+
15+
for(var i = 0; i < length; i++) {
16+
isEqualChecker[i] = IsEqual();
17+
isZeroChecker[i] = IsZero();
18+
19+
isEqualChecker[i].in[0] <== element;
20+
isEqualChecker[i].in[1] <== set[i];
21+
22+
isZeroChecker[i].in <== isEqualChecker[i].out;
23+
24+
product[i + 1] <== product[i] * isZeroChecker[i].out;
25+
}
26+
27+
product[length] === 0;
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pragma circom 2.0.0;
2+
3+
include "../../node_modules/circomlib/circuits/poseidon.circom";
4+
5+
template Poseidon4Gadget() {
6+
signal input outChainID;
7+
signal input outAmount;
8+
signal input outPubkey;
9+
signal input outBlinding;
10+
signal input outputCommitment;
11+
12+
component outUtxoHasher = Poseidon(4);
13+
outUtxoHasher.inputs[0] <== outChainID;
14+
outUtxoHasher.inputs[1] <== outAmount;
15+
outUtxoHasher.inputs[2] <== outPubkey;
16+
outUtxoHasher.inputs[3] <== outBlinding;
17+
outUtxoHasher.out === outputCommitment;
18+
}
19+
20+
component main {public [outputCommitment]} = Poseidon4Gadget();
21+

circuits/test/poseidon_bridge_2.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ pragma circom 2.0.0;
33
include "../bridge/withdraw.circom";
44

55
component main {public [nullifierHash, recipient, relayer, fee,
6-
refund, chainID, roots, refreshCommitment]} = Withdraw(30, 2);
6+
refund, refreshCommitment, chainID, roots]} = Withdraw(30, 2);
77

circuits/test/poseidon_bridge_3.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pragma circom 2.0.0;
33
include "../bridge/withdraw.circom";
44

55
component main {public [nullifierHash, recipient, relayer, fee,
6-
refund, chainID, roots, refreshCommitment]} = Withdraw(30, 3);
6+
refund, refreshCommitment, chainID, roots]} = Withdraw(30, 3);

0 commit comments

Comments
 (0)