@maci-protocol/circuits 0.0.0-ci.f4bc8a6 → 0.0.0-ci.f5db322

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.
Files changed (49) hide show
  1. package/LICENSE +1 -2
  2. package/build/ts/{genZkeys.d.ts → generateZkeys.d.ts} +1 -1
  3. package/build/ts/generateZkeys.d.ts.map +1 -0
  4. package/build/ts/{genZkeys.js → generateZkeys.js} +1 -1
  5. package/build/ts/generateZkeys.js.map +1 -0
  6. package/build/ts/types.d.ts +11 -12
  7. package/build/ts/types.d.ts.map +1 -1
  8. package/build/tsconfig.build.tsbuildinfo +1 -1
  9. package/circom/circuits.json +23 -7
  10. package/circom/coordinator/full/MessageProcessor.circom +253 -0
  11. package/circom/coordinator/full/SingleMessageProcessor.circom +204 -0
  12. package/circom/coordinator/non-qv/processMessages.circom +119 -119
  13. package/circom/coordinator/non-qv/tallyVotes.circom +51 -45
  14. package/circom/coordinator/qv/processMessages.circom +120 -117
  15. package/circom/coordinator/qv/tallyVotes.circom +65 -63
  16. package/circom/utils/{calculateTotal.circom → CalculateTotal.circom} +8 -6
  17. package/circom/utils/{verifySignature.circom → EdDSAPoseidonVerifier.circom} +40 -66
  18. package/circom/utils/MessageHasher.circom +57 -0
  19. package/circom/utils/MessageToCommand.circom +107 -0
  20. package/circom/utils/PoseidonHasher.circom +29 -0
  21. package/circom/utils/{privToPubKey.circom → PrivateToPublicKey.circom} +12 -10
  22. package/circom/utils/VerifySignature.circom +39 -0
  23. package/circom/utils/full/MessageValidator.circom +91 -0
  24. package/circom/utils/full/StateLeafAndBallotTransformer.circom +122 -0
  25. package/circom/utils/non-qv/{messageValidator.circom → MessageValidator.circom} +17 -15
  26. package/circom/utils/non-qv/{stateLeafAndBallotTransformer.circom → StateLeafAndBallotTransformer.circom} +36 -36
  27. package/circom/utils/qv/{messageValidator.circom → MessageValidator.circom} +17 -15
  28. package/circom/utils/qv/{stateLeafAndBallotTransformer.circom → StateLeafAndBallotTransformer.circom} +36 -36
  29. package/circom/utils/trees/BinaryMerkleRoot.circom +62 -0
  30. package/circom/utils/trees/CheckRoot.circom +49 -0
  31. package/circom/utils/trees/LeafExists.circom +27 -0
  32. package/circom/utils/trees/MerklePathIndicesGenerator.circom +44 -0
  33. package/circom/utils/trees/MerkleTreeInclusionProof.circom +50 -0
  34. package/circom/utils/trees/QuinaryCheckRoot.circom +54 -0
  35. package/circom/utils/trees/QuinaryGeneratePathIndices.circom +44 -0
  36. package/circom/utils/trees/QuinaryLeafExists.circom +30 -0
  37. package/circom/utils/trees/QuinarySelector.circom +42 -0
  38. package/circom/utils/trees/QuinaryTreeInclusionProof.circom +55 -0
  39. package/circom/utils/trees/Splicer.circom +76 -0
  40. package/circom/voter/PollJoined.circom +43 -0
  41. package/circom/voter/PollJoining.circom +54 -0
  42. package/package.json +17 -14
  43. package/build/ts/genZkeys.d.ts.map +0 -1
  44. package/build/ts/genZkeys.js.map +0 -1
  45. package/circom/utils/hashers.circom +0 -78
  46. package/circom/utils/messageToCommand.circom +0 -78
  47. package/circom/utils/trees/incrementalMerkleTree.circom +0 -198
  48. package/circom/utils/trees/incrementalQuinaryTree.circom +0 -287
  49. package/circom/voter/poll.circom +0 -93
@@ -9,28 +9,30 @@ include "./escalarmulfix.circom";
9
9
  * Converts a private key to a public key on the BabyJubJub curve.
10
10
  * The input private key needs to be hashed and then pruned before.
11
11
  */
12
- template PrivToPubKey() {
12
+ template PrivateToPublicKey() {
13
13
  // The base point of the BabyJubJub curve.
14
14
  var BASE8[2] = [
15
15
  5299619240641551281634865583518297030282874472190772894086521144482721001553,
16
16
  16950150798460657717958625567821834550301663161624707787222815936182638968203
17
17
  ];
18
18
 
19
- // Prime subgroup order 'l'.
20
- var l = 2736030358979909402780800718157159386076813972158567259200215660948447373041;
19
+ // The prime subgroup order.
20
+ var SUBGROUP_ORDER = 2736030358979909402780800718157159386076813972158567259200215660948447373041;
21
21
 
22
- signal input privKey;
23
- signal output pubKey[2];
22
+ // The private key
23
+ signal input privateKey;
24
+ // The public key
25
+ signal output publicKey[2];
24
26
 
25
- // Check if private key is in the prime subgroup order 'l'
26
- var isLessThan = LessThan(251)([privKey, l]);
27
+ // Check if private key is in the prime subgroup order
28
+ var isLessThan = LessThan(251)([privateKey, SUBGROUP_ORDER]);
27
29
  isLessThan === 1;
28
30
 
29
31
  // Convert the private key to bits.
30
- var computedPrivBits[253] = Num2Bits(253)(privKey);
32
+ var computedPrivateBits[253] = Num2Bits(253)(privateKey);
31
33
 
32
34
  // Perform scalar multiplication with the basepoint.
33
- var computedEscalarMulFix[2] = EscalarMulFix(253, BASE8)(computedPrivBits);
35
+ var computedPublicKey[2] = EscalarMulFix(253, BASE8)(computedPrivateBits);
34
36
 
35
- pubKey <== computedEscalarMulFix;
37
+ publicKey <== computedPublicKey;
36
38
  }
@@ -0,0 +1,39 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // local imports
4
+ include "./EdDSAPoseidonVerifier.circom";
5
+ include "./PoseidonHasher.circom";
6
+
7
+ /**
8
+ * Verifies the EdDSA signature for a given command, which has exactly four elements in the hash preimage.
9
+ */
10
+ template VerifySignature() {
11
+ // Number of elements in the hash preimage.
12
+ var PRE_IMAGE_LENGTH = 4;
13
+
14
+ // Public key of the signer, consisting of two coordinates [x, y].
15
+ signal input publicKey[2];
16
+ // signaturePoint point from the signature, consisting of two coordinates [x, y].
17
+ signal input signaturePoint[2];
18
+ // Scalar component of the signature.
19
+ signal input signatureScalar;
20
+ // The preimage data that was hashed, an array of four elements.
21
+ signal input preimage[PRE_IMAGE_LENGTH];
22
+ // The validity of the signature.
23
+ signal output isValid;
24
+
25
+ // Hash the preimage using the Poseidon hashing function configured for four inputs.
26
+ var computedPreimage = PoseidonHasher(4)(preimage);
27
+
28
+ // Instantiate the patched EdDSA Poseidon verifier with the necessary inputs.
29
+ var computedIsValid = EdDSAPoseidonVerifier()(
30
+ publicKey[0],
31
+ publicKey[1],
32
+ signatureScalar,
33
+ signaturePoint[0],
34
+ signaturePoint[1],
35
+ computedPreimage
36
+ );
37
+
38
+ isValid <== computedIsValid;
39
+ }
@@ -0,0 +1,91 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // zk-kit imports
4
+ include "./safe-comparators.circom";
5
+ // local imports
6
+ include "../VerifySignature.circom";
7
+
8
+ /**
9
+ * Checks if a MACI message is valid or not.
10
+ * This template supports the full mode (all credits are spent on one option)
11
+ */
12
+ template MessageValidatorFull() {
13
+ // Length of the packed command.
14
+ var PACKED_COMMAND_LENGTH = 4;
15
+ // Number of checks to be performed.
16
+ var TOTAL_CHECKS = 5;
17
+
18
+ // State index of the user.
19
+ signal input stateTreeIndex;
20
+ // Number of user sign-ups in the state tree.
21
+ signal input totalSignups;
22
+ // Vote option index.
23
+ signal input voteOptionIndex;
24
+ // Number of valid vote options for the poll.
25
+ signal input voteOptions;
26
+ // Ballot nonce.
27
+ signal input originalNonce;
28
+ // Command nonce.
29
+ signal input commandNonce;
30
+ // Packed command.
31
+ signal input command[PACKED_COMMAND_LENGTH];
32
+ // Public key of the state leaf (user).
33
+ signal input publicKey[2];
34
+ // EdDSA signature of the command (R part).
35
+ signal input signaturePoint[2];
36
+ // EdDSA signature of the command (S part).
37
+ signal input signatureScalar;
38
+ // State leaf current voice credit balance.
39
+ signal input currentVoiceCreditBalance;
40
+ // Current number of votes for specific option.
41
+ signal input currentVotesForOption;
42
+ // Vote weight.
43
+ signal input voteWeight;
44
+
45
+ // True when the command is valid; otherwise false.
46
+ signal output isValid;
47
+ // True if the state leaf index is valid
48
+ signal output isStateLeafIndexValid;
49
+ // True if the vote option index is valid
50
+ signal output isVoteOptionIndexValid;
51
+
52
+ // Check (1) - The state leaf index must be valid.
53
+ // The check ensure that the stateTreeIndex < totalSignups as first validation.
54
+ // Must be < because the stateTreeIndex is 0-based. Zero is for blank state leaf
55
+ // while 1 is for the first actual user.
56
+ var computedIsStateLeafIndexValid = SafeLessThan(252)([stateTreeIndex, totalSignups]);
57
+
58
+ // Check (2) - The vote option index must be less than the number of valid vote options (0 indexed).
59
+ var computedIsVoteOptionIndexValid = SafeLessThan(252)([voteOptionIndex, voteOptions]);
60
+
61
+ // Check (3) - The nonce must be correct.
62
+ var computedIsNonceValid = IsEqual()([originalNonce + 1, commandNonce]);
63
+
64
+ // Check (4) - The signature must be correct.
65
+ var computedIsSignatureValid = VerifySignature()(publicKey, signaturePoint, signatureScalar, command);
66
+
67
+ // Check (5) - There must be sufficient voice credits.
68
+ // The check ensure that currentVotesForOption + currentVoiceCreditBalance is equal to voteWeight.
69
+ var computedAreVoiceCreditsSpent = IsEqual()(
70
+ [
71
+ currentVotesForOption + currentVoiceCreditBalance,
72
+ voteWeight
73
+ ]
74
+ );
75
+
76
+ // When all five checks are correct, then isValid = 1.
77
+ var computedIsUpdateValid = IsEqual()(
78
+ [
79
+ TOTAL_CHECKS,
80
+ computedIsSignatureValid +
81
+ computedAreVoiceCreditsSpent +
82
+ computedIsNonceValid +
83
+ computedIsStateLeafIndexValid +
84
+ computedIsVoteOptionIndexValid
85
+ ]
86
+ );
87
+
88
+ isValid <== computedIsUpdateValid;
89
+ isStateLeafIndexValid <== computedIsStateLeafIndexValid;
90
+ isVoteOptionIndexValid <== computedIsVoteOptionIndexValid;
91
+ }
@@ -0,0 +1,122 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // circomlib import
4
+ include "./mux1.circom";
5
+ // local import
6
+ include "./MessageValidator.circom";
7
+
8
+ /**
9
+ * Processes a command by verifying its validity and updates the state leaf and ballot accordingly.
10
+ * If the message is correct, updates the public key in the state leaf and the nonce
11
+ * in the ballot using multiplexer components.
12
+ * This template supports the full mode (all credits are spent on one option)
13
+ */
14
+ template StateLeafAndBallotTransformerFull() {
15
+ // Length of the packed command.
16
+ var PACKED_COMMAND_LENGTH = 4;
17
+
18
+ // Number of user sign-ups in the state tree.
19
+ signal input totalSignups;
20
+ // Number of valid vote options for the poll.
21
+ signal input voteOptions;
22
+
23
+ // The following signals represents a state leaf (signed up user).
24
+ // Public key.
25
+ signal input stateLeafPublicKey[2];
26
+ // Current voice credit balance.
27
+ signal input stateLeafVoiceCreditBalance;
28
+
29
+ // The following signals represents a ballot.
30
+ // Nonce.
31
+ signal input ballotNonce;
32
+ // Current number of votes for specific option.
33
+ signal input ballotCurrentVotesForOption;
34
+
35
+ // The following signals represents a command.
36
+ // State index of the user.
37
+ signal input commandStateIndex;
38
+ // Public key of the user.
39
+ signal input commandPublicKey[2];
40
+ // Vote option index.
41
+ signal input commandVoteOptionIndex;
42
+ // Vote weight.
43
+ signal input commandNewVoteWeight;
44
+ // Nonce.
45
+ signal input commandNonce;
46
+ // Poll identifier.
47
+ signal input commandPollId;
48
+ // Salt.
49
+ signal input commandSalt;
50
+ // EdDSA signature of the command (R part).
51
+ signal input commandSignaturePoint[2];
52
+ // EdDSA signature of the command (S part).
53
+ signal input commandSignatureScalar;
54
+ // Packed command.
55
+ // nb. we are assuming that the packedCommand is always valid.
56
+ signal input packedCommand[PACKED_COMMAND_LENGTH];
57
+
58
+ // New state leaf (if the command is valid).
59
+ signal output newStateLeafPublicKey[2];
60
+ // New ballot (if the command is valid).
61
+ signal output newBallotNonce;
62
+
63
+ // True when the command is valid; otherwise false.
64
+ signal output isValid;
65
+ // True if the state leaf index is valid
66
+ signal output isStateLeafIndexValid;
67
+ // True if the vote option index is valid
68
+ signal output isVoteOptionIndexValid;
69
+
70
+ // Check if the command / message is valid.
71
+ var (
72
+ computedIsValid,
73
+ computedIsStateLeafIndexValid,
74
+ computedIsVoteOptionIndexValid
75
+ ) = MessageValidatorFull()(
76
+ commandStateIndex,
77
+ totalSignups,
78
+ commandVoteOptionIndex,
79
+ voteOptions,
80
+ ballotNonce,
81
+ commandNonce,
82
+ packedCommand,
83
+ stateLeafPublicKey,
84
+ commandSignaturePoint,
85
+ commandSignatureScalar,
86
+ stateLeafVoiceCreditBalance,
87
+ ballotCurrentVotesForOption,
88
+ commandNewVoteWeight
89
+ );
90
+
91
+ // If the message is valid then we swap out the public key.
92
+ // This means using a Mux1() for publicKey[0] and another one
93
+ // for publicKey[1].
94
+ var computedNewstateLeafPublicKey0Mux = Mux1()(
95
+ [
96
+ stateLeafPublicKey[0],
97
+ commandPublicKey[0]
98
+ ],
99
+ computedIsValid
100
+ );
101
+
102
+ var computedNewstateLeafPublicKey1Mux = Mux1()(
103
+ [
104
+ stateLeafPublicKey[1],
105
+ commandPublicKey[1]
106
+ ],
107
+ computedIsValid
108
+ );
109
+
110
+ newStateLeafPublicKey[0] <== computedNewstateLeafPublicKey0Mux;
111
+ newStateLeafPublicKey[1] <== computedNewstateLeafPublicKey1Mux;
112
+
113
+ // If the message is valid, then we swap out the ballot nonce
114
+ // using a Mux1().
115
+ var computedNewBallotNonceMux = Mux1()([ballotNonce, commandNonce], computedIsValid);
116
+
117
+ newBallotNonce <== computedNewBallotNonceMux;
118
+
119
+ isValid <== computedIsValid;
120
+ isStateLeafIndexValid <== computedIsStateLeafIndexValid;
121
+ isVoteOptionIndexValid <== computedIsVoteOptionIndexValid;
122
+ }
@@ -3,7 +3,7 @@ pragma circom 2.0.0;
3
3
  // zk-kit imports
4
4
  include "./safe-comparators.circom";
5
5
  // local imports
6
- include "../verifySignature.circom";
6
+ include "../VerifySignature.circom";
7
7
 
8
8
  /**
9
9
  * Checks if a MACI message is valid or not.
@@ -11,12 +11,14 @@ include "../verifySignature.circom";
11
11
  */
12
12
  template MessageValidatorNonQv() {
13
13
  // Length of the packed command.
14
- var PACKED_CMD_LENGTH = 4;
14
+ var PACKED_COMMAND_LENGTH = 4;
15
+ // Number of checks to be performed.
16
+ var TOTAL_CHECKS = 5;
15
17
 
16
18
  // State index of the user.
17
19
  signal input stateTreeIndex;
18
20
  // Number of user sign-ups in the state tree.
19
- signal input numSignUps;
21
+ signal input totalSignups;
20
22
  // Vote option index.
21
23
  signal input voteOptionIndex;
22
24
  // Number of valid vote options for the poll.
@@ -24,15 +26,15 @@ template MessageValidatorNonQv() {
24
26
  // Ballot nonce.
25
27
  signal input originalNonce;
26
28
  // Command nonce.
27
- signal input nonce;
29
+ signal input commandNonce;
28
30
  // Packed command.
29
- signal input cmd[PACKED_CMD_LENGTH];
31
+ signal input command[PACKED_COMMAND_LENGTH];
30
32
  // Public key of the state leaf (user).
31
- signal input pubKey[2];
32
- // ECDSA signature of the command (R part).
33
- signal input sigR8[2];
34
- // ECDSA signature of the command (S part).
35
- signal input sigS;
33
+ signal input publicKey[2];
34
+ // EdDSA signature of the command (R part).
35
+ signal input signaturePoint[2];
36
+ // EdDSA signature of the command (S part).
37
+ signal input signatureScalar;
36
38
  // State leaf current voice credit balance.
37
39
  signal input currentVoiceCreditBalance;
38
40
  // Current number of votes for specific option.
@@ -48,19 +50,19 @@ template MessageValidatorNonQv() {
48
50
  signal output isVoteOptionIndexValid;
49
51
 
50
52
  // Check (1) - The state leaf index must be valid.
51
- // The check ensure that the stateTreeIndex < numSignUps as first validation.
53
+ // The check ensure that the stateTreeIndex < totalSignups as first validation.
52
54
  // Must be < because the stateTreeIndex is 0-based. Zero is for blank state leaf
53
55
  // while 1 is for the first actual user.
54
- var computedIsStateLeafIndexValid = SafeLessThan(252)([stateTreeIndex, numSignUps]);
56
+ var computedIsStateLeafIndexValid = SafeLessThan(252)([stateTreeIndex, totalSignups]);
55
57
 
56
58
  // Check (2) - The vote option index must be less than the number of valid vote options (0 indexed).
57
59
  var computedIsVoteOptionIndexValid = SafeLessThan(252)([voteOptionIndex, voteOptions]);
58
60
 
59
61
  // Check (3) - The nonce must be correct.
60
- var computedIsNonceValid = IsEqual()([originalNonce + 1, nonce]);
62
+ var computedIsNonceValid = IsEqual()([originalNonce + 1, commandNonce]);
61
63
 
62
64
  // Check (4) - The signature must be correct.
63
- var computedIsSignatureValid = VerifySignature()(pubKey, sigR8, sigS, cmd);
65
+ var computedIsSignatureValid = VerifySignature()(publicKey, signaturePoint, signatureScalar, command);
64
66
 
65
67
  // Check (5) - There must be sufficient voice credits.
66
68
  // The check ensure that currentVoiceCreditBalance + (currentVotesForOption) >= (voteWeight).
@@ -74,7 +76,7 @@ template MessageValidatorNonQv() {
74
76
  // When all five checks are correct, then isValid = 1.
75
77
  var computedIsUpdateValid = IsEqual()(
76
78
  [
77
- 5,
79
+ TOTAL_CHECKS,
78
80
  computedIsSignatureValid +
79
81
  computedAreVoiceCreditsSufficient +
80
82
  computedIsNonceValid +
@@ -3,7 +3,7 @@ pragma circom 2.0.0;
3
3
  // circomlib import
4
4
  include "./mux1.circom";
5
5
  // local import
6
- include "./messageValidator.circom";
6
+ include "./MessageValidator.circom";
7
7
 
8
8
  /**
9
9
  * Processes a command by verifying its validity and updates the state leaf and ballot accordingly.
@@ -13,18 +13,18 @@ include "./messageValidator.circom";
13
13
  */
14
14
  template StateLeafAndBallotTransformerNonQv() {
15
15
  // Length of the packed command.
16
- var PACKED_CMD_LENGTH = 4;
16
+ var PACKED_COMMAND_LENGTH = 4;
17
17
 
18
18
  // Number of user sign-ups in the state tree.
19
- signal input numSignUps;
19
+ signal input totalSignups;
20
20
  // Number of valid vote options for the poll.
21
21
  signal input voteOptions;
22
22
 
23
23
  // The following signals represents a state leaf (signed up user).
24
24
  // Public key.
25
- signal input slPubKey[2];
25
+ signal input stateLeafPublicKey[2];
26
26
  // Current voice credit balance.
27
- signal input slVoiceCreditBalance;
27
+ signal input stateLeafVoiceCreditBalance;
28
28
 
29
29
  // The following signals represents a ballot.
30
30
  // Nonce.
@@ -34,29 +34,29 @@ template StateLeafAndBallotTransformerNonQv() {
34
34
 
35
35
  // The following signals represents a command.
36
36
  // State index of the user.
37
- signal input cmdStateIndex;
37
+ signal input commandStateIndex;
38
38
  // Public key of the user.
39
- signal input cmdNewPubKey[2];
39
+ signal input commandPublicKey[2];
40
40
  // Vote option index.
41
- signal input cmdVoteOptionIndex;
41
+ signal input commandVoteOptionIndex;
42
42
  // Vote weight.
43
- signal input cmdNewVoteWeight;
43
+ signal input commandNewVoteWeight;
44
44
  // Nonce.
45
- signal input cmdNonce;
45
+ signal input commandNonce;
46
46
  // Poll identifier.
47
- signal input cmdPollId;
47
+ signal input commandPollId;
48
48
  // Salt.
49
- signal input cmdSalt;
50
- // ECDSA signature of the command (R part).
51
- signal input cmdSigR8[2];
52
- // ECDSA signature of the command (S part).
53
- signal input cmdSigS;
49
+ signal input commandSalt;
50
+ // EdDSA signature of the command (R part).
51
+ signal input commandSignaturePoint[2];
52
+ // EdDSA signature of the command (S part).
53
+ signal input commandSignatureScalar;
54
54
  // Packed command.
55
55
  // nb. we are assuming that the packedCommand is always valid.
56
- signal input packedCommand[PACKED_CMD_LENGTH];
56
+ signal input packedCommand[PACKED_COMMAND_LENGTH];
57
57
 
58
58
  // New state leaf (if the command is valid).
59
- signal output newSlPubKey[2];
59
+ signal output newStateLeafPublicKey[2];
60
60
  // New ballot (if the command is valid).
61
61
  signal output newBallotNonce;
62
62
 
@@ -68,38 +68,38 @@ template StateLeafAndBallotTransformerNonQv() {
68
68
  signal output isVoteOptionIndexValid;
69
69
 
70
70
  // Check if the command / message is valid.
71
- var (computedMessageValidator, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = MessageValidatorNonQv()(
72
- cmdStateIndex,
73
- numSignUps,
74
- cmdVoteOptionIndex,
71
+ var (computedIsValid, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = MessageValidatorNonQv()(
72
+ commandStateIndex,
73
+ totalSignups,
74
+ commandVoteOptionIndex,
75
75
  voteOptions,
76
76
  ballotNonce,
77
- cmdNonce,
77
+ commandNonce,
78
78
  packedCommand,
79
- slPubKey,
80
- cmdSigR8,
81
- cmdSigS,
82
- slVoiceCreditBalance,
79
+ stateLeafPublicKey,
80
+ commandSignaturePoint,
81
+ commandSignatureScalar,
82
+ stateLeafVoiceCreditBalance,
83
83
  ballotCurrentVotesForOption,
84
- cmdNewVoteWeight
84
+ commandNewVoteWeight
85
85
  );
86
86
 
87
87
  // If the message is valid then we swap out the public key.
88
- // This means using a Mux1() for pubKey[0] and another one
89
- // for pubKey[1].
90
- var computedNewSlPubKey0Mux = Mux1()([slPubKey[0], cmdNewPubKey[0]], computedMessageValidator);
91
- var computedNewSlPubKey1Mux = Mux1()([slPubKey[1], cmdNewPubKey[1]], computedMessageValidator);
88
+ // This means using a Mux1() for publicKey[0] and another one
89
+ // for publicKey[1].
90
+ var computedNewstateLeafPublicKey0Mux = Mux1()([stateLeafPublicKey[0], commandPublicKey[0]], computedIsValid);
91
+ var computedNewstateLeafPublicKey1Mux = Mux1()([stateLeafPublicKey[1], commandPublicKey[1]], computedIsValid);
92
92
 
93
- newSlPubKey[0] <== computedNewSlPubKey0Mux;
94
- newSlPubKey[1] <== computedNewSlPubKey1Mux;
93
+ newStateLeafPublicKey[0] <== computedNewstateLeafPublicKey0Mux;
94
+ newStateLeafPublicKey[1] <== computedNewstateLeafPublicKey1Mux;
95
95
 
96
96
  // If the message is valid, then we swap out the ballot nonce
97
97
  // using a Mux1().
98
- var computedNewBallotNonceMux = Mux1()([ballotNonce, cmdNonce], computedMessageValidator);
98
+ var computedNewBallotNonceMux = Mux1()([ballotNonce, commandNonce], computedIsValid);
99
99
 
100
100
  newBallotNonce <== computedNewBallotNonceMux;
101
101
 
102
- isValid <== computedMessageValidator;
102
+ isValid <== computedIsValid;
103
103
  isStateLeafIndexValid <== computedIsStateLeafIndexValid;
104
104
  isVoteOptionIndexValid <== computedIsVoteOptionIndexValid;
105
105
  }
@@ -3,7 +3,7 @@ pragma circom 2.0.0;
3
3
  // zk-kit imports
4
4
  include "./safe-comparators.circom";
5
5
  // local imports
6
- include "../verifySignature.circom";
6
+ include "../VerifySignature.circom";
7
7
 
8
8
  /**
9
9
  * Checks if a MACI message is valid or not.
@@ -11,12 +11,14 @@ include "../verifySignature.circom";
11
11
  */
12
12
  template MessageValidator() {
13
13
  // Length of the packed command.
14
- var PACKED_CMD_LENGTH = 4;
14
+ var PACKED_COMMAND_LENGTH = 4;
15
+ // Number of checks to be performed.
16
+ var TOTAL_CHECKS = 6;
15
17
 
16
18
  // State index of the user.
17
19
  signal input stateTreeIndex;
18
20
  // Number of user sign-ups in the state tree.
19
- signal input numSignUps;
21
+ signal input totalSignups;
20
22
  // Vote option index.
21
23
  signal input voteOptionIndex;
22
24
  // Number of valid vote options for the poll.
@@ -24,15 +26,15 @@ template MessageValidator() {
24
26
  // Ballot nonce.
25
27
  signal input originalNonce;
26
28
  // Command nonce.
27
- signal input nonce;
29
+ signal input commandNonce;
28
30
  // Packed command.
29
- signal input cmd[PACKED_CMD_LENGTH];
31
+ signal input command[PACKED_COMMAND_LENGTH];
30
32
  // Public key of the state leaf (user).
31
- signal input pubKey[2];
32
- // ECDSA signature of the command (R part).
33
- signal input sigR8[2];
34
- // ECDSA signature of the command (S part).
35
- signal input sigS;
33
+ signal input publicKey[2];
34
+ // EdDSA signature of the command (R part).
35
+ signal input signaturePoint[2];
36
+ // EdDSA signature of the command (S part).
37
+ signal input signatureScalar;
36
38
  // State leaf current voice credit balance.
37
39
  signal input currentVoiceCreditBalance;
38
40
  // Current number of votes for specific option.
@@ -48,19 +50,19 @@ template MessageValidator() {
48
50
  signal output isVoteOptionIndexValid;
49
51
 
50
52
  // Check (1) - The state leaf index must be valid.
51
- // The check ensure that the stateTreeIndex < numSignUps as first validation.
53
+ // The check ensure that the stateTreeIndex < totalSignups as first validation.
52
54
  // Must be < because the stateTreeIndex is 0-based. Zero is for blank state leaf
53
55
  // while 1 is for the first actual user.
54
- var computedIsStateLeafIndexValid = SafeLessThan(252)([stateTreeIndex, numSignUps]);
56
+ var computedIsStateLeafIndexValid = SafeLessThan(252)([stateTreeIndex, totalSignups]);
55
57
 
56
58
  // Check (2) - The vote option index must be less than the number of valid vote options (0 indexed).
57
59
  var computedIsVoteOptionIndexValid = SafeLessThan(252)([voteOptionIndex, voteOptions]);
58
60
 
59
61
  // Check (3) - The nonce must be correct.
60
- var computedIsNonceValid = IsEqual()([originalNonce + 1, nonce]);
62
+ var computedIsNonceValid = IsEqual()([originalNonce + 1, commandNonce]);
61
63
 
62
64
  // Check (4) - The signature must be correct.
63
- var computedIsSignatureValid = VerifySignature()(pubKey, sigR8, sigS, cmd);
65
+ var computedIsSignatureValid = VerifySignature()(publicKey, signaturePoint, signatureScalar, command);
64
66
 
65
67
  // Check (5) - There must be sufficient voice credits.
66
68
  // The check ensure that the voteWeight is < sqrt(field size)
@@ -79,7 +81,7 @@ template MessageValidator() {
79
81
  // When all six checks are correct, then isValid = 1.
80
82
  var computedIsUpdateValid = IsEqual()(
81
83
  [
82
- 6,
84
+ TOTAL_CHECKS,
83
85
  computedIsSignatureValid +
84
86
  computedAreVoiceCreditsSufficient +
85
87
  computedIsVoteWeightValid +