@maci-protocol/circuits 0.0.0-ci.153b117 → 0.0.0-ci.17c3dcd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,6 @@ include "./mux1.circom";
5
5
  // local imports
6
6
  include "../../utils/PoseidonHasher.circom";
7
7
  include "../../utils/trees/MerkleTreeInclusionProof.circom";
8
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
9
8
  include "../../utils/trees/BinaryMerkleRoot.circom";
10
9
  include "../../utils/trees/QuinaryTreeInclusionProof.circom";
11
10
  include "../../utils/trees/QuinaryGeneratePathIndices.circom";
@@ -112,14 +111,13 @@ template SingleMessageProcessorFull(stateTreeDepth, voteOptionTreeDepth) {
112
111
  // 2. If computedIsStateLeafIndexValid is equal to zero, generate indices for leaf zero.
113
112
  // Otherwise, generate indices for command.stateIndex.
114
113
  var stateIndexMux = Mux1()([0, commandStateIndex], computedIsStateLeafIndexValid);
115
- var computedStateLeafPathIndices[stateTreeDepth] = MerklePathIndicesGenerator(stateTreeDepth)(stateIndexMux);
116
114
 
117
115
  // 3. Verify that the original state leaf exists in the given state root.
118
116
  var stateLeafHash = PoseidonHasher(3)(stateLeaf);
119
117
  var computedStateRoot = BinaryMerkleRoot(stateTreeDepth)(
120
118
  stateLeafHash,
121
119
  actualStateTreeDepth,
122
- computedStateLeafPathIndices,
120
+ stateIndexMux,
123
121
  stateLeafPathElements
124
122
  );
125
123
 
@@ -130,6 +128,7 @@ template SingleMessageProcessorFull(stateTreeDepth, voteOptionTreeDepth) {
130
128
  ballot[BALLOT_NONCE_INDEX],
131
129
  ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
132
130
  ]);
131
+ var computedStateLeafPathIndices[stateTreeDepth] = Num2Bits(stateTreeDepth)(stateIndexMux);
133
132
 
134
133
  var computedBallotRoot = MerkleTreeInclusionProof(stateTreeDepth)(
135
134
  computedBallot,
@@ -186,7 +185,7 @@ template SingleMessageProcessorFull(stateTreeDepth, voteOptionTreeDepth) {
186
185
  var computedNewStateRoot = BinaryMerkleRoot(stateTreeDepth)(
187
186
  computedNewStateLeafhash,
188
187
  actualStateTreeDepth,
189
- computedStateLeafPathIndices,
188
+ stateIndexMux,
190
189
  stateLeafPathElements
191
190
  );
192
191
 
@@ -5,7 +5,6 @@ include "./mux1.circom";
5
5
  // local imports
6
6
  include "../../utils/PoseidonHasher.circom";
7
7
  include "../../utils/trees/MerkleTreeInclusionProof.circom";
8
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
9
8
  include "../../utils/trees/BinaryMerkleRoot.circom";
10
9
  include "../../utils/trees/QuinaryTreeInclusionProof.circom";
11
10
  include "../../utils/trees/QuinaryGeneratePathIndices.circom";
@@ -108,14 +107,13 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
108
107
  // 2. If computedIsStateLeafIndexValid is equal to zero, generate indices for leaf zero.
109
108
  // Otherwise, generate indices for command.stateIndex.
110
109
  var stateIndexMux = Mux1()([0, commandStateIndex], computedIsStateLeafIndexValid);
111
- var computedStateLeafPathIndices[stateTreeDepth] = MerklePathIndicesGenerator(stateTreeDepth)(stateIndexMux);
112
110
 
113
111
  // 3. Verify that the original state leaf exists in the given state root.
114
112
  var stateLeafHash = PoseidonHasher(3)(stateLeaf);
115
113
  var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
116
114
  stateLeafHash,
117
115
  actualStateTreeDepth,
118
- computedStateLeafPathIndices,
116
+ stateIndexMux,
119
117
  stateLeafPathElements
120
118
  );
121
119
 
@@ -126,6 +124,7 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
126
124
  ballot[BALLOT_NONCE_INDEX],
127
125
  ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
128
126
  ]);
127
+ var computedStateLeafPathIndices[stateTreeDepth] = Num2Bits(stateTreeDepth)(stateIndexMux);
129
128
 
130
129
  var computedBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
131
130
  computedBallot,
@@ -182,7 +181,7 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
182
181
  var computedNewStateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
183
182
  computedNewStateLeafHash,
184
183
  actualStateTreeDepth,
185
- computedStateLeafPathIndices,
184
+ stateIndexMux,
186
185
  stateLeafPathElements
187
186
  );
188
187
 
@@ -7,7 +7,6 @@ include "./unpack-element.circom";
7
7
  // local imports
8
8
  include "../../utils/non-qv/ResultCommitmentVerifier.circom";
9
9
  include "../../utils/trees/CheckRoot.circom";
10
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
11
10
  include "../../utils/trees/LeafExists.circom";
12
11
  include "../../utils/trees/QuinaryCheckRoot.circom";
13
12
  include "../../utils/CalculateTotal.circom";
@@ -97,7 +96,7 @@ template VoteTallyNonQv(
97
96
  }
98
97
 
99
98
  var computedBallotSubroot = CheckRoot(tallyProcessingStateTreeDepth)(computedBallotHashers);
100
- var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_TREE_DEPTH_DIFFERENCE)(index / batchSize);
99
+ var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = Num2Bits(STATE_TREE_DEPTH_DIFFERENCE)(index / batchSize);
101
100
 
102
101
  // Verifies each ballot's existence within the ballot tree.
103
102
  LeafExists(STATE_TREE_DEPTH_DIFFERENCE)(
@@ -5,7 +5,6 @@ include "./mux1.circom";
5
5
  // local imports
6
6
  include "../../utils/PoseidonHasher.circom";
7
7
  include "../../utils/trees/MerkleTreeInclusionProof.circom";
8
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
9
8
  include "../../utils/trees/BinaryMerkleRoot.circom";
10
9
  include "../../utils/trees/QuinaryTreeInclusionProof.circom";
11
10
  include "../../utils/trees/QuinaryGeneratePathIndices.circom";
@@ -112,14 +111,13 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
112
111
  // 2. If computedIsStateLeafIndexValid is equal to zero, generate indices for leaf zero.
113
112
  // Otherwise, generate indices for command.stateIndex.
114
113
  var stateIndexMux = Mux1()([0, commandStateIndex], computedIsStateLeafIndexValid);
115
- var computedStateLeafPathIndices[stateTreeDepth] = MerklePathIndicesGenerator(stateTreeDepth)(stateIndexMux);
116
114
 
117
115
  // 3. Verify that the original state leaf exists in the given state root.
118
116
  var stateLeafHash = PoseidonHasher(3)(stateLeaf);
119
117
  var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
120
118
  stateLeafHash,
121
119
  actualStateTreeDepth,
122
- computedStateLeafPathIndices,
120
+ stateIndexMux,
123
121
  stateLeafPathElements
124
122
  );
125
123
 
@@ -130,6 +128,7 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
130
128
  ballot[BALLOT_NONCE_INDEX],
131
129
  ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
132
130
  ]);
131
+ var computedStateLeafPathIndices[stateTreeDepth] = Num2Bits(stateTreeDepth)(stateIndexMux);
133
132
 
134
133
  var computedBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
135
134
  computedBallot,
@@ -189,7 +188,7 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
189
188
  var computedNewStateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
190
189
  computedNewStateLeafHash,
191
190
  actualStateTreeDepth,
192
- computedStateLeafPathIndices,
191
+ stateIndexMux,
193
192
  stateLeafPathElements
194
193
  );
195
194
 
@@ -6,7 +6,6 @@ include "./comparators.circom";
6
6
  include "./unpack-element.circom";
7
7
  // local imports
8
8
  include "../../utils/trees/CheckRoot.circom";
9
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
10
9
  include "../../utils/trees/LeafExists.circom";
11
10
  include "../../utils/trees/QuinaryCheckRoot.circom";
12
11
  include "../../utils/qv/ResultCommitmentVerifier.circom";
@@ -102,7 +101,7 @@ template VoteTallyQv(
102
101
  }
103
102
 
104
103
  var computedBallotSubroot = CheckRoot(tallyProcessingStateTreeDepth)(computedBallotHashers);
105
- var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_TREE_DEPTH_DIFFERENCE)(index / batchSize);
104
+ var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = Num2Bits(STATE_TREE_DEPTH_DIFFERENCE)(index / batchSize);
106
105
 
107
106
  // Verifies each ballot's existence within the ballot tree.
108
107
  LeafExists(STATE_TREE_DEPTH_DIFFERENCE)(
@@ -6,7 +6,6 @@ include "./comparators.circom";
6
6
  include "./unpack-element.circom";
7
7
  // local imports
8
8
  include "../../utils/trees/CheckRoot.circom";
9
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
10
9
  include "../../utils/trees/LeafExists.circom";
11
10
  include "../../utils/trees/QuinaryCheckRoot.circom";
12
11
  include "../../utils/qv/ResultCommitmentVerifier.circom";
@@ -129,10 +128,10 @@ template VoteTallyWithIndividualCountsQv(
129
128
  }
130
129
 
131
130
  var computedBallotSubroot = CheckRoot(tallyProcessingStateTreeDepth)(computedBallotHashers);
132
- var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_TREE_DEPTH_DIFFERENCE)(index / ballotBatchSize);
131
+ var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = Num2Bits(STATE_TREE_DEPTH_DIFFERENCE)(index / ballotBatchSize);
133
132
 
134
133
  var computedVoteCountsSubroot = CheckRoot(tallyProcessingStateTreeDepth)(computedVoteCountsHashers);
135
- var computedVoteCountsPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_TREE_DEPTH_DIFFERENCE)(index / voteCountsBatchSize);
134
+ var computedVoteCountsPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = Num2Bits(STATE_TREE_DEPTH_DIFFERENCE)(index / voteCountsBatchSize);
136
135
 
137
136
  // Verifies each ballot's existence within the ballot tree.
138
137
  LeafExists(STATE_TREE_DEPTH_DIFFERENCE)(
@@ -25,14 +25,17 @@ template BinaryMerkleRoot(MAX_DEPTH) {
25
25
  signal input leaf;
26
26
  // The depth of the Merkle tree.
27
27
  signal input depth;
28
- // The indices of the leaf node in the Merkle tree.
29
- signal input indices[MAX_DEPTH];
28
+ // The index of the leaf node in the Merkle tree.
29
+ signal input index;
30
30
  // The sibling nodes of the leaf node in the Merkle tree.
31
31
  signal input siblings[MAX_DEPTH][1];
32
32
 
33
33
  // The output of the Merkle tree root.
34
34
  signal output out;
35
35
 
36
+ // The indices of the leaf node in the Merkle tree.
37
+ signal indices[MAX_DEPTH] <== Num2Bits(MAX_DEPTH)(index);
38
+
36
39
  signal nodes[MAX_DEPTH + 1];
37
40
  nodes[0] <== leaf;
38
41
 
@@ -19,8 +19,8 @@ template PollJoined(stateTreeDepth) {
19
19
  signal input voiceCreditsBalance;
20
20
  // Path elements
21
21
  signal input pathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
22
- // Path indices
23
- signal input pathIndices[stateTreeDepth];
22
+ // Index
23
+ signal input index;
24
24
  // Poll State tree root which proves the user is joined
25
25
  signal input stateRoot;
26
26
  // The actual tree depth (might be <= stateTreeDepth) Used in BinaryMerkleRoot
@@ -35,7 +35,7 @@ template PollJoined(stateTreeDepth) {
35
35
  var calculatedRoot = BinaryMerkleRoot(stateTreeDepth)(
36
36
  stateLeaf,
37
37
  actualStateTreeDepth,
38
- pathIndices,
38
+ index,
39
39
  pathElements
40
40
  );
41
41
 
@@ -18,8 +18,8 @@ template PollJoining(stateTreeDepth) {
18
18
  signal input pollPublicKey[2];
19
19
  // Siblings
20
20
  signal input siblings[stateTreeDepth][STATE_TREE_ARITY - 1];
21
- // Indices
22
- signal input indices[stateTreeDepth];
21
+ // Index
22
+ signal input index;
23
23
  // User's hashed private key
24
24
  signal input nullifier;
25
25
  // MACI State tree root which proves the user is signed up
@@ -46,7 +46,7 @@ template PollJoining(stateTreeDepth) {
46
46
  var calculatedRoot = BinaryMerkleRoot(stateTreeDepth)(
47
47
  publicKeyHash,
48
48
  actualStateTreeDepth,
49
- indices,
49
+ index,
50
50
  siblings
51
51
  );
52
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maci-protocol/circuits",
3
- "version": "0.0.0-ci.153b117",
3
+ "version": "0.0.0-ci.17c3dcd",
4
4
  "private": false,
5
5
  "description": "zk-SNARK circuits for MACI",
6
6
  "main": "build/ts/index.js",
@@ -46,10 +46,10 @@
46
46
  "test:pollJoined": "pnpm run mocha-test ts/__tests__/PollJoined.test.ts"
47
47
  },
48
48
  "dependencies": {
49
- "@maci-protocol/core": "0.0.0-ci.153b117",
50
- "@maci-protocol/crypto": "0.0.0-ci.153b117",
51
- "@maci-protocol/domainobjs": "0.0.0-ci.153b117",
52
- "@maci-protocol/sdk": "0.0.0-ci.153b117",
49
+ "@maci-protocol/core": "0.0.0-ci.17c3dcd",
50
+ "@maci-protocol/crypto": "0.0.0-ci.17c3dcd",
51
+ "@maci-protocol/domainobjs": "0.0.0-ci.17c3dcd",
52
+ "@maci-protocol/sdk": "0.0.0-ci.17c3dcd",
53
53
  "@zk-kit/circuits": "^0.4.0",
54
54
  "circomkit": "^0.3.4",
55
55
  "circomlib": "^2.0.5"
@@ -70,5 +70,5 @@
70
70
  "ts-node": "^10.9.1",
71
71
  "typescript": "^5.8.3"
72
72
  },
73
- "gitHead": "3f6576c33a14b12e75979161eda002f8fb36dfca"
73
+ "gitHead": "e089df6115c9fc040b340abb97c545c569490549"
74
74
  }
@@ -1,44 +0,0 @@
1
- pragma circom 2.0.0;
2
-
3
- // zk-kit imports
4
- include "./safe-comparators.circom";
5
- // local import
6
- include "../CalculateTotal.circom";
7
-
8
- /**
9
- * Calculates the path indices required for Merkle proof verifications.
10
- * Given a node index within an IMT and the total tree levels, it outputs the path indices leading to that node.
11
- * The template handles the modulo and division operations to break down the tree index into its constituent path indices.
12
- */
13
- template MerklePathIndicesGenerator(levels) {
14
- // The base used for the modulo and division operations, set to 2 for binary trees.
15
- var BASE = 2;
16
-
17
- // The total sum of the path indices.
18
- signal input indices;
19
-
20
- // The generated path indices.
21
- signal output out[levels];
22
-
23
- var computedIndices = indices;
24
- var computedResults[levels];
25
-
26
- for (var i = 0; i < levels; i++) {
27
- // circom's best practices suggests to avoid using <-- unless you
28
- // are aware of what's going on. This is the only way to do modulo operation.
29
- out[i] <-- computedIndices % BASE;
30
- computedIndices = computedIndices \ BASE;
31
-
32
- // Check that each output element is less than the base.
33
- var computedIsOutputElementLessThanBase = SafeLessThan(3)([out[i], BASE]);
34
- computedIsOutputElementLessThanBase === 1;
35
-
36
- // Re-compute the total sum.
37
- computedResults[i] = out[i] * (BASE ** i);
38
- }
39
-
40
- // Check that the total sum matches the index.
41
- var computedCalculateTotal = CalculateTotal(levels)(computedResults);
42
-
43
- computedCalculateTotal === indices;
44
- }