@maci-protocol/circuits 0.0.0-ci.ffabe48 → 0.0.0-ci.ffb9e52

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.
@@ -0,0 +1,107 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // circomlib import
4
+ include "./comparators.circom";
5
+ // local imports
6
+ include "../trees/QuinaryCheckRoot.circom";
7
+ include "../PoseidonHasher.circom";
8
+
9
+ /**
10
+ * Performs verifications and computations related to current voting results.
11
+ * Also, computes and outputs a commitment to the new results.
12
+ * This template supports the Quadratic Voting (QV).
13
+ */
14
+ template ResultCommitmentVerifierQv(voteOptionTreeDepth) {
15
+ // Number of children per node in the tree, defining the tree's branching factor.
16
+ var TREE_ARITY = 5;
17
+ // Number of voting options available, determined by the depth of the vote option tree.
18
+ var totalVoteOptions = TREE_ARITY ** voteOptionTreeDepth;
19
+
20
+ // Equal to 1 if this is the first batch, otherwise 0.
21
+ signal input isFirstBatch;
22
+ // Commitment to the current tally before this batch.
23
+ signal input currentTallyCommitment;
24
+ // Commitment to the new tally after processing this batch.
25
+ signal input newTallyCommitment;
26
+
27
+ // Current results for each vote option.
28
+ signal input currentResults[totalVoteOptions];
29
+ // Salt for the root of the current results.
30
+ signal input currentResultsRootSalt;
31
+
32
+ // New results for each vote option.
33
+ signal input newResults[totalVoteOptions];
34
+ // Salt for the root of the new results.
35
+ signal input newResultsRootSalt;
36
+
37
+ // Total voice credits spent so far.
38
+ signal input currentSpentVoiceCreditSubtotal;
39
+ // Salt for the total spent voice credits.
40
+ signal input currentSpentVoiceCreditSubtotalSalt;
41
+
42
+ // Total new voice credits spent.
43
+ signal input newSpentVoiceCreditSubtotal;
44
+ // Salt for the new total spent voice credits.
45
+ signal input newSpentVoiceCreditSubtotalSalt;
46
+
47
+ // Spent voice credits per vote option.
48
+ signal input currentPerVoteOptionSpentVoiceCredits[totalVoteOptions];
49
+ // Salt for the root of spent credits per option.
50
+ signal input currentPerVoteOptionSpentVoiceCreditsRootSalt;
51
+
52
+ // New spent voice credits per vote option.
53
+ signal input newPerVoteOptionSpentVoiceCredits[totalVoteOptions];
54
+ // Salt for the root of new spent credits per option.
55
+ signal input newPerVoteOptionSpentVoiceCreditsRootSalt;
56
+
57
+ // Compute the commitment to the current results.
58
+ var computedCurrentResultsRoot = QuinaryCheckRoot(voteOptionTreeDepth)(currentResults);
59
+
60
+ // Verify currentResultsCommitmentHash.
61
+ var computedCurrentResultsCommitment = PoseidonHasher(2)([computedCurrentResultsRoot, currentResultsRootSalt]);
62
+
63
+ // Compute the commitment to the current spent voice credits.
64
+ var computedCurrentSpentVoiceCreditsCommitment = PoseidonHasher(2)([currentSpentVoiceCreditSubtotal, currentSpentVoiceCreditSubtotalSalt]);
65
+
66
+ // Compute the root of the spent voice credits per vote option.
67
+ var computedCurrentPerVoteOptionSpentVoiceCreditsRoot = QuinaryCheckRoot(voteOptionTreeDepth)(currentPerVoteOptionSpentVoiceCredits);
68
+ var computedCurrentPerVoteOptionSpentVoiceCreditsCommitment = PoseidonHasher(2)([computedCurrentPerVoteOptionSpentVoiceCreditsRoot, currentPerVoteOptionSpentVoiceCreditsRootSalt]);
69
+
70
+ // Commit to the current tally.
71
+ var computedCurrentTallyCommitment = PoseidonHasher(3)([
72
+ computedCurrentResultsCommitment,
73
+ computedCurrentSpentVoiceCreditsCommitment,
74
+ computedCurrentPerVoteOptionSpentVoiceCreditsCommitment
75
+ ]);
76
+
77
+ // Check if the current tally commitment is correct only if this is not the first batch.
78
+ // computedIsZero.out is 1 if this is not the first batch.
79
+ // computedIsZero.out is 0 if this is the first batch.
80
+ var computedIsZero = IsZero()(isFirstBatch);
81
+
82
+ // isFirstCommitment is 0 if this is the first batch, currentTallyCommitment should be 0 if this is the first batch.
83
+ // isFirstCommitment is 1 if this is not the first batch, currentTallyCommitment should not be 0 if this is the first batch.
84
+ signal isFirstCommitment;
85
+ isFirstCommitment <== computedIsZero * computedCurrentTallyCommitment;
86
+ isFirstCommitment === currentTallyCommitment;
87
+
88
+ // Compute the root of the new results.
89
+ var computedNewResultsRoot = QuinaryCheckRoot(voteOptionTreeDepth)(newResults);
90
+ var computedNewResultsCommitment = PoseidonHasher(2)([computedNewResultsRoot, newResultsRootSalt]);
91
+
92
+ // Compute the commitment to the new spent voice credits value.
93
+ var computedNewSpentVoiceCreditsCommitment = PoseidonHasher(2)([newSpentVoiceCreditSubtotal, newSpentVoiceCreditSubtotalSalt]);
94
+
95
+ // Compute the root of the spent voice credits per vote option.
96
+ var computedNewPerVoteOptionSpentVoiceCreditsRoot = QuinaryCheckRoot(voteOptionTreeDepth)(newPerVoteOptionSpentVoiceCredits);
97
+ var computedNewPerVoteOptionSpentVoiceCreditsCommitment = PoseidonHasher(2)([computedNewPerVoteOptionSpentVoiceCreditsRoot, newPerVoteOptionSpentVoiceCreditsRootSalt]);
98
+
99
+ // Commit to the new tally.
100
+ var computedNewTallyCommitment = PoseidonHasher(3)([
101
+ computedNewResultsCommitment,
102
+ computedNewSpentVoiceCreditsCommitment,
103
+ computedNewPerVoteOptionSpentVoiceCreditsCommitment
104
+ ]);
105
+
106
+ computedNewTallyCommitment === newTallyCommitment;
107
+ }
@@ -7,7 +7,7 @@ include "./comparators.circom";
7
7
  include "../PoseidonHasher.circom";
8
8
 
9
9
  // @note taken from @zk-kit/circuits
10
- // if used directly in processMessages circom complains about duplicated
10
+ // if used directly in MessageProcessor circom complains about duplicated
11
11
  // templates (Ark, Poseidon, etc.)
12
12
  // This circuit is designed to calculate the root of a binary Merkle
13
13
  // tree given a leaf, its depth, and the necessary sibling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maci-protocol/circuits",
3
- "version": "0.0.0-ci.ffabe48",
3
+ "version": "0.0.0-ci.ffb9e52",
4
4
  "private": false,
5
5
  "description": "zk-SNARK circuits for MACI",
6
6
  "main": "build/ts/index.js",
@@ -38,37 +38,37 @@
38
38
  "test:verifySignature": "pnpm run mocha-test ts/__tests__/VerifySignature.test.ts",
39
39
  "test:privateToPublicKey": "pnpm run mocha-test ts/__tests__/PrivateToPublicKey.test.ts",
40
40
  "test:calculateTotal": "pnpm run mocha-test ts/__tests__/CalculateTotal.test.ts",
41
- "test:processMessages": "pnpm run mocha-test ts/__tests__/ProcessMessages.test.ts",
42
- "test:tallyVotes": "pnpm run mocha-test ts/__tests__/TallyVotes.test.ts",
41
+ "test:messageProcessor": "pnpm run mocha-test ts/__tests__/MessageProcessor.test.ts",
42
+ "test:voteTally": "pnpm run mocha-test ts/__tests__/VoteTally.test.ts",
43
43
  "test:ceremonyParams": "pnpm run mocha-test ts/__tests__/CeremonyParams.test.ts",
44
44
  "test:incrementalQuinaryTree": "pnpm run mocha-test ts/__tests__/IncrementalQuinaryTree.test.ts",
45
45
  "test:pollJoining": "pnpm run mocha-test ts/__tests__/PollJoining.test.ts",
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.ffabe48",
50
- "@maci-protocol/crypto": "0.0.0-ci.ffabe48",
51
- "@maci-protocol/domainobjs": "0.0.0-ci.ffabe48",
52
- "@maci-protocol/sdk": "0.0.0-ci.ffabe48",
49
+ "@maci-protocol/core": "0.0.0-ci.ffb9e52",
50
+ "@maci-protocol/crypto": "0.0.0-ci.ffb9e52",
51
+ "@maci-protocol/domainobjs": "0.0.0-ci.ffb9e52",
52
+ "@maci-protocol/sdk": "0.0.0-ci.ffb9e52",
53
53
  "@zk-kit/circuits": "^0.4.0",
54
- "circomkit": "^0.3.2",
54
+ "circomkit": "^0.3.3",
55
55
  "circomlib": "^2.0.5"
56
56
  },
57
57
  "devDependencies": {
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.17",
61
+ "@types/node": "^24.0.1",
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
- "glob": "^11.0.2",
68
- "mocha": "^11.2.2",
67
+ "glob": "^11.0.3",
68
+ "mocha": "^11.6.0",
69
69
  "ts-mocha": "^11.1.0",
70
70
  "ts-node": "^10.9.1",
71
71
  "typescript": "^5.8.3"
72
72
  },
73
- "gitHead": "69f75a97dbbb94cfd6daafb22ffd5a8cc1b993d3"
73
+ "gitHead": "9b90437759d0ba6f59731c3667be2a68954832b6"
74
74
  }