@maci-protocol/circuits 0.0.0-ci.fb960ed → 0.0.0-ci.fc91dc9

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.
@@ -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;
49
+ signal input commandSalt;
50
50
  // ECDSA signature of the command (R part).
51
- signal input cmdSigR8[2];
51
+ signal input commandSignaturePoint[2];
52
52
  // ECDSA signature of the command (S part).
53
- signal input cmdSigS;
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
 
@@ -69,33 +69,33 @@ template StateLeafAndBallotTransformerNonQv() {
69
69
 
70
70
  // Check if the command / message is valid.
71
71
  var (computedMessageValidator, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = MessageValidatorNonQv()(
72
- cmdStateIndex,
73
- numSignUps,
74
- cmdVoteOptionIndex,
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
88
  // This means using a Mux1() for publicKey[0] and another one
89
89
  // for publicKey[1].
90
- var computedNewSlPubKey0Mux = Mux1()([slPubKey[0], cmdNewPubKey[0]], computedMessageValidator);
91
- var computedNewSlPubKey1Mux = Mux1()([slPubKey[1], cmdNewPubKey[1]], computedMessageValidator);
90
+ var computedNewstateLeafPublicKey0Mux = Mux1()([stateLeafPublicKey[0], commandPublicKey[0]], computedMessageValidator);
91
+ var computedNewstateLeafPublicKey1Mux = Mux1()([stateLeafPublicKey[1], commandPublicKey[1]], computedMessageValidator);
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], computedMessageValidator);
99
99
 
100
100
  newBallotNonce <== computedNewBallotNonceMux;
101
101
 
@@ -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.
@@ -26,13 +28,13 @@ template MessageValidator() {
26
28
  // Command nonce.
27
29
  signal input nonce;
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
33
  signal input publicKey[2];
32
34
  // ECDSA signature of the command (R part).
33
- signal input sigR8[2];
35
+ signal input signaturePoint[2];
34
36
  // ECDSA signature of the command (S part).
35
- signal input sigS;
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,10 +50,10 @@ 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]);
@@ -60,7 +62,7 @@ template MessageValidator() {
60
62
  var computedIsNonceValid = IsEqual()([originalNonce + 1, nonce]);
61
63
 
62
64
  // Check (4) - The signature must be correct.
63
- var computedIsSignatureValid = VerifySignature()(publicKey, 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 +
@@ -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 StateLeafAndBallotTransformer() {
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 StateLeafAndBallotTransformer() {
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;
49
+ signal input commandSalt;
50
50
  // ECDSA signature of the command (R part).
51
- signal input cmdSigR8[2];
51
+ signal input commandSignaturePoint[2];
52
52
  // ECDSA signature of the command (S part).
53
- signal input cmdSigS;
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
 
@@ -69,33 +69,33 @@ template StateLeafAndBallotTransformer() {
69
69
 
70
70
  // Check if the command / message is valid.
71
71
  var (computedMessageValidator, computedIsStateLeafIndexValid, computedIsVoteOptionIndexValid) = MessageValidator()(
72
- cmdStateIndex,
73
- numSignUps,
74
- cmdVoteOptionIndex,
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
88
  // This means using a Mux1() for publicKey[0] and another one
89
89
  // for publicKey[1].
90
- var computedNewSlPubKey0Mux = Mux1()([slPubKey[0], cmdNewPubKey[0]], computedMessageValidator);
91
- var computedNewSlPubKey1Mux = Mux1()([slPubKey[1], cmdNewPubKey[1]], computedMessageValidator);
90
+ var computedNewstateLeafPublicKey0Mux = Mux1()([stateLeafPublicKey[0], commandPublicKey[0]], computedMessageValidator);
91
+ var computedNewstateLeafPublicKey1Mux = Mux1()([stateLeafPublicKey[1], commandPublicKey[1]], computedMessageValidator);
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], computedMessageValidator);
99
99
 
100
100
  newBallotNonce <== computedNewBallotNonceMux;
101
101
 
@@ -10,7 +10,7 @@ include "../CalculateTotal.circom";
10
10
  * Given a node index within an IMT and the total tree levels, it outputs the path indices leading to that node.
11
11
  * The template handles the modulo and division operations to break down the tree index into its constituent path indices.
12
12
  */
13
- template MerkleGeneratePathIndices(levels) {
13
+ template MerklePathIndicesGenerator(levels) {
14
14
  // The base used for the modulo and division operations, set to 2 for binary trees.
15
15
  var BASE = 2;
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maci-protocol/circuits",
3
- "version": "0.0.0-ci.fb960ed",
3
+ "version": "0.0.0-ci.fc91dc9",
4
4
  "private": false,
5
5
  "description": "zk-SNARK circuits for MACI",
6
6
  "main": "build/ts/index.js",
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "build-test-circuits-c": "ts-node ./ts/compile.ts --cWitness",
20
20
  "build-test-circuits-wasm": "ts-node ./ts/compile.ts",
21
- "gen-zkeys": "ts-node ./ts/genZkeys.ts",
21
+ "generate-zkeys": "ts-node ./ts/generateZkeys.ts",
22
22
  "info": "NODE_OPTIONS=--max-old-space-size=4096 ts-node ./ts/info.ts",
23
23
  "watch": "tsc --watch",
24
24
  "build": "tsc -p tsconfig.build.json",
@@ -44,10 +44,10 @@
44
44
  "test:pollJoined": "pnpm run mocha-test ts/__tests__/PollJoined.test.ts"
45
45
  },
46
46
  "dependencies": {
47
- "@maci-protocol/core": "0.0.0-ci.fb960ed",
48
- "@maci-protocol/crypto": "0.0.0-ci.fb960ed",
49
- "@maci-protocol/domainobjs": "0.0.0-ci.fb960ed",
50
- "@maci-protocol/sdk": "0.0.0-ci.fb960ed",
47
+ "@maci-protocol/core": "0.0.0-ci.fc91dc9",
48
+ "@maci-protocol/crypto": "0.0.0-ci.fc91dc9",
49
+ "@maci-protocol/domainobjs": "0.0.0-ci.fc91dc9",
50
+ "@maci-protocol/sdk": "0.0.0-ci.fc91dc9",
51
51
  "@zk-kit/circuits": "^0.4.0",
52
52
  "circomkit": "^0.3.2",
53
53
  "circomlib": "^2.0.5"
@@ -56,7 +56,7 @@
56
56
  "@types/chai": "^4.3.11",
57
57
  "@types/chai-as-promised": "^7.1.8",
58
58
  "@types/mocha": "^10.0.10",
59
- "@types/node": "^22.14.0",
59
+ "@types/node": "^22.14.1",
60
60
  "@types/snarkjs": "^0.7.9",
61
61
  "@zk-kit/baby-jubjub": "^1.0.3",
62
62
  "chai": "^4.3.10",
@@ -68,5 +68,5 @@
68
68
  "ts-node": "^10.9.1",
69
69
  "typescript": "^5.8.3"
70
70
  },
71
- "gitHead": "02eb740f27e79b4c2545713ae8a938643d553e64"
71
+ "gitHead": "cae5ed7363dca196c50b429e81c3d6c87c11ee39"
72
72
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"genZkeys.d.ts","sourceRoot":"","sources":["../../ts/genZkeys.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,IAAI,CA2CrE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"genZkeys.js","sourceRoot":"","sources":["../../ts/genZkeys.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAkD;AAClD,yCAAgF;AAEhF,4CAAoB;AACpB,gDAAwB;AAIxB;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,UAAmB,EAAiB,EAAE;IACxE,8BAA8B;IAC9B,MAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACvE,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,CAAoB,CAAC;IAC3G,MAAM,kBAAkB,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;IACpF,MAAM,qBAAqB,GAAG,IAAI,CAAC,KAAK,CACtC,MAAM,YAAE,CAAC,QAAQ,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