@maci-protocol/circuits 0.0.0-ci.c898917 → 0.0.0-ci.c910408
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.
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/circom/coordinator/full/MessageProcessor.circom +9 -9
- package/circom/coordinator/non-qv/processMessages.circom +9 -9
- package/circom/coordinator/non-qv/tallyVotes.circom +14 -14
- package/circom/coordinator/qv/processMessages.circom +9 -9
- package/circom/coordinator/qv/tallyVotes.circom +9 -9
- package/circom/utils/CalculateTotal.circom +6 -6
- package/package.json +7 -7
|
@@ -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
|
|
206
|
-
var
|
|
207
|
-
var
|
|
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];
|
|
208
208
|
|
|
209
209
|
for (var j = 0; j < stateTreeDepth; j++) {
|
|
210
210
|
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
currentStateLeavesPathElement[j][k] = currentStateLeavesPathElements[i][j][k];
|
|
212
|
+
currentBallotPathElement[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
|
-
|
|
218
|
+
currentVoteWeightsPathElement[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
|
-
|
|
228
|
+
currentStateLeavesPathElement,
|
|
229
229
|
currentBallots[i],
|
|
230
|
-
|
|
230
|
+
currentBallotPathElement,
|
|
231
231
|
currentVoteWeights[i],
|
|
232
|
-
|
|
232
|
+
currentVoteWeightsPathElement,
|
|
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
|
|
213
|
-
var
|
|
214
|
-
var
|
|
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];
|
|
215
215
|
|
|
216
216
|
for (var j = 0; j < stateTreeDepth; j++) {
|
|
217
217
|
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
currentStateLeavesPathElement[j][k] = currentStateLeavesPathElements[i][j][k];
|
|
219
|
+
currentBallotPathElement[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
|
-
|
|
225
|
+
currentVoteWeightsPathElement[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
|
-
|
|
235
|
+
currentStateLeavesPathElement,
|
|
236
236
|
currentBallots[i],
|
|
237
|
-
|
|
237
|
+
currentBallotPathElement,
|
|
238
238
|
currentVoteWeights[i],
|
|
239
|
-
|
|
239
|
+
currentVoteWeightsPathElement,
|
|
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
|
-
|
|
21
|
+
intStateTreeDepth,
|
|
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(
|
|
27
|
+
assert(intStateTreeDepth > 0);
|
|
28
28
|
// The intermediate state tree must be smaller than the full state tree.
|
|
29
|
-
assert(
|
|
29
|
+
assert(intStateTreeDepth < 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 **
|
|
36
|
+
var batchSize = BALLOT_TREE_ARITY ** intStateTreeDepth;
|
|
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
|
|
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;
|
|
@@ -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[
|
|
67
|
+
signal input ballotPathElements[STATE_INT_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(
|
|
99
|
-
var computedBallotPathIndices[
|
|
98
|
+
var computedBallotSubroot = CheckRoot(intStateTreeDepth)(computedBallotHashers);
|
|
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(
|
|
102
|
+
LeafExists(STATE_INT_TREE_DEPTH_DIFFERENCE)(
|
|
103
103
|
computedBallotSubroot,
|
|
104
104
|
ballotPathElements,
|
|
105
105
|
computedBallotPathIndices,
|
|
@@ -122,14 +122,13 @@ template TallyVotesNonQv(
|
|
|
122
122
|
var computedCalculateTotalResult[totalVoteOptions];
|
|
123
123
|
|
|
124
124
|
for (var i = 0; i < totalVoteOptions; i++) {
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
var computedNumsRC[batchSize + 1];
|
|
126
|
+
computedNumsRC[batchSize] = currentResults[i] * computedIsZero;
|
|
128
127
|
for (var j = 0; j < batchSize; j++) {
|
|
129
|
-
|
|
128
|
+
computedNumsRC[j] = votes[j][i];
|
|
130
129
|
}
|
|
131
130
|
|
|
132
|
-
computedCalculateTotalResult[i] = CalculateTotal(batchSize + 1)(
|
|
131
|
+
computedCalculateTotalResult[i] = CalculateTotal(batchSize + 1)(computedNumsRC);
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
// Tally the new spent voice credit total.
|
|
@@ -236,3 +235,4 @@ template TallyVotesNonQv(
|
|
|
236
235
|
|
|
237
236
|
computedNewTallyCommitment === newTallyCommitment;
|
|
238
237
|
}
|
|
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
|
|
210
|
-
var
|
|
211
|
-
var
|
|
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];
|
|
212
212
|
|
|
213
213
|
for (var j = 0; j < stateTreeDepth; j++) {
|
|
214
214
|
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
currentStateLeavesPathElement[j][k] = currentStateLeavesPathElements[i][j][k];
|
|
216
|
+
currentBallotPathElement[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
|
-
|
|
222
|
+
currentVoteWeightsPathElement[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
|
-
|
|
232
|
+
currentStateLeavesPathElement,
|
|
233
233
|
currentBallots[i],
|
|
234
|
-
|
|
234
|
+
currentBallotPathElement,
|
|
235
235
|
currentVoteWeights[i],
|
|
236
|
-
|
|
236
|
+
currentVoteWeightsPathElement,
|
|
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
|
-
|
|
21
|
+
intStateTreeDepth,
|
|
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(
|
|
27
|
+
assert(intStateTreeDepth > 0);
|
|
28
28
|
// The intermediate state tree must be smaller than the full state tree.
|
|
29
|
-
assert(
|
|
29
|
+
assert(intStateTreeDepth < 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 **
|
|
36
|
+
var batchSize = BALLOT_TREE_ARITY ** intStateTreeDepth;
|
|
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
|
|
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;
|
|
@@ -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[
|
|
67
|
+
signal input ballotPathElements[STATE_INT_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(
|
|
104
|
-
var computedBallotPathIndices[
|
|
103
|
+
var computedBallotSubroot = CheckRoot(intStateTreeDepth)(computedBallotHashers);
|
|
104
|
+
var computedBallotPathIndices[STATE_INT_TREE_DEPTH_DIFFERENCE] = MerklePathIndicesGenerator(STATE_INT_TREE_DEPTH_DIFFERENCE)(index / batchSize);
|
|
105
105
|
|
|
106
106
|
// Verifies each ballot's existence within the ballot tree.
|
|
107
|
-
LeafExists(
|
|
107
|
+
LeafExists(STATE_INT_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
|
|
4
|
+
* Computes the cumulative sum of an array of n 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(
|
|
10
|
+
template CalculateTotal(n) {
|
|
11
11
|
// Array of values.
|
|
12
|
-
signal input nums[
|
|
12
|
+
signal input nums[n];
|
|
13
13
|
// Total sum.
|
|
14
14
|
signal output sum;
|
|
15
15
|
|
|
16
|
-
signal sums[
|
|
16
|
+
signal sums[n];
|
|
17
17
|
sums[0] <== nums[0];
|
|
18
18
|
|
|
19
|
-
for (var i = 1; i <
|
|
19
|
+
for (var i = 1; i < n; i++) {
|
|
20
20
|
sums[i] <== sums[i - 1] + nums[i];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
sum <== sums[
|
|
23
|
+
sum <== sums[n - 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.
|
|
3
|
+
"version": "0.0.0-ci.c910408",
|
|
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.
|
|
50
|
-
"@maci-protocol/crypto": "0.0.0-ci.
|
|
51
|
-
"@maci-protocol/domainobjs": "0.0.0-ci.
|
|
52
|
-
"@maci-protocol/sdk": "0.0.0-ci.
|
|
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",
|
|
53
53
|
"@zk-kit/circuits": "^0.4.0",
|
|
54
54
|
"circomkit": "^0.3.2",
|
|
55
55
|
"circomlib": "^2.0.5"
|
|
@@ -65,10 +65,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.
|
|
68
|
+
"mocha": "^11.1.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": "
|
|
73
|
+
"gitHead": "813dec205168adc09564e15a7d75244dc283ec7f"
|
|
74
74
|
}
|