@maci-protocol/circuits 0.0.0-ci.9840a0f → 0.0.0-ci.991fa14
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 +5 -13
- package/circom/coordinator/non-qv/MessageProcessor.circom +5 -13
- package/circom/coordinator/non-qv/SingleMessageProcessor.circom +7 -9
- package/circom/coordinator/qv/MessageProcessor.circom +5 -13
- package/circom/coordinator/qv/SingleMessageProcessor.circom +7 -10
- package/circom/utils/EdDSAPoseidonVerifier.circom +8 -3
- package/circom/utils/IsOnCurve.circom +40 -0
- package/circom/utils/full/StateLeafAndBallotTransformer.circom +5 -0
- package/circom/utils/non-qv/StateLeafAndBallotTransformer.circom +5 -0
- package/circom/utils/qv/StateLeafAndBallotTransformer.circom +5 -0
- package/package.json +9 -8
|
@@ -33,14 +33,6 @@ include "./SingleMessageProcessor.circom";
|
|
|
33
33
|
var PACKED_COMMAND_LENGTH = 4;
|
|
34
34
|
var STATE_LEAF_LENGTH = 3;
|
|
35
35
|
var BALLOT_LENGTH = 2;
|
|
36
|
-
var BALLOT_NONCE_INDEX = 0;
|
|
37
|
-
var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
|
|
38
|
-
var STATE_LEAF_PUBLIC_X_INDEX = 0;
|
|
39
|
-
var STATE_LEAF_PUBLIC_Y_INDEX = 1;
|
|
40
|
-
var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
|
|
41
|
-
var MESSAGE_TREE_ZERO_VALUE = 8370432830353022751713833565135785980866757267633941821328460903436894336785;
|
|
42
|
-
// Number of options for this poll.
|
|
43
|
-
var maxVoteOptions = VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth;
|
|
44
36
|
|
|
45
37
|
// Number of users that have completed the sign up.
|
|
46
38
|
signal input totalSignups;
|
|
@@ -57,7 +49,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
57
49
|
// The current state root (before the processing).
|
|
58
50
|
signal input currentStateRoot;
|
|
59
51
|
// The actual tree depth (might be <= stateTreeDepth).
|
|
60
|
-
// @note it is a public input to ensure fair processing from
|
|
52
|
+
// @note it is a public input to ensure fair processing from
|
|
61
53
|
// the coordinator (no censoring)
|
|
62
54
|
signal input actualStateTreeDepth;
|
|
63
55
|
// The coordinator public key hash
|
|
@@ -97,7 +89,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
97
89
|
|
|
98
90
|
// The index of the first message in the batch, inclusive.
|
|
99
91
|
signal input index;
|
|
100
|
-
|
|
92
|
+
|
|
101
93
|
// The index of the last message in the batch to process, exclusive.
|
|
102
94
|
// This value may be less than index + batchSize if this batch is
|
|
103
95
|
// the last batch and the total number of messages is not a multiple of the batch size.
|
|
@@ -112,7 +104,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
112
104
|
var computedCurrentSbCommitment = PoseidonHasher(3)([currentStateRoot, currentBallotRoot, currentSbSalt]);
|
|
113
105
|
computedCurrentSbCommitment === currentSbCommitment;
|
|
114
106
|
|
|
115
|
-
// -----------------------------------------------------------------------
|
|
107
|
+
// -----------------------------------------------------------------------
|
|
116
108
|
// 0. Ensure that the maximum vote options signal is valid and if
|
|
117
109
|
// the maximum users signal is valid
|
|
118
110
|
var voteOptionsValid = LessEqThan(32)([voteOptions, VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth]);
|
|
@@ -162,7 +154,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
162
154
|
|
|
163
155
|
// Decrypt each Message into a Command.
|
|
164
156
|
// The command i-th is composed by the following fields.
|
|
165
|
-
// e.g., command 0 is made of commandsStateIndex[0],
|
|
157
|
+
// e.g., command 0 is made of commandsStateIndex[0],
|
|
166
158
|
// commandsNewPublicKey[0], ..., commandsPackedCommandOut[0]
|
|
167
159
|
var computedCommandsStateIndex[batchSize];
|
|
168
160
|
var computedCommandsNewPublicKey[batchSize][2];
|
|
@@ -205,7 +197,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
205
197
|
var computedCurrentStateLeavesPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
206
198
|
var computedCurrentBallotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
207
199
|
var computedCurrentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
|
|
208
|
-
|
|
200
|
+
|
|
209
201
|
for (var j = 0; j < stateTreeDepth; j++) {
|
|
210
202
|
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
|
|
211
203
|
computedCurrentStateLeavesPathElements[j][k] = currentStateLeavesPathElements[i][j][k];
|
|
@@ -33,14 +33,6 @@ include "./SingleMessageProcessor.circom";
|
|
|
33
33
|
var PACKED_COMMAND_LENGTH = 4;
|
|
34
34
|
var STATE_LEAF_LENGTH = 3;
|
|
35
35
|
var BALLOT_LENGTH = 2;
|
|
36
|
-
var BALLOT_NONCE_INDEX = 0;
|
|
37
|
-
var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
|
|
38
|
-
var STATE_LEAF_PUBLIC_X_INDEX = 0;
|
|
39
|
-
var STATE_LEAF_PUBLIC_Y_INDEX = 1;
|
|
40
|
-
var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
|
|
41
|
-
var MESSAGE_TREE_ZERO_VALUE = 8370432830353022751713833565135785980866757267633941821328460903436894336785;
|
|
42
|
-
// Number of options for this poll.
|
|
43
|
-
var maxVoteOptions = VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth;
|
|
44
36
|
|
|
45
37
|
// Number of users that have completed the sign up.
|
|
46
38
|
signal input totalSignups;
|
|
@@ -57,7 +49,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
57
49
|
// The current state root (before the processing).
|
|
58
50
|
signal input currentStateRoot;
|
|
59
51
|
// The actual tree depth (might be <= stateTreeDepth).
|
|
60
|
-
// @note it is a public input to ensure fair processing from
|
|
52
|
+
// @note it is a public input to ensure fair processing from
|
|
61
53
|
// the coordinator (no censoring)
|
|
62
54
|
signal input actualStateTreeDepth;
|
|
63
55
|
// The coordinator public key hash
|
|
@@ -97,7 +89,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
97
89
|
|
|
98
90
|
// The index of the first message in the batch, inclusive.
|
|
99
91
|
signal input index;
|
|
100
|
-
|
|
92
|
+
|
|
101
93
|
// The index of the last message in the batch to process, exclusive.
|
|
102
94
|
// This value may be less than index + batchSize if this batch is
|
|
103
95
|
// the last batch and the total number of messages is not a multiple of the batch size.
|
|
@@ -112,7 +104,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
112
104
|
var computedCurrentSbCommitment = PoseidonHasher(3)([currentStateRoot, currentBallotRoot, currentSbSalt]);
|
|
113
105
|
computedCurrentSbCommitment === currentSbCommitment;
|
|
114
106
|
|
|
115
|
-
// -----------------------------------------------------------------------
|
|
107
|
+
// -----------------------------------------------------------------------
|
|
116
108
|
// 0. Ensure that the maximum vote options signal is valid and if
|
|
117
109
|
// the maximum users signal is valid
|
|
118
110
|
var voteOptionsValid = LessEqThan(32)([voteOptions, VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth]);
|
|
@@ -162,7 +154,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
162
154
|
|
|
163
155
|
// Decrypt each Message into a Command.
|
|
164
156
|
// The command i-th is composed by the following fields.
|
|
165
|
-
// e.g., command 0 is made of commandsStateIndex[0],
|
|
157
|
+
// e.g., command 0 is made of commandsStateIndex[0],
|
|
166
158
|
// commandsNewPublicKey[0], ..., commandsPackedCommandOut[0]
|
|
167
159
|
var computedCommandsStateIndex[batchSize];
|
|
168
160
|
var computedCommandsNewPublicKey[batchSize][2];
|
|
@@ -205,7 +197,7 @@ include "./SingleMessageProcessor.circom";
|
|
|
205
197
|
var computedCurrentStateLeavesPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
206
198
|
var computedCurrentBallotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
207
199
|
var computedCurrentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
|
|
208
|
-
|
|
200
|
+
|
|
209
201
|
for (var j = 0; j < stateTreeDepth; j++) {
|
|
210
202
|
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
|
|
211
203
|
computedCurrentStateLeavesPathElements[j][k] = currentStateLeavesPathElements[i][j][k];
|
|
@@ -12,10 +12,10 @@ include "../../utils/non-qv/StateLeafAndBallotTransformer.circom";
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Processes one message and updates the state accordingly.
|
|
16
|
-
* This template involves complex interactions, including transformations based on message type,
|
|
17
|
-
* validations against current states like voice credit balances or vote weights,
|
|
18
|
-
* and updates to Merkle trees representing state and ballot information.
|
|
15
|
+
* Processes one message and updates the state accordingly.
|
|
16
|
+
* This template involves complex interactions, including transformations based on message type,
|
|
17
|
+
* validations against current states like voice credit balances or vote weights,
|
|
18
|
+
* and updates to Merkle trees representing state and ballot information.
|
|
19
19
|
* This is a critical building block for ensuring the integrity and correctness of MACI state.
|
|
20
20
|
* This template does not support Quadratic Voting (QV).
|
|
21
21
|
*/
|
|
@@ -23,7 +23,6 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
23
23
|
// Constants defining the structure and size of state and ballots.
|
|
24
24
|
var STATE_LEAF_LENGTH = 3;
|
|
25
25
|
var BALLOT_LENGTH = 2;
|
|
26
|
-
var MESSAGE_LENGTH = 10;
|
|
27
26
|
var PACKED_COMMAND_LENGTH = 4;
|
|
28
27
|
var VOTE_OPTION_TREE_ARITY = 5;
|
|
29
28
|
var STATE_TREE_ARITY = 2;
|
|
@@ -37,7 +36,6 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
37
36
|
var STATE_LEAF_PUBLIC_Y_INDEX = 1;
|
|
38
37
|
// Voice Credit balance.
|
|
39
38
|
var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
|
|
40
|
-
var NUMBER_BITS = 252;
|
|
41
39
|
|
|
42
40
|
// Number of users that have completed the sign up.
|
|
43
41
|
signal input totalSignups;
|
|
@@ -121,7 +119,7 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
121
119
|
|
|
122
120
|
// 4. Verify that the original ballot exists in the given ballot root.
|
|
123
121
|
var computedBallot = PoseidonHasher(2)([
|
|
124
|
-
ballot[BALLOT_NONCE_INDEX],
|
|
122
|
+
ballot[BALLOT_NONCE_INDEX],
|
|
125
123
|
ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
|
|
126
124
|
]);
|
|
127
125
|
var computedStateLeafPathIndices[stateTreeDepth] = Num2Bits(stateTreeDepth)(stateIndexMux);
|
|
@@ -186,8 +184,8 @@ template SingleMessageProcessorNonQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
186
184
|
);
|
|
187
185
|
|
|
188
186
|
newStateRoot <== computedNewStateLeafQip;
|
|
189
|
-
|
|
190
|
-
// 7. Generate a new ballot root.
|
|
187
|
+
|
|
188
|
+
// 7. Generate a new ballot root.
|
|
191
189
|
var computedNewBallot = PoseidonHasher(2)([computedNewBallotNonce, newBallotVoteOptionRoot]);
|
|
192
190
|
var computedNewBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
|
|
193
191
|
computedNewBallot,
|
|
@@ -34,14 +34,6 @@ template MessageProcessorQv(
|
|
|
34
34
|
var PACKED_COMMAND_LENGTH = 4;
|
|
35
35
|
var STATE_LEAF_LENGTH = 3;
|
|
36
36
|
var BALLOT_LENGTH = 2;
|
|
37
|
-
var BALLOT_NONCE_INDEX = 0;
|
|
38
|
-
var BALLOT_VOTE_OPTION_ROOT_INDEX = 1;
|
|
39
|
-
var STATE_LEAF_PUBLIC_X_INDEX = 0;
|
|
40
|
-
var STATE_LEAF_PUBLIC_Y_INDEX = 1;
|
|
41
|
-
var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
|
|
42
|
-
var MESSAGE_TREE_ZERO_VALUE = 8370432830353022751713833565135785980866757267633941821328460903436894336785;
|
|
43
|
-
// Number of options for this poll.
|
|
44
|
-
var maxVoteOptions = VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth;
|
|
45
37
|
|
|
46
38
|
// Number of users that have completed the sign up.
|
|
47
39
|
signal input totalSignups;
|
|
@@ -58,7 +50,7 @@ template MessageProcessorQv(
|
|
|
58
50
|
// The current state root (before the processing).
|
|
59
51
|
signal input currentStateRoot;
|
|
60
52
|
// The actual tree depth (might be <= stateTreeDepth).
|
|
61
|
-
// @note it is a public input to ensure fair processing from
|
|
53
|
+
// @note it is a public input to ensure fair processing from
|
|
62
54
|
// the coordinator (no censoring)
|
|
63
55
|
signal input actualStateTreeDepth;
|
|
64
56
|
// The coordinator public key hash
|
|
@@ -98,7 +90,7 @@ template MessageProcessorQv(
|
|
|
98
90
|
|
|
99
91
|
// The index of the first message in the batch, inclusive.
|
|
100
92
|
signal input index;
|
|
101
|
-
|
|
93
|
+
|
|
102
94
|
// The index of the last message in the batch to process, exclusive.
|
|
103
95
|
// This value may be less than batchSize if this batch is
|
|
104
96
|
// the last batch and the total number of messages is not a multiple of the batch size.
|
|
@@ -160,7 +152,7 @@ template MessageProcessorQv(
|
|
|
160
152
|
|
|
161
153
|
// Decrypt each Message into a Command.
|
|
162
154
|
// The command i-th is composed by the following fields.
|
|
163
|
-
// e.g., command 0 is made of commandsStateIndex[0],
|
|
155
|
+
// e.g., command 0 is made of commandsStateIndex[0],
|
|
164
156
|
// commandsNewPublicKey[0], ..., commandsPackedCommandOut[0]
|
|
165
157
|
var computedCommandsStateIndex[batchSize];
|
|
166
158
|
var computedCommandsNewPublicKey[batchSize][2];
|
|
@@ -203,7 +195,7 @@ template MessageProcessorQv(
|
|
|
203
195
|
var computedCurrentStateLeavesPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
204
196
|
var computedCurrentBallotPathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
205
197
|
var computedCurrentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];
|
|
206
|
-
|
|
198
|
+
|
|
207
199
|
for (var j = 0; j < stateTreeDepth; j++) {
|
|
208
200
|
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
|
|
209
201
|
computedCurrentStateLeavesPathElements[j][k] = currentStateLeavesPathElements[i][j][k];
|
|
@@ -216,7 +208,7 @@ template MessageProcessorQv(
|
|
|
216
208
|
computedCurrentVoteWeightsPathElements[j][k] = currentVoteWeightsPathElements[i][j][k];
|
|
217
209
|
}
|
|
218
210
|
}
|
|
219
|
-
|
|
211
|
+
|
|
220
212
|
(computedNewVoteStateRoot[i], computedNewVoteBallotRoot[i]) = SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth)(
|
|
221
213
|
totalSignups,
|
|
222
214
|
stateRoots[i + 1],
|
|
@@ -11,10 +11,10 @@ include "../../utils/trees/QuinaryGeneratePathIndices.circom";
|
|
|
11
11
|
include "../../utils/qv/StateLeafAndBallotTransformer.circom";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Processes one message and updates the state accordingly.
|
|
15
|
-
* This template involves complex interactions, including transformations based on message type,
|
|
16
|
-
* validations against current states like voice credit balances or vote weights,
|
|
17
|
-
* and updates to Merkle trees representing state and ballot information.
|
|
14
|
+
* Processes one message and updates the state accordingly.
|
|
15
|
+
* This template involves complex interactions, including transformations based on message type,
|
|
16
|
+
* validations against current states like voice credit balances or vote weights,
|
|
17
|
+
* and updates to Merkle trees representing state and ballot information.
|
|
18
18
|
* This is a critical building block for ensuring the integrity and correctness of MACI state.
|
|
19
19
|
* This template supports the Quadratic Voting (QV).
|
|
20
20
|
*/
|
|
@@ -22,7 +22,6 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
22
22
|
// Constants defining the structure and size of state and ballots.
|
|
23
23
|
var STATE_LEAF_LENGTH = 3;
|
|
24
24
|
var BALLOT_LENGTH = 2;
|
|
25
|
-
var MESSAGE_LENGTH = 10;
|
|
26
25
|
var PACKED_COMMAND_LENGTH = 4;
|
|
27
26
|
var VOTE_OPTION_TREE_ARITY = 5;
|
|
28
27
|
var STATE_TREE_ARITY = 2;
|
|
@@ -36,7 +35,6 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
36
35
|
var STATE_LEAF_PUBLIC_Y_INDEX = 1;
|
|
37
36
|
// Voice Credit balance.
|
|
38
37
|
var STATE_LEAF_VOICE_CREDIT_BALANCE_INDEX = 2;
|
|
39
|
-
var NUMBER_BITS = 252;
|
|
40
38
|
|
|
41
39
|
// Number of users that have completed the sign up.
|
|
42
40
|
signal input totalSignups;
|
|
@@ -125,7 +123,7 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
125
123
|
|
|
126
124
|
// 4. Verify that the original ballot exists in the given ballot root.
|
|
127
125
|
var computedBallot = PoseidonHasher(2)([
|
|
128
|
-
ballot[BALLOT_NONCE_INDEX],
|
|
126
|
+
ballot[BALLOT_NONCE_INDEX],
|
|
129
127
|
ballot[BALLOT_VOTE_OPTION_ROOT_INDEX]
|
|
130
128
|
]);
|
|
131
129
|
var computedStateLeafPathIndices[stateTreeDepth] = Num2Bits(stateTreeDepth)(stateIndexMux);
|
|
@@ -193,8 +191,8 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
193
191
|
);
|
|
194
192
|
|
|
195
193
|
newStateRoot <== computedNewStateLeafQip;
|
|
196
|
-
|
|
197
|
-
// 7. Generate a new ballot root.
|
|
194
|
+
|
|
195
|
+
// 7. Generate a new ballot root.
|
|
198
196
|
var computedNewBallot = PoseidonHasher(2)([computedNewBallotNonce, newBallotVoteOptionRoot]);
|
|
199
197
|
var computedNewBallotQip = MerkleTreeInclusionProof(stateTreeDepth)(
|
|
200
198
|
computedNewBallot,
|
|
@@ -204,4 +202,3 @@ template SingleMessageProcessorQv(stateTreeDepth, voteOptionTreeDepth) {
|
|
|
204
202
|
|
|
205
203
|
newBallotRoot <== computedNewBallotQip;
|
|
206
204
|
}
|
|
207
|
-
|
|
@@ -9,6 +9,7 @@ include "./escalarmulany.circom";
|
|
|
9
9
|
include "./escalarmulfix.circom";
|
|
10
10
|
// local imports
|
|
11
11
|
include "./PoseidonHasher.circom";
|
|
12
|
+
include "./IsOnCurve.circom";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Variant of the EdDSAPoseidonVerifier template from circomlib
|
|
@@ -37,9 +38,13 @@ template EdDSAPoseidonVerifier() {
|
|
|
37
38
|
// Output signal for the validity of the signature.
|
|
38
39
|
signal output isValid;
|
|
39
40
|
|
|
41
|
+
// Verify the public key and signature point are on the BabyJubJub curve.
|
|
42
|
+
var computedIsPkOnCurve = IsOnCurve()(publicKeyX, publicKeyY);
|
|
43
|
+
var computedIsSpOnCurve = IsOnCurve()(signaturePointX, signaturePointY);
|
|
44
|
+
|
|
40
45
|
// Ensure signatureScalar<Subgroup Order.
|
|
41
46
|
// convert the signature scalar signatureScalar into its binary representation.
|
|
42
|
-
var computedNum2Bits[254] =
|
|
47
|
+
var computedNum2Bits[254] = Num2Bits_strict()(signatureScalar);
|
|
43
48
|
|
|
44
49
|
var computedCompConstantIn[254] = computedNum2Bits;
|
|
45
50
|
computedCompConstantIn[253] = 0;
|
|
@@ -82,10 +87,10 @@ template EdDSAPoseidonVerifier() {
|
|
|
82
87
|
// Components to handle edge cases and ensure that all conditions
|
|
83
88
|
// for a valid signature are met, including the
|
|
84
89
|
// public key not being zero and other integrity checks.
|
|
85
|
-
var computedIsAxZero = IsZero()(
|
|
90
|
+
var computedIsAxZero = IsZero()(computedDouble3XOut);
|
|
86
91
|
var computedIsAxEqual = IsEqual()([computedIsAxZero, 0]);
|
|
87
92
|
var computedIsCcZero = IsZero()(computedCompConstant);
|
|
88
|
-
var computedIsValid = IsEqual()([computedIsLeftRightValid + computedIsAxEqual + computedIsCcZero,
|
|
93
|
+
var computedIsValid = IsEqual()([computedIsLeftRightValid + computedIsAxEqual + computedIsCcZero + computedIsPkOnCurve + computedIsSpOnCurve, 5]);
|
|
89
94
|
|
|
90
95
|
isValid <== computedIsValid;
|
|
91
96
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
pragma circom 2.0.0;
|
|
2
|
+
|
|
3
|
+
// zk-kit imports
|
|
4
|
+
include "./comparators.circom";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns 0 or 1 depending on if the point is on the BabyJubJub curve or not. The point is on the
|
|
8
|
+
* BabyJubJub curve if the following equation is true: a*x^2 + y^2 == 1 + d*x^2*y^2
|
|
9
|
+
* This template is identical to the BabyCheck template from circomlib, but it returns 0 or 1
|
|
10
|
+
* instead of having a hard constraint.
|
|
11
|
+
* Based on: https://github.com/iden3/circomlib/blob/master/circuits/babyjub.circom
|
|
12
|
+
*/
|
|
13
|
+
template IsOnCurve() {
|
|
14
|
+
// x coordinate of the point on the BabyJubJub curve.
|
|
15
|
+
signal input x;
|
|
16
|
+
// y coordinate of the point on the BabyJubJub curve.
|
|
17
|
+
signal input y;
|
|
18
|
+
// True when the point (x, y) satisfies the BabyJubJub curve equation.
|
|
19
|
+
signal output isValid;
|
|
20
|
+
|
|
21
|
+
// x^2 and y^2 intermediate values.
|
|
22
|
+
signal x2;
|
|
23
|
+
signal y2;
|
|
24
|
+
// x^2 * y^2 intermediate value.
|
|
25
|
+
signal x2y2;
|
|
26
|
+
|
|
27
|
+
// BabyJubJub curve parameters.
|
|
28
|
+
var a = 168700;
|
|
29
|
+
var d = 168696;
|
|
30
|
+
|
|
31
|
+
// Compute x^2 and y^2.
|
|
32
|
+
x2 <== x * x;
|
|
33
|
+
y2 <== y * y;
|
|
34
|
+
|
|
35
|
+
// Compute x^2 * y^2.
|
|
36
|
+
x2y2 <== x2 * y2;
|
|
37
|
+
|
|
38
|
+
// Check if a*x^2 + y^2 == 1 + d*x^2*y^2.
|
|
39
|
+
isValid <== IsEqual()([a * x2 + y2, 1 + d * x2y2]);
|
|
40
|
+
}
|
|
@@ -119,4 +119,9 @@ template StateLeafAndBallotTransformerFull() {
|
|
|
119
119
|
isValid <== computedIsValid;
|
|
120
120
|
isStateLeafIndexValid <== computedIsStateLeafIndexValid;
|
|
121
121
|
isVoteOptionIndexValid <== computedIsVoteOptionIndexValid;
|
|
122
|
+
|
|
123
|
+
// Constrain commandPollId and commandSalt using dummy squares.
|
|
124
|
+
// This binds the proof to a specific poll and salt.
|
|
125
|
+
signal commandPollIdSquare <== commandPollId * commandPollId;
|
|
126
|
+
signal commandSaltSquared <== commandSalt * commandSalt;
|
|
122
127
|
}
|
|
@@ -102,4 +102,9 @@ template StateLeafAndBallotTransformerNonQv() {
|
|
|
102
102
|
isValid <== computedIsValid;
|
|
103
103
|
isStateLeafIndexValid <== computedIsStateLeafIndexValid;
|
|
104
104
|
isVoteOptionIndexValid <== computedIsVoteOptionIndexValid;
|
|
105
|
+
|
|
106
|
+
// Constrain commandPollId and commandSalt using dummy squares.
|
|
107
|
+
// This binds the proof to a specific poll and salt.
|
|
108
|
+
signal commandPollIdSquare <== commandPollId * commandPollId;
|
|
109
|
+
signal commandSaltSquared <== commandSalt * commandSalt;
|
|
105
110
|
}
|
|
@@ -102,4 +102,9 @@ template StateLeafAndBallotTransformer() {
|
|
|
102
102
|
isValid <== computedIsValid;
|
|
103
103
|
isStateLeafIndexValid <== computedIsStateLeafIndexValid;
|
|
104
104
|
isVoteOptionIndexValid <== computedIsVoteOptionIndexValid;
|
|
105
|
+
|
|
106
|
+
// Constrain commandPollId and commandSalt using dummy squares.
|
|
107
|
+
// This binds the proof to a specific poll and salt.
|
|
108
|
+
signal commandPollIdSquare <== commandPollId * commandPollId;
|
|
109
|
+
signal commandSaltSquared <== commandSalt * commandSalt;
|
|
105
110
|
}
|
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.991fa14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "zk-SNARK circuits for MACI",
|
|
6
6
|
"main": "build/ts/index.js",
|
|
@@ -38,7 +38,8 @@
|
|
|
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:
|
|
41
|
+
"test:messageProcessorFull": "pnpm run mocha-test ts/__tests__/MessageProcessorFull.test.ts",
|
|
42
|
+
"test:isOnCurve": "pnpm run mocha-test ts/__tests__/IsOnCurve.test.ts",
|
|
42
43
|
"test:voteTally": "pnpm run mocha-test ts/__tests__/VoteTally.test.ts",
|
|
43
44
|
"test:ceremonyParams": "pnpm run mocha-test ts/__tests__/CeremonyParams.test.ts",
|
|
44
45
|
"test:incrementalQuinaryTree": "pnpm run mocha-test ts/__tests__/IncrementalQuinaryTree.test.ts",
|
|
@@ -46,10 +47,10 @@
|
|
|
46
47
|
"test:pollJoined": "pnpm run mocha-test ts/__tests__/PollJoined.test.ts"
|
|
47
48
|
},
|
|
48
49
|
"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.
|
|
50
|
+
"@maci-protocol/core": "0.0.0-ci.991fa14",
|
|
51
|
+
"@maci-protocol/crypto": "0.0.0-ci.991fa14",
|
|
52
|
+
"@maci-protocol/domainobjs": "0.0.0-ci.991fa14",
|
|
53
|
+
"@maci-protocol/sdk": "0.0.0-ci.991fa14",
|
|
53
54
|
"@zk-kit/circuits": "^0.4.0",
|
|
54
55
|
"circomkit": "^0.3.4",
|
|
55
56
|
"circomlib": "^2.0.5"
|
|
@@ -65,10 +66,10 @@
|
|
|
65
66
|
"chai-as-promised": "^8.0.1",
|
|
66
67
|
"fast-check": "^4.2.0",
|
|
67
68
|
"glob": "^11.0.3",
|
|
68
|
-
"mocha": "^11.7.
|
|
69
|
+
"mocha": "^11.7.2",
|
|
69
70
|
"ts-mocha": "^11.1.0",
|
|
70
71
|
"ts-node": "^10.9.1",
|
|
71
72
|
"typescript": "^5.9.2"
|
|
72
73
|
},
|
|
73
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "5e5511f3d75a046c4c270d4de4669061a65ba7eb"
|
|
74
75
|
}
|