@maci-protocol/circuits 0.0.0-ci.2a2b6ab → 0.0.0-ci.2cf83db

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.
@@ -11,9 +11,9 @@
11
11
  "params": [10],
12
12
  "pubs": ["stateRoot"]
13
13
  },
14
- "ProcessMessages_10-20-2_test": {
15
- "file": "./coordinator/qv/processMessages",
16
- "template": "ProcessMessages",
14
+ "MessageProcessorQv_10-20-2_test": {
15
+ "file": "./coordinator/qv/MessageProcessor",
16
+ "template": "MessageProcessorQv",
17
17
  "params": [10, 20, 2],
18
18
  "pubs": [
19
19
  "totalSignups",
@@ -27,9 +27,9 @@
27
27
  "voteOptions"
28
28
  ]
29
29
  },
30
- "ProcessMessagesNonQv_10-20-2_test": {
31
- "file": "./coordinator/non-qv/processMessages",
32
- "template": "ProcessMessagesNonQv",
30
+ "MessageProcessorNonQv_10-20-2_test": {
31
+ "file": "./coordinator/non-qv/MessageProcessor",
32
+ "template": "MessageProcessorNonQv",
33
33
  "params": [10, 20, 2],
34
34
  "pubs": [
35
35
  "totalSignups",
@@ -59,15 +59,15 @@
59
59
  "voteOptions"
60
60
  ]
61
61
  },
62
- "TallyVotes_10-1-2_test": {
63
- "file": "./coordinator/qv/tallyVotes",
64
- "template": "TallyVotes",
62
+ "VoteTallyQv_10-1-2_test": {
63
+ "file": "./coordinator/qv/VoteTally",
64
+ "template": "VoteTallyQv",
65
65
  "params": [10, 1, 2],
66
66
  "pubs": ["index", "totalSignups", "sbCommitment", "currentTallyCommitment", "newTallyCommitment"]
67
67
  },
68
- "TallyVotesNonQv_10-1-2_test": {
69
- "file": "./coordinator/non-qv/tallyVotes",
70
- "template": "TallyVotesNonQv",
68
+ "VoteTallyNonQv_10-1-2_test": {
69
+ "file": "./coordinator/non-qv/VoteTally",
70
+ "template": "VoteTallyNonQv",
71
71
  "params": [10, 1, 2],
72
72
  "pubs": ["index", "totalSignups", "sbCommitment", "currentTallyCommitment", "newTallyCommitment"]
73
73
  }
@@ -9,20 +9,13 @@ 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";
13
- include "../../utils/trees/MerkleTreeInclusionProof.circom";
14
- include "../../utils/trees/LeafExists.circom";
15
- include "../../utils/trees/CheckRoot.circom";
16
- include "../../utils/trees/MerklePathIndicesGenerator.circom";
17
- include "../../utils/trees/BinaryMerkleRoot.circom";
18
- include "../../utils/trees/QuinaryTreeInclusionProof.circom";
19
- include "../../utils/trees/QuinaryGeneratePathIndices.circom";
12
+ include "./SingleMessageProcessor.circom";
20
13
 
21
14
  /**
22
15
  * Proves the correctness of processing a batch of MACI messages.
23
16
  * This template does not support Quadratic Voting (QV).
24
17
  */
25
- template ProcessMessagesNonQv(
18
+ template MessageProcessorNonQv(
26
19
  stateTreeDepth,
27
20
  batchSize,
28
21
  voteOptionTreeDepth
@@ -226,7 +219,7 @@ include "../../utils/trees/QuinaryGeneratePathIndices.circom";
226
219
  }
227
220
  }
228
221
 
229
- (computedNewVoteStateRoot[i], computedNewVoteBallotRoot[i]) = ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth)(
222
+ (computedNewVoteStateRoot[i], computedNewVoteBallotRoot[i]) = SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth)(
230
223
  totalSignups,
231
224
  stateRoots[i + 1],
232
225
  ballotRoots[i + 1],
@@ -257,191 +250,3 @@ include "../../utils/trees/QuinaryGeneratePathIndices.circom";
257
250
  var computedNewSbCommitment = PoseidonHasher(3)([stateRoots[0], ballotRoots[0], newSbSalt]);
258
251
  computedNewSbCommitment === newSbCommitment;
259
252
  }
260
-
261
- /**
262
- * Processes one message and updates the state accordingly.
263
- * This template involves complex interactions, including transformations based on message type,
264
- * validations against current states like voice credit balances or vote weights,
265
- * and updates to Merkle trees representing state and ballot information.
266
- * This is a critical building block for ensuring the integrity and correctness of MACI state.
267
- * This template does not support Quadratic Voting (QV).
268
- */
269
- template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
270
- // Constants defining the structure and size of state and ballots.
271
- var STATE_LEAF_LENGTH = 3;
272
- var BALLOT_LENGTH = 2;
273
- var MESSAGE_LENGTH = 10;
274
- var PACKED_COMMAND_LENGTH = 4;
275
- var VOTE_OPTION_TREE_ARITY = 5;
276
- var STATE_TREE_ARITY = 2;
277
- var BALLOT_NONCE_INDEX = 0;
278
- // Ballot vote option (vote option) root index.
279
- var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
280
-
281
- // Indices for elements within a state leaf.
282
- // Public key.
283
- var STATE_LEAF_PUBLIC_X_INDEX = 0;
284
- var STATE_LEAF_PUBLIC_Y_INDEX = 1;
285
- // Voice Credit balance.
286
- var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
287
- var NUMBER_BITS = 252;
288
-
289
- // Number of users that have completed the sign up.
290
- signal input totalSignups;
291
- // The current value of the state tree root.
292
- signal input currentStateRoot;
293
- // The current value of the ballot tree root.
294
- signal input currentBallotRoot;
295
- // The actual tree depth (might be <= stateTreeDepth).
296
- signal input actualStateTreeDepth;
297
-
298
- // The state leaf and related path elements.
299
- signal input stateLeaf[STATE_LEAF_LENGTH];
300
- // Sibling nodes at each level of the state tree to verify the specific state leaf.
301
- signal input stateLeafPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
302
-
303
- // The ballot and related path elements.
304
- signal input ballot[BALLOT_LENGTH];
305
- signal input ballotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
306
-
307
- // The current vote weight and related path elements.
308
- signal input currentVoteWeight;
309
- signal input currentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
310
-
311
- // Inputs related to the command being processed.
312
- signal input commandStateIndex;
313
- signal input commandPublicKey[2];
314
- signal input commandVoteOptionIndex;
315
- signal input commandNewVoteWeight;
316
- signal input commandNonce;
317
- signal input commandPollId;
318
- signal input commandSalt;
319
- signal input commandSignaturePoint[2];
320
- signal input commandSignatureScalar;
321
- signal input packedCommand[PACKED_COMMAND_LENGTH];
322
-
323
- // The number of valid vote options for the poll.
324
- signal input voteOptions;
325
-
326
- signal output newStateRoot;
327
- signal output newBallotRoot;
328
-
329
- // equal to newBallotVoteOptionRootMux (Mux1).
330
- signal newBallotVoteOptionRoot;
331
-
332
- // 1. Transform a state leaf and a ballot with a command.
333
- // The result is a new state leaf, a new ballot, and an isValid signal (0 or 1).
334
- var computedNewStateLeafPublicKey[2], computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid;
335
- (computedNewStateLeafPublicKey, computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = StateLeafAndBallotTransformerNonQv()(
336
- totalSignups,
337
- voteOptions,
338
- [stateLeaf[STATE_LEAF_PUBLIC_X_INDEX], stateLeaf[STATE_LEAF_PUBLIC_Y_INDEX]],
339
- stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX],
340
- ballot[BALLOT_NONCE_INDEX],
341
- currentVoteWeight,
342
- commandStateIndex,
343
- commandPublicKey,
344
- commandVoteOptionIndex,
345
- commandNewVoteWeight,
346
- commandNonce,
347
- commandPollId,
348
- commandSalt,
349
- commandSignaturePoint,
350
- commandSignatureScalar,
351
- packedCommand
352
- );
353
-
354
- // 2. If computedIsStateLeafIndexValid is equal to zero, generate indices for leaf zero.
355
- // Otherwise, generate indices for command.stateIndex.
356
- var stateIndexMux = Mux1()([0, commandStateIndex], computedIsStateLeafIndexValid);
357
- var computedStateLeafPathIndices[stateTreeDepth] = MerklePathIndicesGenerator(stateTreeDepth)(stateIndexMux);
358
-
359
- // 3. Verify that the original state leaf exists in the given state root.
360
- var stateLeafHash = PoseidonHasher(3)(stateLeaf);
361
- var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
362
- stateLeafHash,
363
- actualStateTreeDepth,
364
- computedStateLeafPathIndices,
365
- stateLeafPathElements
366
- );
367
-
368
- stateLeafQip === currentStateRoot;
369
-
370
- // 4. Verify that the original ballot exists in the given ballot root.
371
- var computedBallot = PoseidonHasher(2)([
372
- ballot[BALLOT_NONCE_INDEX],
373
- ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
374
- ]);
375
-
376
- var computedBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
377
- computedBallot,
378
- computedStateLeafPathIndices,
379
- ballotPathElements
380
- );
381
-
382
- computedBallotQip === currentBallotRoot;
383
-
384
- // 5. Verify that currentVoteWeight exists in the ballot's vote option root
385
- // at commandVoteOptionIndex.
386
- var commandVoteOptionIndexMux = Mux1()([0, commandVoteOptionIndex], computedIsVoteOptionIndexValid);
387
- var computedCurrentVoteWeightPathIndices[voteOptionTreeDepth] = QuinaryGeneratePathIndices(voteOptionTreeDepth)(commandVoteOptionIndexMux);
388
-
389
- var computedCurrentVoteWeightQip = QuinaryTreeInclusionProof(voteOptionTreeDepth)(
390
- currentVoteWeight,
391
- computedCurrentVoteWeightPathIndices,
392
- currentVoteWeightsPathElements
393
- );
394
-
395
- computedCurrentVoteWeightQip === ballot[BALLOT_VOTE_OPTION_ROOT_INDEX];
396
-
397
- var voteWeightMux = Mux1()([currentVoteWeight, commandNewVoteWeight], computedIsValid);
398
- var voiceCreditBalanceMux = Mux1()(
399
- [
400
- stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX],
401
- stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX] + currentVoteWeight - commandNewVoteWeight
402
- ],
403
- computedIsValid
404
- );
405
-
406
- // 5.1. Update the ballot's vote option root with the new vote weight.
407
- var computedNewVoteOptionTreeQip = QuinaryTreeInclusionProof(voteOptionTreeDepth)(
408
- voteWeightMux,
409
- computedCurrentVoteWeightPathIndices,
410
- currentVoteWeightsPathElements
411
- );
412
-
413
- // The new vote option root in the ballot
414
- var newBallotVoteOptionRootMux = Mux1()(
415
- [ballot[BALLOT_VOTE_OPTION_ROOT_INDEX], computedNewVoteOptionTreeQip],
416
- computedIsValid
417
- );
418
-
419
- newBallotVoteOptionRoot <== newBallotVoteOptionRootMux;
420
-
421
- // 6. Generate a new state root.
422
- var computedNewStateLeafHash = PoseidonHasher(3)([
423
- computedNewStateLeafPublicKey[STATE_LEAF_PUBLIC_X_INDEX],
424
- computedNewStateLeafPublicKey[STATE_LEAF_PUBLIC_Y_INDEX],
425
- voiceCreditBalanceMux
426
- ]);
427
-
428
- var computedNewStateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
429
- computedNewStateLeafHash,
430
- actualStateTreeDepth,
431
- computedStateLeafPathIndices,
432
- stateLeafPathElements
433
- );
434
-
435
- newStateRoot <== computedNewStateLeafQip;
436
-
437
- // 7. Generate a new ballot root.
438
- var computedNewBallot = PoseidonHasher(2)([computedNewBallotNonce, newBallotVoteOptionRoot]);
439
- var computedNewBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
440
- computedNewBallot,
441
- computedStateLeafPathIndices,
442
- ballotPathElements
443
- );
444
-
445
- newBallotRoot <== computedNewBallotQip;
446
- }
447
-
@@ -0,0 +1,200 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // circomlib import
4
+ include "./mux1.circom";
5
+ // local imports
6
+ include "../../utils/PoseidonHasher.circom";
7
+ include "../../utils/trees/MerkleTreeInclusionProof.circom";
8
+ include "../../utils/trees/MerklePathIndicesGenerator.circom";
9
+ include "../../utils/trees/BinaryMerkleRoot.circom";
10
+ include "../../utils/trees/QuinaryTreeInclusionProof.circom";
11
+ include "../../utils/trees/QuinaryGeneratePathIndices.circom";
12
+ include "../../utils/non-qv/StateLeafAndBallotTransformer.circom";
13
+
14
+
15
+ /**
16
+ * Processes one message and updates the state accordingly.
17
+ * This template involves complex interactions, including transformations based on message type,
18
+ * validations against current states like voice credit balances or vote weights,
19
+ * and updates to Merkle trees representing state and ballot information.
20
+ * This is a critical building block for ensuring the integrity and correctness of MACI state.
21
+ * This template does not support Quadratic Voting (QV).
22
+ */
23
+ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
24
+ // Constants defining the structure and size of state and ballots.
25
+ var STATE_LEAF_LENGTH = 3;
26
+ var BALLOT_LENGTH = 2;
27
+ var MESSAGE_LENGTH = 10;
28
+ var PACKED_COMMAND_LENGTH = 4;
29
+ var VOTE_OPTION_TREE_ARITY = 5;
30
+ var STATE_TREE_ARITY = 2;
31
+ var BALLOT_NONCE_INDEX = 0;
32
+ // Ballot vote option (vote option) root index.
33
+ var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
34
+
35
+ // Indices for elements within a state leaf.
36
+ // Public key.
37
+ var STATE_LEAF_PUBLIC_X_INDEX = 0;
38
+ var STATE_LEAF_PUBLIC_Y_INDEX = 1;
39
+ // Voice Credit balance.
40
+ var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
41
+ var NUMBER_BITS = 252;
42
+
43
+ // Number of users that have completed the sign up.
44
+ signal input totalSignups;
45
+ // The current value of the state tree root.
46
+ signal input currentStateRoot;
47
+ // The current value of the ballot tree root.
48
+ signal input currentBallotRoot;
49
+ // The actual tree depth (might be <= stateTreeDepth).
50
+ signal input actualStateTreeDepth;
51
+
52
+ // The state leaf and related path elements.
53
+ signal input stateLeaf[STATE_LEAF_LENGTH];
54
+ // Sibling nodes at each level of the state tree to verify the specific state leaf.
55
+ signal input stateLeafPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
56
+
57
+ // The ballot and related path elements.
58
+ signal input ballot[BALLOT_LENGTH];
59
+ signal input ballotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
60
+
61
+ // The current vote weight and related path elements.
62
+ signal input currentVoteWeight;
63
+ signal input currentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
64
+
65
+ // Inputs related to the command being processed.
66
+ signal input commandStateIndex;
67
+ signal input commandPublicKey[2];
68
+ signal input commandVoteOptionIndex;
69
+ signal input commandNewVoteWeight;
70
+ signal input commandNonce;
71
+ signal input commandPollId;
72
+ signal input commandSalt;
73
+ signal input commandSignaturePoint[2];
74
+ signal input commandSignatureScalar;
75
+ signal input packedCommand[PACKED_COMMAND_LENGTH];
76
+
77
+ // The number of valid vote options for the poll.
78
+ signal input voteOptions;
79
+
80
+ signal output newStateRoot;
81
+ signal output newBallotRoot;
82
+
83
+ // equal to newBallotVoteOptionRootMux (Mux1).
84
+ signal newBallotVoteOptionRoot;
85
+
86
+ // 1. Transform a state leaf and a ballot with a command.
87
+ // The result is a new state leaf, a new ballot, and an isValid signal (0 or 1).
88
+ var computedNewStateLeafPublicKey[2], computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid;
89
+ (computedNewStateLeafPublicKey, computedNewBallotNonce, computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = StateLeafAndBallotTransformerNonQv()(
90
+ totalSignups,
91
+ voteOptions,
92
+ [stateLeaf[STATE_LEAF_PUBLIC_X_INDEX], stateLeaf[STATE_LEAF_PUBLIC_Y_INDEX]],
93
+ stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX],
94
+ ballot[BALLOT_NONCE_INDEX],
95
+ currentVoteWeight,
96
+ commandStateIndex,
97
+ commandPublicKey,
98
+ commandVoteOptionIndex,
99
+ commandNewVoteWeight,
100
+ commandNonce,
101
+ commandPollId,
102
+ commandSalt,
103
+ commandSignaturePoint,
104
+ commandSignatureScalar,
105
+ packedCommand
106
+ );
107
+
108
+ // 2. If computedIsStateLeafIndexValid is equal to zero, generate indices for leaf zero.
109
+ // Otherwise, generate indices for command.stateIndex.
110
+ var stateIndexMux = Mux1()([0, commandStateIndex], computedIsStateLeafIndexValid);
111
+ var computedStateLeafPathIndices[stateTreeDepth] = MerklePathIndicesGenerator(stateTreeDepth)(stateIndexMux);
112
+
113
+ // 3. Verify that the original state leaf exists in the given state root.
114
+ var stateLeafHash = PoseidonHasher(3)(stateLeaf);
115
+ var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
116
+ stateLeafHash,
117
+ actualStateTreeDepth,
118
+ computedStateLeafPathIndices,
119
+ stateLeafPathElements
120
+ );
121
+
122
+ stateLeafQip === currentStateRoot;
123
+
124
+ // 4. Verify that the original ballot exists in the given ballot root.
125
+ var computedBallot = PoseidonHasher(2)([
126
+ ballot[BALLOT_NONCE_INDEX],
127
+ ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
128
+ ]);
129
+
130
+ var computedBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
131
+ computedBallot,
132
+ computedStateLeafPathIndices,
133
+ ballotPathElements
134
+ );
135
+
136
+ computedBallotQip === currentBallotRoot;
137
+
138
+ // 5. Verify that currentVoteWeight exists in the ballot's vote option root
139
+ // at commandVoteOptionIndex.
140
+ var commandVoteOptionIndexMux = Mux1()([0, commandVoteOptionIndex], computedIsVoteOptionIndexValid);
141
+ var computedCurrentVoteWeightPathIndices[voteOptionTreeDepth] = QuinaryGeneratePathIndices(voteOptionTreeDepth)(commandVoteOptionIndexMux);
142
+
143
+ var computedCurrentVoteWeightQip = QuinaryTreeInclusionProof(voteOptionTreeDepth)(
144
+ currentVoteWeight,
145
+ computedCurrentVoteWeightPathIndices,
146
+ currentVoteWeightsPathElements
147
+ );
148
+
149
+ computedCurrentVoteWeightQip === ballot[BALLOT_VOTE_OPTION_ROOT_INDEX];
150
+
151
+ var voteWeightMux = Mux1()([currentVoteWeight, commandNewVoteWeight], computedIsValid);
152
+ var voiceCreditBalanceMux = Mux1()(
153
+ [
154
+ stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX],
155
+ stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX] + currentVoteWeight - commandNewVoteWeight
156
+ ],
157
+ computedIsValid
158
+ );
159
+
160
+ // 5.1. Update the ballot's vote option root with the new vote weight.
161
+ var computedNewVoteOptionTreeQip = QuinaryTreeInclusionProof(voteOptionTreeDepth)(
162
+ voteWeightMux,
163
+ computedCurrentVoteWeightPathIndices,
164
+ currentVoteWeightsPathElements
165
+ );
166
+
167
+ // The new vote option root in the ballot
168
+ var newBallotVoteOptionRootMux = Mux1()(
169
+ [ballot[BALLOT_VOTE_OPTION_ROOT_INDEX], computedNewVoteOptionTreeQip],
170
+ computedIsValid
171
+ );
172
+
173
+ newBallotVoteOptionRoot <== newBallotVoteOptionRootMux;
174
+
175
+ // 6. Generate a new state root.
176
+ var computedNewStateLeafHash = PoseidonHasher(3)([
177
+ computedNewStateLeafPublicKey[STATE_LEAF_PUBLIC_X_INDEX],
178
+ computedNewStateLeafPublicKey[STATE_LEAF_PUBLIC_Y_INDEX],
179
+ voiceCreditBalanceMux
180
+ ]);
181
+
182
+ var computedNewStateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
183
+ computedNewStateLeafHash,
184
+ actualStateTreeDepth,
185
+ computedStateLeafPathIndices,
186
+ stateLeafPathElements
187
+ );
188
+
189
+ newStateRoot <== computedNewStateLeafQip;
190
+
191
+ // 7. Generate a new ballot root.
192
+ var computedNewBallot = PoseidonHasher(2)([computedNewBallotNonce, newBallotVoteOptionRoot]);
193
+ var computedNewBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
194
+ computedNewBallot,
195
+ computedStateLeafPathIndices,
196
+ ballotPathElements
197
+ );
198
+
199
+ newBallotRoot <== computedNewBallotQip;
200
+ }
@@ -5,6 +5,7 @@ include "./comparators.circom";
5
5
  // zk-kit import
6
6
  include "./unpack-element.circom";
7
7
  // local imports
8
+ include "../../utils/non-qv/ResultCommitmentVerifier.circom";
8
9
  include "../../utils/trees/CheckRoot.circom";
9
10
  include "../../utils/trees/MerklePathIndicesGenerator.circom";
10
11
  include "../../utils/trees/LeafExists.circom";
@@ -16,7 +17,7 @@ include "../../utils/PoseidonHasher.circom";
16
17
  * Processes batches of votes and verifies their validity in a Merkle tree structure.
17
18
  * This template does not support Quadratic Voting (QV).
18
19
  */
19
- template TallyVotesNonQv(
20
+ template VoteTallyNonQv(
20
21
  stateTreeDepth,
21
22
  tallyProcessingStateTreeDepth,
22
23
  voteOptionTreeDepth
@@ -159,80 +160,3 @@ template TallyVotesNonQv(
159
160
  newSpentVoiceCreditSubtotalSalt
160
161
  );
161
162
  }
162
-
163
- /**
164
- * Performs verifications and computations related to current voting results.
165
- * Also, computes and outputs a commitment to the new results.
166
- * This template does not support Quadratic Voting (QV).
167
- */
168
- template ResultCommitmentVerifierNonQv(voteOptionTreeDepth) {
169
- // Number of children per node in the tree, defining the tree's branching factor.
170
- var TREE_ARITY = 5;
171
- // Number of voting options available, determined by the depth of the vote option tree.
172
- var totalVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
173
-
174
- // Equal to 1 if this is the first batch, otherwise 0.
175
- signal input isFirstBatch;
176
- // Commitment to the current tally before this batch.
177
- signal input currentTallyCommitment;
178
- // Commitment to the new tally after processing this batch.
179
- signal input newTallyCommitment;
180
-
181
- // Current results for each vote option.
182
- signal input currentResults[totalVoteOptions];
183
- // Salt for the root of the current results.
184
- signal input currentResultsRootSalt;
185
-
186
- // New results for each vote option.
187
- signal input newResults[totalVoteOptions];
188
- // Salt for the root of the new results.
189
- signal input newResultsRootSalt;
190
-
191
- // Total voice credits spent so far.
192
- signal input currentSpentVoiceCreditSubtotal;
193
- // Salt for the total spent voice credits.
194
- signal input currentSpentVoiceCreditSubtotalSalt;
195
-
196
- // Total new voice credits spent.
197
- signal input newSpentVoiceCreditSubtotal;
198
- // Salt for the new total spent voice credits.
199
- signal input newSpentVoiceCreditSubtotalSalt;
200
-
201
- // Compute the commitment to the current results.
202
- var computedCurrentResultsRoot = QuinaryCheckRoot(voteOptionTreeDepth)(currentResults);
203
-
204
- // Verify currentResultsCommitmentHash.
205
- var computedCurrentResultsCommitment = PoseidonHasher(2)([computedCurrentResultsRoot, currentResultsRootSalt]);
206
-
207
- // Compute the commitment to the current spent voice credits.
208
- var computedCurrentSpentVoiceCreditsCommitment = PoseidonHasher(2)([currentSpentVoiceCreditSubtotal, currentSpentVoiceCreditSubtotalSalt]);
209
-
210
- // Commit to the current tally
211
- var computedCurrentTallyCommitment = PoseidonHasher(2)([computedCurrentResultsCommitment, computedCurrentSpentVoiceCreditsCommitment]);
212
-
213
- // Check if the current tally commitment is correct only if this is not the first batch.
214
- // computedIsZero.out is 1 if this is not the first batch.
215
- // computedIsZero.out is 0 if this is the first batch.
216
- var computedIsZero = IsZero()(isFirstBatch);
217
-
218
- // isFirstCommitment is 0 if this is the first batch, currentTallyCommitment should be 0 if this is the first batch.
219
- // isFirstCommitment is 1 if this is not the first batch, currentTallyCommitment should not be 0 if this is the first batch.
220
- signal isFirstCommitment;
221
- isFirstCommitment <== computedIsZero * computedCurrentTallyCommitment;
222
- isFirstCommitment === currentTallyCommitment;
223
-
224
- // Compute the root of the new results.
225
- var computedNewResultsRoot = QuinaryCheckRoot(voteOptionTreeDepth)(newResults);
226
- var computedNewResultsCommitment = PoseidonHasher(2)([computedNewResultsRoot, newResultsRootSalt]);
227
-
228
- // Compute the commitment to the new spent voice credits value.
229
- var computedNewSpentVoiceCreditsCommitment = PoseidonHasher(2)([newSpentVoiceCreditSubtotal, newSpentVoiceCreditSubtotalSalt]);
230
-
231
- // Commit to the new tally.
232
- var computedNewTallyCommitment = PoseidonHasher(2)([
233
- computedNewResultsCommitment,
234
- computedNewSpentVoiceCreditsCommitment
235
- ]);
236
-
237
- computedNewTallyCommitment === newTallyCommitment;
238
- }