@maci-protocol/circuits 0.0.0-ci.c910408 → 0.0.0-ci.ca15230

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.
@@ -202,20 +202,20 @@ include "./SingleMessageProcessor.circom";
202
202
  // Start from batchSize and decrement for process in reverse order.
203
203
  for (var i = batchSize - 1; i >= 0; i--) {
204
204
  // Process as vote type message.
205
- var currentStateLeavesPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
206
- var currentBallotPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
207
- var currentVoteWeightsPathElement[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
205
+ var computedCurrentStateLeavesPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
206
+ var computedCurrentBallotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
207
+ var computedCurrentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
208
208
 
209
209
  for (var j = 0; j < stateTreeDepth; j++) {
210
210
  for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
211
- currentStateLeavesPathElement[j][k] = currentStateLeavesPathElements[i][j][k];
212
- currentBallotPathElement[j][k] = currentBallotsPathElements[i][j][k];
211
+ computedCurrentStateLeavesPathElements[j][k] = currentStateLeavesPathElements[i][j][k];
212
+ computedCurrentBallotPathElements[j][k] = currentBallotsPathElements[i][j][k];
213
213
  }
214
214
  }
215
215
 
216
216
  for (var j = 0; j < voteOptionTreeDepth; j++) {
217
217
  for (var k = 0; k < VOTE_OPTION_TREE_ARITY - 1; k++) {
218
- currentVoteWeightsPathElement[j][k] = currentVoteWeightsPathElements[i][j][k];
218
+ computedCurrentVoteWeightsPathElements[j][k] = currentVoteWeightsPathElements[i][j][k];
219
219
  }
220
220
  }
221
221
 
@@ -225,11 +225,11 @@ include "./SingleMessageProcessor.circom";
225
225
  ballotRoots[i + 1],
226
226
  actualStateTreeDepth,
227
227
  currentStateLeaves[i],
228
- currentStateLeavesPathElement,
228
+ computedCurrentStateLeavesPathElements,
229
229
  currentBallots[i],
230
- currentBallotPathElement,
230
+ computedCurrentBallotPathElements,
231
231
  currentVoteWeights[i],
232
- currentVoteWeightsPathElement,
232
+ computedCurrentVoteWeightsPathElements,
233
233
  computedCommandsStateIndex[i],
234
234
  computedCommandsNewPublicKey[i],
235
235
  computedCommandsVoteOptionIndex[i],
@@ -209,20 +209,20 @@ include "../../utils/trees/QuinaryGeneratePathIndices.circom";
209
209
  // Start from batchSize and decrement for process in reverse order.
210
210
  for (var i = batchSize - 1; i >= 0; i--) {
211
211
  // Process as vote type message.
212
- var currentStateLeavesPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
213
- var currentBallotPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
214
- var currentVoteWeightsPathElement[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
212
+ var computedCurrentStateLeavesPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
213
+ var computedCurrentBallotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
214
+ var computedCurrentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
215
215
 
216
216
  for (var j = 0; j < stateTreeDepth; j++) {
217
217
  for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
218
- currentStateLeavesPathElement[j][k] = currentStateLeavesPathElements[i][j][k];
219
- currentBallotPathElement[j][k] = currentBallotsPathElements[i][j][k];
218
+ computedCurrentStateLeavesPathElements[j][k] = currentStateLeavesPathElements[i][j][k];
219
+ computedCurrentBallotPathElements[j][k] = currentBallotsPathElements[i][j][k];
220
220
  }
221
221
  }
222
222
 
223
223
  for (var j = 0; j < voteOptionTreeDepth; j++) {
224
224
  for (var k = 0; k < VOTE_OPTION_TREE_ARITY - 1; k++) {
225
- currentVoteWeightsPathElement[j][k] = currentVoteWeightsPathElements[i][j][k];
225
+ computedCurrentVoteWeightsPathElements[j][k] = currentVoteWeightsPathElements[i][j][k];
226
226
  }
227
227
  }
228
228
 
@@ -232,11 +232,11 @@ include "../../utils/trees/QuinaryGeneratePathIndices.circom";
232
232
  ballotRoots[i + 1],
233
233
  actualStateTreeDepth,
234
234
  currentStateLeaves[i],
235
- currentStateLeavesPathElement,
235
+ computedCurrentStateLeavesPathElements,
236
236
  currentBallots[i],
237
- currentBallotPathElement,
237
+ computedCurrentBallotPathElements,
238
238
  currentVoteWeights[i],
239
- currentVoteWeightsPathElement,
239
+ computedCurrentVoteWeightsPathElements,
240
240
  computedCommandsStateIndex[i],
241
241
  computedCommandsNewPublicKey[i],
242
242
  computedCommandsVoteOptionIndex[i],
@@ -18,22 +18,22 @@ include "../../utils/PoseidonHasher.circom";
18
18
  */
19
19
  template TallyVotesNonQv(
20
20
  stateTreeDepth,
21
- intStateTreeDepth,
21
+ tallyProcessingStateTreeDepth,
22
22
  voteOptionTreeDepth
23
23
  ) {
24
24
  // Ensure there's at least one level in the vote option tree.
25
25
  assert(voteOptionTreeDepth > 0);
26
26
  // Ensure the intermediate state tree has at least one level.
27
- assert(intStateTreeDepth > 0);
27
+ assert(tallyProcessingStateTreeDepth > 0);
28
28
  // The intermediate state tree must be smaller than the full state tree.
29
- assert(intStateTreeDepth < stateTreeDepth);
29
+ assert(tallyProcessingStateTreeDepth < stateTreeDepth);
30
30
 
31
31
  // Number of children per node in the tree, defining the tree's branching factor.
32
32
  var TREE_ARITY = 5;
33
33
  var BALLOT_TREE_ARITY = 2;
34
34
 
35
35
  // The number of ballots processed at once, determined by the depth of the intermediate state tree.
36
- var batchSize = BALLOT_TREE_ARITY ** intStateTreeDepth;
36
+ var batchSize = BALLOT_TREE_ARITY ** tallyProcessingStateTreeDepth;
37
37
  // Number of voting options available, determined by the depth of the vote option tree.
38
38
  var totalVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
39
39
 
@@ -44,7 +44,7 @@ template TallyVotesNonQv(
44
44
  // Index for the voting option root in the ballot array.
45
45
  var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
46
46
  // Difference in tree depths, used in path calculations.
47
- var STATE_INT_TREE_DEPTH_DIFFERENCE = stateTreeDepth - intStateTreeDepth;
47
+ var STATE_TREE_DEPTH_DIFFERENCE = stateTreeDepth - tallyProcessingStateTreeDepth;
48
48
 
49
49
  // Root of the state Merkle tree, representing the overall state before voting.
50
50
  signal input stateRoot;
@@ -64,7 +64,7 @@ template TallyVotesNonQv(
64
64
  signal input totalSignups;
65
65
  // Ballots and their corresponding path elements for verification in the tree.
66
66
  signal input ballots[batchSize][BALLOT_LENGTH];
67
- signal input ballotPathElements[STATE_INT_TREE_DEPTH_DIFFERENCE][BALLOT_TREE_ARITY - 1];
67
+ signal input ballotPathElements[STATE_TREE_DEPTH_DIFFERENCE][BALLOT_TREE_ARITY - 1];
68
68
  signal input votes[batchSize][totalVoteOptions];
69
69
  // Current results for each vote option.
70
70
  signal input currentResults[totalVoteOptions];
@@ -95,11 +95,11 @@ template TallyVotesNonQv(
95
95
  computedBallotHashers[i] = PoseidonHasher(2)([ballots[i][BALLOT_NONCE_INDEX], ballots[i][BALLOT_VOTE_OPTION_ROOT_INDEX]]);
96
96
  }
97
97
 
98
- var computedBallotSubroot = CheckRoot(intStateTreeDepth)(computedBallotHashers);
99
- var computedBallotPathIndices[STATE_INT_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_INT_TREE_DEPTH_DIFFERENCE)(index / batchSize);
98
+ var computedBallotSubroot = CheckRoot(tallyProcessingStateTreeDepth)(computedBallotHashers);
99
+ var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_TREE_DEPTH_DIFFERENCE)(index / batchSize);
100
100
 
101
101
  // Verifies each ballot's existence within the ballot tree.
102
- LeafExists(STATE_INT_TREE_DEPTH_DIFFERENCE)(
102
+ LeafExists(STATE_TREE_DEPTH_DIFFERENCE)(
103
103
  computedBallotSubroot,
104
104
  ballotPathElements,
105
105
  computedBallotPathIndices,
@@ -122,13 +122,14 @@ template TallyVotesNonQv(
122
122
  var computedCalculateTotalResult[totalVoteOptions];
123
123
 
124
124
  for (var i = 0; i < totalVoteOptions; i++) {
125
- var computedNumsRC[batchSize + 1];
126
- computedNumsRC[batchSize] = currentResults[i] * computedIsZero;
125
+ var computedVotes[batchSize + 1];
126
+ computedVotes[batchSize] = currentResults[i] * computedIsZero;
127
+
127
128
  for (var j = 0; j < batchSize; j++) {
128
- computedNumsRC[j] = votes[j][i];
129
+ computedVotes[j] = votes[j][i];
129
130
  }
130
131
 
131
- computedCalculateTotalResult[i] = CalculateTotal(batchSize + 1)(computedNumsRC);
132
+ computedCalculateTotalResult[i] = CalculateTotal(batchSize + 1)(computedVotes);
132
133
  }
133
134
 
134
135
  // Tally the new spent voice credit total.
@@ -235,4 +236,3 @@ template TallyVotesNonQv(
235
236
 
236
237
  computedNewTallyCommitment === newTallyCommitment;
237
238
  }
238
-
@@ -206,20 +206,20 @@ template ProcessMessages(
206
206
  // Start from batchSize and decrement for process in reverse order.
207
207
  for (var i = batchSize - 1; i >= 0; i--) {
208
208
  // Process as vote type message.
209
- var currentStateLeavesPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
210
- var currentBallotPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
211
- var currentVoteWeightsPathElement[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
209
+ var computedCurrentStateLeavesPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
210
+ var computedCurrentBallotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
211
+ var computedCurrentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
212
212
 
213
213
  for (var j = 0; j < stateTreeDepth; j++) {
214
214
  for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
215
- currentStateLeavesPathElement[j][k] = currentStateLeavesPathElements[i][j][k];
216
- currentBallotPathElement[j][k] = currentBallotsPathElements[i][j][k];
215
+ computedCurrentStateLeavesPathElements[j][k] = currentStateLeavesPathElements[i][j][k];
216
+ computedCurrentBallotPathElements[j][k] = currentBallotsPathElements[i][j][k];
217
217
  }
218
218
  }
219
219
 
220
220
  for (var j = 0; j < voteOptionTreeDepth; j++) {
221
221
  for (var k = 0; k < VOTE_OPTION_TREE_ARITY - 1; k++) {
222
- currentVoteWeightsPathElement[j][k] = currentVoteWeightsPathElements[i][j][k];
222
+ computedCurrentVoteWeightsPathElements[j][k] = currentVoteWeightsPathElements[i][j][k];
223
223
  }
224
224
  }
225
225
 
@@ -229,11 +229,11 @@ template ProcessMessages(
229
229
  ballotRoots[i + 1],
230
230
  actualStateTreeDepth,
231
231
  currentStateLeaves[i],
232
- currentStateLeavesPathElement,
232
+ computedCurrentStateLeavesPathElements,
233
233
  currentBallots[i],
234
- currentBallotPathElement,
234
+ computedCurrentBallotPathElements,
235
235
  currentVoteWeights[i],
236
- currentVoteWeightsPathElement,
236
+ computedCurrentVoteWeightsPathElements,
237
237
  computedCommandsStateIndex[i],
238
238
  computedCommandsNewPublicKey[i],
239
239
  computedCommandsVoteOptionIndex[i],
@@ -18,22 +18,22 @@ include "../../utils/PoseidonHasher.circom";
18
18
  */
19
19
  template TallyVotes(
20
20
  stateTreeDepth,
21
- intStateTreeDepth,
21
+ tallyProcessingStateTreeDepth,
22
22
  voteOptionTreeDepth
23
23
  ) {
24
24
  // Ensure there's at least one level in the vote option tree.
25
25
  assert(voteOptionTreeDepth > 0);
26
26
  // Ensure the intermediate state tree has at least one level.
27
- assert(intStateTreeDepth > 0);
27
+ assert(tallyProcessingStateTreeDepth > 0);
28
28
  // The intermediate state tree must be smaller than the full state tree.
29
- assert(intStateTreeDepth < stateTreeDepth);
29
+ assert(tallyProcessingStateTreeDepth < stateTreeDepth);
30
30
 
31
31
  // Number of children per node in the tree, defining the tree's branching factor.
32
32
  var TREE_ARITY = 5;
33
33
  var BALLOT_TREE_ARITY = 2;
34
34
 
35
35
  // The number of ballots processed at once, determined by the depth of the intermediate state tree.
36
- var batchSize = BALLOT_TREE_ARITY ** intStateTreeDepth;
36
+ var batchSize = BALLOT_TREE_ARITY ** tallyProcessingStateTreeDepth;
37
37
  // Number of voting options available, determined by the depth of the vote option tree.
38
38
  var totalVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
39
39
 
@@ -44,7 +44,7 @@ template TallyVotes(
44
44
  // Index for the voting option root in the ballot array.
45
45
  var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
46
46
  // Difference in tree depths, used in path calculations.
47
- var STATE_INT_TREE_DEPTH_DIFFERENCE = stateTreeDepth - intStateTreeDepth;
47
+ var STATE_TREE_DEPTH_DIFFERENCE = stateTreeDepth - tallyProcessingStateTreeDepth;
48
48
 
49
49
  // Root of the state Merkle tree, representing the overall state before voting.
50
50
  signal input stateRoot;
@@ -64,7 +64,7 @@ template TallyVotes(
64
64
  signal input totalSignups;
65
65
  // Ballots and their corresponding path elements for verification in the tree.
66
66
  signal input ballots[batchSize][BALLOT_LENGTH];
67
- signal input ballotPathElements[STATE_INT_TREE_DEPTH_DIFFERENCE][BALLOT_TREE_ARITY - 1];
67
+ signal input ballotPathElements[STATE_TREE_DEPTH_DIFFERENCE][BALLOT_TREE_ARITY - 1];
68
68
  signal input votes[batchSize][totalVoteOptions];
69
69
  // Current results for each vote option.
70
70
  signal input currentResults[totalVoteOptions];
@@ -100,11 +100,11 @@ template TallyVotes(
100
100
  computedBallotHashers[i] = PoseidonHasher(2)([ballots[i][BALLOT_NONCE_INDEX], ballots[i][BALLOT_VOTE_OPTION_ROOT_INDEX]]);
101
101
  }
102
102
 
103
- var computedBallotSubroot = CheckRoot(intStateTreeDepth)(computedBallotHashers);
104
- var computedBallotPathIndices[STATE_INT_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_INT_TREE_DEPTH_DIFFERENCE)(index / batchSize);
103
+ var computedBallotSubroot = CheckRoot(tallyProcessingStateTreeDepth)(computedBallotHashers);
104
+ var computedBallotPathIndices[STATE_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_TREE_DEPTH_DIFFERENCE)(index / batchSize);
105
105
 
106
106
  // Verifies each ballot's existence within the ballot tree.
107
- LeafExists(STATE_INT_TREE_DEPTH_DIFFERENCE)(
107
+ LeafExists(STATE_TREE_DEPTH_DIFFERENCE)(
108
108
  computedBallotSubroot,
109
109
  ballotPathElements,
110
110
  computedBallotPathIndices,
@@ -1,24 +1,24 @@
1
1
  pragma circom 2.0.0;
2
2
 
3
3
  /**
4
- * Computes the cumulative sum of an array of n input signals.
4
+ * Computes the cumulative sum of an array of length input signals.
5
5
  * It iterates through each input, aggregating the sum up to that point,
6
6
  * and outputs the total sum of all inputs. This template is useful for
7
7
  * operations requiring the total sum of multiple signals, ensuring the
8
8
  * final output reflects the cumulative total of the inputs provided.
9
9
  */
10
- template CalculateTotal(n) {
10
+ template CalculateTotal(length) {
11
11
  // Array of values.
12
- signal input nums[n];
12
+ signal input nums[length];
13
13
  // Total sum.
14
14
  signal output sum;
15
15
 
16
- signal sums[n];
16
+ signal sums[length];
17
17
  sums[0] <== nums[0];
18
18
 
19
- for (var i = 1; i < n; i++) {
19
+ for (var i = 1; i < length; i++) {
20
20
  sums[i] <== sums[i - 1] + nums[i];
21
21
  }
22
22
 
23
- sum <== sums[n - 1];
23
+ sum <== sums[length - 1];
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maci-protocol/circuits",
3
- "version": "0.0.0-ci.c910408",
3
+ "version": "0.0.0-ci.ca15230",
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.c910408",
50
- "@maci-protocol/crypto": "0.0.0-ci.c910408",
51
- "@maci-protocol/domainobjs": "0.0.0-ci.c910408",
52
- "@maci-protocol/sdk": "0.0.0-ci.c910408",
49
+ "@maci-protocol/core": "0.0.0-ci.ca15230",
50
+ "@maci-protocol/crypto": "0.0.0-ci.ca15230",
51
+ "@maci-protocol/domainobjs": "0.0.0-ci.ca15230",
52
+ "@maci-protocol/sdk": "0.0.0-ci.ca15230",
53
53
  "@zk-kit/circuits": "^0.4.0",
54
54
  "circomkit": "^0.3.2",
55
55
  "circomlib": "^2.0.5"
@@ -58,17 +58,17 @@
58
58
  "@types/chai": "^4.3.11",
59
59
  "@types/chai-as-promised": "^7.1.8",
60
60
  "@types/mocha": "^10.0.10",
61
- "@types/node": "^22.15.8",
61
+ "@types/node": "^22.15.17",
62
62
  "@types/snarkjs": "^0.7.9",
63
63
  "@zk-kit/baby-jubjub": "^1.0.3",
64
64
  "chai": "^4.3.10",
65
65
  "chai-as-promised": "^7.1.2",
66
66
  "fast-check": "^4.1.1",
67
67
  "glob": "^11.0.1",
68
- "mocha": "^11.1.0",
68
+ "mocha": "^11.2.2",
69
69
  "ts-mocha": "^11.1.0",
70
70
  "ts-node": "^10.9.1",
71
71
  "typescript": "^5.8.3"
72
72
  },
73
- "gitHead": "813dec205168adc09564e15a7d75244dc283ec7f"
73
+ "gitHead": "59235076599fc5a3ed416aa6481579dd9467f251"
74
74
  }