@maci-protocol/circuits 0.0.0-ci.fb960ed → 0.0.0-ci.fc91dc9

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.
@@ -16,7 +16,7 @@
16
16
  "template": "ProcessMessages",
17
17
  "params": [10, 20, 2],
18
18
  "pubs": [
19
- "numSignUps",
19
+ "totalSignups",
20
20
  "index",
21
21
  "batchEndIndex",
22
22
  "currentSbCommitment",
@@ -32,7 +32,7 @@
32
32
  "template": "ProcessMessagesNonQv",
33
33
  "params": [10, 20, 2],
34
34
  "pubs": [
35
- "numSignUps",
35
+ "totalSignups",
36
36
  "index",
37
37
  "batchEndIndex",
38
38
  "currentSbCommitment",
@@ -47,12 +47,12 @@
47
47
  "file": "./coordinator/qv/tallyVotes",
48
48
  "template": "TallyVotes",
49
49
  "params": [10, 1, 2],
50
- "pubs": ["index", "numSignUps", "sbCommitment", "currentTallyCommitment", "newTallyCommitment"]
50
+ "pubs": ["index", "totalSignups", "sbCommitment", "currentTallyCommitment", "newTallyCommitment"]
51
51
  },
52
52
  "TallyVotesNonQv_10-1-2_test": {
53
53
  "file": "./coordinator/non-qv/tallyVotes",
54
54
  "template": "TallyVotesNonQv",
55
55
  "params": [10, 1, 2],
56
- "pubs": ["index", "numSignUps", "sbCommitment", "currentTallyCommitment", "newTallyCommitment"]
56
+ "pubs": ["index", "totalSignups", "sbCommitment", "currentTallyCommitment", "newTallyCommitment"]
57
57
  }
58
58
  }
@@ -9,11 +9,11 @@ include "../../utils/PoseidonHasher.circom";
9
9
  include "../../utils/MessageHasher.circom";
10
10
  include "../../utils/MessageToCommand.circom";
11
11
  include "../../utils/PrivateToPublicKey.circom";
12
- include "../../utils/non-qv/stateLeafAndBallotTransformer.circom";
12
+ include "../../utils/non-qv/StateLeafAndBallotTransformer.circom";
13
13
  include "../../utils/trees/MerkleTreeInclusionProof.circom";
14
14
  include "../../utils/trees/LeafExists.circom";
15
15
  include "../../utils/trees/CheckRoot.circom";
16
- include "../../utils/trees/MerkleGeneratePathIndices.circom";
16
+ include "../../utils/trees/MerklePathIndicesGenerator.circom";
17
17
  include "../../utils/trees/BinaryMerkleRoot.circom";
18
18
  include "../../utils/trees/incrementalQuinaryTree.circom";
19
19
 
@@ -35,27 +35,27 @@ include "../../utils/trees/incrementalQuinaryTree.circom";
35
35
  var VOTE_OPTION_TREE_ARITY = 5;
36
36
  // Default for Binary trees.
37
37
  var STATE_TREE_ARITY = 2;
38
- var MSG_LENGTH = 10;
39
- var PACKED_CMD_LENGTH = 4;
38
+ var MESSAGE_LENGTH = 10;
39
+ var PACKED_COMMAND_LENGTH = 4;
40
40
  var STATE_LEAF_LENGTH = 3;
41
41
  var BALLOT_LENGTH = 2;
42
- var BALLOT_NONCE_IDX = 0;
43
- var BALLOT_VO_ROOT_IDX = 1;
44
- var STATE_LEAF_PUB_X_IDX = 0;
45
- var STATE_LEAF_PUB_Y_IDX = 1;
46
- var STATE_LEAF_VOICE_CREDIT_BALANCE_IDX = 2;
47
- var msgTreeZeroValue = 8370432830353022751713833565135785980866757267633941821328460903436894336785;
42
+ var BALLOT_NONCE_INDEX = 0;
43
+ var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
44
+ var STATE_LEAF_PUBLIC_X_INDEX = 0;
45
+ var STATE_LEAF_PUBLIC_Y_INDEX = 1;
46
+ var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
47
+ var MESSAGE_TREE_ZERO_VALUE = 8370432830353022751713833565135785980866757267633941821328460903436894336785;
48
48
  // Number of options for this poll.
49
49
  var maxVoteOptions = VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth;
50
50
 
51
51
  // Number of users that have completed the sign up.
52
- signal input numSignUps;
52
+ signal input totalSignups;
53
53
  // Value of chainHash at beginning of batch
54
54
  signal input inputBatchHash;
55
55
  // Value of chainHash at end of batch
56
56
  signal input outputBatchHash;
57
57
  // The messages.
58
- signal input messages[batchSize][MSG_LENGTH];
58
+ signal input messages[batchSize][MESSAGE_LENGTH];
59
59
  // The coordinator's private key.
60
60
  signal input coordinatorPrivateKey;
61
61
  // The ECDH public key per message.
@@ -113,31 +113,28 @@ include "../../utils/trees/incrementalQuinaryTree.circom";
113
113
  // signals (for processing purposes).
114
114
  signal stateRoots[batchSize + 1];
115
115
  signal ballotRoots[batchSize + 1];
116
- signal tmpStateRoot1[batchSize];
117
- signal tmpStateRoot2[batchSize];
118
- signal tmpBallotRoot1[batchSize];
119
- signal tmpBallotRoot2[batchSize];
120
116
 
121
117
  // Must verify the current sb commitment.
122
118
  var computedCurrentSbCommitment = PoseidonHasher(3)([currentStateRoot, currentBallotRoot, currentSbSalt]);
123
119
  computedCurrentSbCommitment === currentSbCommitment;
124
120
 
125
121
  // -----------------------------------------------------------------------
126
- // 0. Ensure that the maximum vote options signal is valid and if
122
+ // 0. Ensure that the maximum vote options signal is valid and if
127
123
  // the maximum users signal is valid
128
124
  var voteOptionsValid = LessEqThan(32)([voteOptions, VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth]);
129
125
  voteOptionsValid === 1;
130
126
 
131
- // Check numSignUps <= the max number of users (i.e., number of state leaves
127
+ // Check totalSignups <= the max number of users (i.e., number of state leaves
132
128
  // that can fit the state tree).
133
- var numSignUpsValid = LessEqThan(32)([numSignUps, STATE_TREE_ARITY ** stateTreeDepth]);
134
- numSignUpsValid === 1;
129
+ var totalSignupsValid = LessEqThan(32)([totalSignups, STATE_TREE_ARITY ** stateTreeDepth]);
130
+ totalSignupsValid === 1;
135
131
 
136
132
  // Hash each Message to check their existence in the Message chain hash.
137
133
  var computedMessageHashers[batchSize];
138
134
  var computedChainHashes[batchSize];
139
135
  var chainHash[batchSize + 1];
140
136
  chainHash[0] = inputBatchHash;
137
+
141
138
  for (var i = 0; i < batchSize; i++) {
142
139
  // calculate message hash
143
140
  computedMessageHashers[i] = MessageHasher()(messages[i], encryptionPublicKeys[i]);
@@ -165,36 +162,36 @@ include "../../utils/trees/incrementalQuinaryTree.circom";
165
162
  // Ensure that the coordinator's public key from the contract is correct
166
163
  // based on the given private key - that is, the prover knows the
167
164
  // coordinator's private key.
168
- var derivedPubKey[2] = PrivateToPublicKey()(coordinatorPrivateKey);
169
- var derivedPubKeyHash = PoseidonHasher(2)(derivedPubKey);
170
- derivedPubKeyHash === coordinatorPublicKeyHash;
165
+ var derivedPublicKey[2] = PrivateToPublicKey()(coordinatorPrivateKey);
166
+ var derivedPublicKeyHash = PoseidonHasher(2)(derivedPublicKey);
167
+ derivedPublicKeyHash === coordinatorPublicKeyHash;
171
168
 
172
169
  // Decrypt each Message into a Command.
173
170
  // The command i-th is composed by the following fields.
174
171
  // e.g., command 0 is made of commandsStateIndex[0],
175
- // commandsNewPubKey[0], ..., commandsPackedCommandOut[0]
172
+ // commandsNewPublicKey[0], ..., commandsPackedCommandOut[0]
176
173
  var computedCommandsStateIndex[batchSize];
177
- var computedCommandsNewPubKey[batchSize][2];
174
+ var computedCommandsNewPublicKey[batchSize][2];
178
175
  var computedCommandsVoteOptionIndex[batchSize];
179
176
  var computedCommandsNewVoteWeight[batchSize];
180
177
  var computedCommandsNonce[batchSize];
181
178
  var computedCommandsPollId[batchSize];
182
179
  var computedCommandsSalt[batchSize];
183
- var computedCommandsSigR8[batchSize][2];
184
- var computedCommandsSigS[batchSize];
185
- var computedCommandsPackedCommandOut[batchSize][PACKED_CMD_LENGTH];
180
+ var computedCommandsSignaturePoint[batchSize][2];
181
+ var computedCommandsSignatureScalar[batchSize];
182
+ var computedCommandsPackedCommandOut[batchSize][PACKED_COMMAND_LENGTH];
186
183
 
187
184
  for (var i = 0; i < batchSize; i++) {
188
185
  (
189
186
  computedCommandsStateIndex[i],
190
- computedCommandsNewPubKey[i],
187
+ computedCommandsNewPublicKey[i],
191
188
  computedCommandsVoteOptionIndex[i],
192
189
  computedCommandsNewVoteWeight[i],
193
190
  computedCommandsNonce[i],
194
191
  computedCommandsPollId[i],
195
192
  computedCommandsSalt[i],
196
- computedCommandsSigR8[i],
197
- computedCommandsSigS[i],
193
+ computedCommandsSignaturePoint[i],
194
+ computedCommandsSignatureScalar[i],
198
195
  computedCommandsPackedCommandOut[i]
199
196
  ) = MessageToCommand()(messages[i], coordinatorPrivateKey, encryptionPublicKeys[i]);
200
197
  }
@@ -229,7 +226,7 @@ include "../../utils/trees/incrementalQuinaryTree.circom";
229
226
  }
230
227
 
231
228
  (computedNewVoteStateRoot[i], computedNewVoteBallotRoot[i]) = ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth)(
232
- numSignUps,
229
+ totalSignups,
233
230
  stateRoots[i + 1],
234
231
  ballotRoots[i + 1],
235
232
  actualStateTreeDepth,
@@ -240,14 +237,14 @@ include "../../utils/trees/incrementalQuinaryTree.circom";
240
237
  currentVoteWeights[i],
241
238
  currentVoteWeightsPathElement,
242
239
  computedCommandsStateIndex[i],
243
- computedCommandsNewPubKey[i],
240
+ computedCommandsNewPublicKey[i],
244
241
  computedCommandsVoteOptionIndex[i],
245
242
  computedCommandsNewVoteWeight[i],
246
243
  computedCommandsNonce[i],
247
244
  computedCommandsPollId[i],
248
245
  computedCommandsSalt[i],
249
- computedCommandsSigR8[i],
250
- computedCommandsSigS[i],
246
+ computedCommandsSignaturePoint[i],
247
+ computedCommandsSignatureScalar[i],
251
248
  computedCommandsPackedCommandOut[i],
252
249
  voteOptions
253
250
  );
@@ -272,24 +269,24 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
272
269
  // Constants defining the structure and size of state and ballots.
273
270
  var STATE_LEAF_LENGTH = 3;
274
271
  var BALLOT_LENGTH = 2;
275
- var MSG_LENGTH = 10;
276
- var PACKED_CMD_LENGTH = 4;
272
+ var MESSAGE_LENGTH = 10;
273
+ var PACKED_COMMAND_LENGTH = 4;
277
274
  var VOTE_OPTION_TREE_ARITY = 5;
278
275
  var STATE_TREE_ARITY = 2;
279
- var BALLOT_NONCE_IDX = 0;
280
- // Ballot vote option (VO) root index.
281
- var BALLOT_VO_ROOT_IDX = 1;
276
+ var BALLOT_NONCE_INDEX = 0;
277
+ // Ballot vote option (vote option) root index.
278
+ var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
282
279
 
283
280
  // Indices for elements within a state leaf.
284
281
  // Public key.
285
- var STATE_LEAF_PUB_X_IDX = 0;
286
- var STATE_LEAF_PUB_Y_IDX = 1;
282
+ var STATE_LEAF_PUBLIC_X_INDEX = 0;
283
+ var STATE_LEAF_PUBLIC_Y_INDEX = 1;
287
284
  // Voice Credit balance.
288
- var STATE_LEAF_VOICE_CREDIT_BALANCE_IDX = 2;
289
- var N_BITS = 252;
285
+ var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
286
+ var NUMBER_BITS = 252;
290
287
 
291
288
  // Number of users that have completed the sign up.
292
- signal input numSignUps;
289
+ signal input totalSignups;
293
290
  // The current value of the state tree root.
294
291
  signal input currentStateRoot;
295
292
  // The current value of the ballot tree root.
@@ -311,16 +308,16 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
311
308
  signal input currentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
312
309
 
313
310
  // Inputs related to the command being processed.
314
- signal input cmdStateIndex;
315
- signal input cmdNewPubKey[2];
316
- signal input cmdVoteOptionIndex;
317
- signal input cmdNewVoteWeight;
318
- signal input cmdNonce;
319
- signal input cmdPollId;
320
- signal input cmdSalt;
321
- signal input cmdSigR8[2];
322
- signal input cmdSigS;
323
- signal input packedCmd[PACKED_CMD_LENGTH];
311
+ signal input commandStateIndex;
312
+ signal input commandPublicKey[2];
313
+ signal input commandVoteOptionIndex;
314
+ signal input commandNewVoteWeight;
315
+ signal input commandNonce;
316
+ signal input commandPollId;
317
+ signal input commandSalt;
318
+ signal input commandSignaturePoint[2];
319
+ signal input commandSignatureScalar;
320
+ signal input packedCommand[PACKED_COMMAND_LENGTH];
324
321
 
325
322
  // The number of valid vote options for the poll.
326
323
  signal input voteOptions;
@@ -328,35 +325,35 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
328
325
  signal output newStateRoot;
329
326
  signal output newBallotRoot;
330
327
 
331
- // equal to newBallotVoRootMux (Mux1).
328
+ // equal to newBallotVoteOptionRootMux (Mux1).
332
329
  signal newBallotVoRoot;
333
330
 
334
331
  // 1. Transform a state leaf and a ballot with a command.
335
332
  // The result is a new state leaf, a new ballot, and an isValid signal (0 or 1).
336
- var computedNewSlPubKey[2], computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid;
337
- (computedNewSlPubKey, computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = StateLeafAndBallotTransformerNonQv()(
338
- numSignUps,
333
+ var computedNewstateLeafPublicKey[2], computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid;
334
+ (computedNewstateLeafPublicKey, computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = StateLeafAndBallotTransformerNonQv()(
335
+ totalSignups,
339
336
  voteOptions,
340
- [stateLeaf[STATE_LEAF_PUB_X_IDX], stateLeaf[STATE_LEAF_PUB_Y_IDX]],
341
- stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
342
- ballot[BALLOT_NONCE_IDX],
337
+ [stateLeaf[STATE_LEAF_PUBLIC_X_INDEX], stateLeaf[STATE_LEAF_PUBLIC_Y_INDEX]],
338
+ stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX],
339
+ ballot[BALLOT_NONCE_INDEX],
343
340
  currentVoteWeight,
344
- cmdStateIndex,
345
- cmdNewPubKey,
346
- cmdVoteOptionIndex,
347
- cmdNewVoteWeight,
348
- cmdNonce,
349
- cmdPollId,
350
- cmdSalt,
351
- cmdSigR8,
352
- cmdSigS,
353
- packedCmd
341
+ commandStateIndex,
342
+ commandPublicKey,
343
+ commandVoteOptionIndex,
344
+ commandNewVoteWeight,
345
+ commandNonce,
346
+ commandPollId,
347
+ commandSalt,
348
+ commandSignaturePoint,
349
+ commandSignatureScalar,
350
+ packedCommand
354
351
  );
355
352
 
356
353
  // 2. If computedIsStateLeafIndexValid is equal to zero, generate indices for leaf zero.
357
354
  // Otherwise, generate indices for command.stateIndex.
358
- var stateIndexMux = Mux1()([0, cmdStateIndex], computedIsStateLeafIndexValid);
359
- var computedStateLeafPathIndices[stateTreeDepth] = MerkleGeneratePathIndices(stateTreeDepth)(stateIndexMux);
355
+ var stateIndexMux = Mux1()([0, commandStateIndex], computedIsStateLeafIndexValid);
356
+ var computedStateLeafPathIndices[stateTreeDepth] = MerklePathIndicesGenerator(stateTreeDepth)(stateIndexMux);
360
357
 
361
358
  // 3. Verify that the original state leaf exists in the given state root.
362
359
  var stateLeafHash = PoseidonHasher(3)(stateLeaf);
@@ -371,8 +368,8 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
371
368
 
372
369
  // 4. Verify that the original ballot exists in the given ballot root.
373
370
  var computedBallot = PoseidonHasher(2)([
374
- ballot[BALLOT_NONCE_IDX],
375
- ballot[BALLOT_VO_ROOT_IDX]
371
+ ballot[BALLOT_NONCE_INDEX],
372
+ ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
376
373
  ]);
377
374
 
378
375
  var computedBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
@@ -384,9 +381,9 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
384
381
  computedBallotQip === currentBallotRoot;
385
382
 
386
383
  // 5. Verify that currentVoteWeight exists in the ballot's vote option root
387
- // at cmdVoteOptionIndex.
388
- var cmdVoteOptionIndexMux = Mux1()([0, cmdVoteOptionIndex], computedIsVoteOptionIndexValid);
389
- var computedCurrentVoteWeightPathIndices[voteOptionTreeDepth] = QuinGeneratePathIndices(voteOptionTreeDepth)(cmdVoteOptionIndexMux);
384
+ // at commandVoteOptionIndex.
385
+ var commandVoteOptionIndexMux = Mux1()([0, commandVoteOptionIndex], computedIsVoteOptionIndexValid);
386
+ var computedCurrentVoteWeightPathIndices[voteOptionTreeDepth] = QuinGeneratePathIndices(voteOptionTreeDepth)(commandVoteOptionIndexMux);
390
387
 
391
388
  var computedCurrentVoteWeightQip = QuinTreeInclusionProof(voteOptionTreeDepth)(
392
389
  currentVoteWeight,
@@ -394,13 +391,13 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
394
391
  currentVoteWeightsPathElements
395
392
  );
396
393
 
397
- computedCurrentVoteWeightQip === ballot[BALLOT_VO_ROOT_IDX];
394
+ computedCurrentVoteWeightQip === ballot[BALLOT_VOTE_OPTION_ROOT_INDEX];
398
395
 
399
- var voteWeightMux = Mux1()([currentVoteWeight, cmdNewVoteWeight], computedIsValid);
396
+ var voteWeightMux = Mux1()([currentVoteWeight, commandNewVoteWeight], computedIsValid);
400
397
  var voiceCreditBalanceMux = Mux1()(
401
398
  [
402
- stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
403
- stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeight - cmdNewVoteWeight
399
+ stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX],
400
+ stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX] + currentVoteWeight - commandNewVoteWeight
404
401
  ],
405
402
  computedIsValid
406
403
  );
@@ -413,17 +410,17 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
413
410
  );
414
411
 
415
412
  // The new vote option root in the ballot
416
- var newBallotVoRootMux = Mux1()(
417
- [ballot[BALLOT_VO_ROOT_IDX], computedNewVoteOptionTreeQip],
413
+ var newBallotVoteOptionRootMux = Mux1()(
414
+ [ballot[BALLOT_VOTE_OPTION_ROOT_INDEX], computedNewVoteOptionTreeQip],
418
415
  computedIsValid
419
416
  );
420
417
 
421
- newBallotVoRoot <== newBallotVoRootMux;
418
+ newBallotVoRoot <== newBallotVoteOptionRootMux;
422
419
 
423
420
  // 6. Generate a new state root.
424
421
  var computedNewStateLeafhash = PoseidonHasher(3)([
425
- computedNewSlPubKey[STATE_LEAF_PUB_X_IDX],
426
- computedNewSlPubKey[STATE_LEAF_PUB_Y_IDX],
422
+ computedNewstateLeafPublicKey[STATE_LEAF_PUBLIC_X_INDEX],
423
+ computedNewstateLeafPublicKey[STATE_LEAF_PUBLIC_Y_INDEX],
427
424
  voiceCreditBalanceMux
428
425
  ]);
429
426
 
@@ -6,7 +6,7 @@ include "./comparators.circom";
6
6
  include "./unpack-element.circom";
7
7
  // local imports
8
8
  include "../../utils/trees/CheckRoot.circom";
9
- include "../../utils/trees/MerkleGeneratePathIndices.circom";
9
+ include "../../utils/trees/MerklePathIndicesGenerator.circom";
10
10
  include "../../utils/trees/LeafExists.circom";
11
11
  include "../../utils/trees/incrementalQuinaryTree.circom";
12
12
  include "../../utils/CalculateTotal.circom";
@@ -35,16 +35,16 @@ template TallyVotesNonQv(
35
35
  // The number of ballots processed at once, determined by the depth of the intermediate state tree.
36
36
  var batchSize = BALLOT_TREE_ARITY ** intStateTreeDepth;
37
37
  // Number of voting options available, determined by the depth of the vote option tree.
38
- var numVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
38
+ var totalVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
39
39
 
40
40
  // Number of elements in each ballot.
41
41
  var BALLOT_LENGTH = 2;
42
42
  // Index for the nonce in the ballot array.
43
- var BALLOT_NONCE_IDX = 0;
43
+ var BALLOT_NONCE_INDEX = 0;
44
44
  // Index for the voting option root in the ballot array.
45
- var BALLOT_VO_ROOT_IDX = 1;
45
+ var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
46
46
  // Difference in tree depths, used in path calculations.
47
- var k = stateTreeDepth - intStateTreeDepth;
47
+ var STATE_INT_TREE_DEPTH_DIFFERENCE = stateTreeDepth - intStateTreeDepth;
48
48
 
49
49
  // Root of the state Merkle tree, representing the overall state before voting.
50
50
  signal input stateRoot;
@@ -61,13 +61,13 @@ template TallyVotesNonQv(
61
61
  // Start index of given batch
62
62
  signal input index;
63
63
  // Number of users that signup
64
- signal input numSignUps;
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[k][BALLOT_TREE_ARITY - 1];
68
- signal input votes[batchSize][numVoteOptions];
67
+ signal input ballotPathElements[STATE_INT_TREE_DEPTH_DIFFERENCE][BALLOT_TREE_ARITY - 1];
68
+ signal input votes[batchSize][totalVoteOptions];
69
69
  // Current results for each vote option.
70
- signal input currentResults[numVoteOptions];
70
+ signal input currentResults[totalVoteOptions];
71
71
  // Salt for the root of the current results.
72
72
  signal input currentResultsRootSalt;
73
73
  // Total voice credits spent so far.
@@ -85,21 +85,21 @@ template TallyVotesNonQv(
85
85
 
86
86
 
87
87
  // Validates that the index is within the valid range of sign-ups.
88
- var numSignUpsValid = LessEqThan(50)([index, numSignUps]);
89
- numSignUpsValid === 1;
88
+ var totalSignupsValid = LessEqThan(50)([index, totalSignups]);
89
+ totalSignupsValid === 1;
90
90
 
91
91
  // Hashes each ballot for subroot generation, and checks the existence of the leaf in the Merkle tree.
92
92
  var computedBallotHashers[batchSize];
93
93
 
94
94
  for (var i = 0; i < batchSize; i++) {
95
- computedBallotHashers[i] = PoseidonHasher(2)([ballots[i][BALLOT_NONCE_IDX], ballots[i][BALLOT_VO_ROOT_IDX]]);
95
+ computedBallotHashers[i] = PoseidonHasher(2)([ballots[i][BALLOT_NONCE_INDEX], ballots[i][BALLOT_VOTE_OPTION_ROOT_INDEX]]);
96
96
  }
97
97
 
98
98
  var computedBallotSubroot = CheckRoot(intStateTreeDepth)(computedBallotHashers);
99
- var computedBallotPathIndices[k] = MerkleGeneratePathIndices(k)(index / batchSize);
99
+ var computedBallotPathIndices[STATE_INT_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_INT_TREE_DEPTH_DIFFERENCE)(index / batchSize);
100
100
 
101
101
  // Verifies each ballot's existence within the ballot tree.
102
- LeafExists(k)(
102
+ LeafExists(STATE_INT_TREE_DEPTH_DIFFERENCE)(
103
103
  computedBallotSubroot,
104
104
  ballotPathElements,
105
105
  computedBallotPathIndices,
@@ -108,9 +108,10 @@ template TallyVotesNonQv(
108
108
 
109
109
  // Processes vote options, verifying each against its declared root.
110
110
  var computedVoteTree[batchSize];
111
+
111
112
  for (var i = 0; i < batchSize; i++) {
112
113
  computedVoteTree[i] = QuinCheckRoot(voteOptionTreeDepth)(votes[i]);
113
- computedVoteTree[i] === ballots[i][BALLOT_VO_ROOT_IDX];
114
+ computedVoteTree[i] === ballots[i][BALLOT_VOTE_OPTION_ROOT_INDEX];
114
115
  }
115
116
 
116
117
  // Calculates new results and spent voice credits based on the current and incoming votes.
@@ -118,8 +119,9 @@ template TallyVotesNonQv(
118
119
  var computedIsZero = IsZero()(computedIsFirstBatch);
119
120
 
120
121
  // Tally the new results.
121
- var computedCalculateTotalResult[numVoteOptions];
122
- for (var i = 0; i < numVoteOptions; i++) {
122
+ var computedCalculateTotalResult[totalVoteOptions];
123
+
124
+ for (var i = 0; i < totalVoteOptions; i++) {
123
125
  var computedNumsRC[batchSize + 1];
124
126
  computedNumsRC[batchSize] = currentResults[i] * computedIsZero;
125
127
  for (var j = 0; j < batchSize; j++) {
@@ -130,15 +132,16 @@ template TallyVotesNonQv(
130
132
  }
131
133
 
132
134
  // Tally the new spent voice credit total.
133
- var computedNumsSVC[batchSize * numVoteOptions + 1];
134
- computedNumsSVC[batchSize * numVoteOptions] = currentSpentVoiceCreditSubtotal * computedIsZero;
135
+ var computedNumsSVC[batchSize * totalVoteOptions + 1];
136
+ computedNumsSVC[batchSize * totalVoteOptions] = currentSpentVoiceCreditSubtotal * computedIsZero;
137
+
135
138
  for (var i = 0; i < batchSize; i++) {
136
- for (var j = 0; j < numVoteOptions; j++) {
137
- computedNumsSVC[i * numVoteOptions + j] = votes[i][j];
139
+ for (var j = 0; j < totalVoteOptions; j++) {
140
+ computedNumsSVC[i * totalVoteOptions + j] = votes[i][j];
138
141
  }
139
142
  }
140
143
 
141
- var computedNewSpentVoiceCreditSubtotal = CalculateTotal(batchSize * numVoteOptions + 1)(computedNumsSVC);
144
+ var computedNewSpentVoiceCreditSubtotal = CalculateTotal(batchSize * totalVoteOptions + 1)(computedNumsSVC);
142
145
 
143
146
  // Verifies the updated results and spent credits, ensuring consistency and correctness of tally updates.
144
147
  ResultCommitmentVerifierNonQv(voteOptionTreeDepth)(
@@ -165,7 +168,7 @@ template TallyVotesNonQv(
165
168
  // Number of children per node in the tree, defining the tree's branching factor.
166
169
  var TREE_ARITY = 5;
167
170
  // Number of voting options available, determined by the depth of the vote option tree.
168
- var numVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
171
+ var totalVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
169
172
 
170
173
  // Equal to 1 if this is the first batch, otherwise 0.
171
174
  signal input isFirstBatch;
@@ -175,12 +178,12 @@ template TallyVotesNonQv(
175
178
  signal input newTallyCommitment;
176
179
 
177
180
  // Current results for each vote option.
178
- signal input currentResults[numVoteOptions];
181
+ signal input currentResults[totalVoteOptions];
179
182
  // Salt for the root of the current results.
180
183
  signal input currentResultsRootSalt;
181
184
 
182
185
  // New results for each vote option.
183
- signal input newResults[numVoteOptions];
186
+ signal input newResults[totalVoteOptions];
184
187
  // Salt for the root of the new results.
185
188
  signal input newResultsRootSalt;
186
189
 
@@ -211,11 +214,11 @@ template TallyVotesNonQv(
211
214
  // computedIsZero.out is 0 if this is the first batch.
212
215
  var computedIsZero = IsZero()(isFirstBatch);
213
216
 
214
- // hz is 0 if this is the first batch, currentTallyCommitment should be 0 if this is the first batch.
215
- // hz is 1 if this is not the first batch, currentTallyCommitment should not be 0 if this is the first batch.
216
- signal hz;
217
- hz <== computedIsZero * computedCurrentTallyCommitment;
218
- hz === currentTallyCommitment;
217
+ // isFirstCommitment is 0 if this is the first batch, currentTallyCommitment should be 0 if this is the first batch.
218
+ // isFirstCommitment is 1 if this is not the first batch, currentTallyCommitment should not be 0 if this is the first batch.
219
+ signal isFirstCommitment;
220
+ isFirstCommitment <== computedIsZero * computedCurrentTallyCommitment;
221
+ isFirstCommitment === currentTallyCommitment;
219
222
 
220
223
  // Compute the root of the new results.
221
224
  var computedNewResultsRoot = QuinCheckRoot(voteOptionTreeDepth)(newResults);