@maci-protocol/circuits 0.0.0-ci.3dedbc5 → 0.0.0-ci.3ff6873

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 (32) hide show
  1. package/build/ts/types.d.ts +6 -7
  2. package/build/ts/types.d.ts.map +1 -1
  3. package/build/tsconfig.build.tsbuildinfo +1 -1
  4. package/circom/circuits.json +3 -3
  5. package/circom/coordinator/non-qv/processMessages.circom +21 -19
  6. package/circom/coordinator/non-qv/tallyVotes.circom +6 -3
  7. package/circom/coordinator/qv/processMessages.circom +21 -19
  8. package/circom/coordinator/qv/tallyVotes.circom +5 -3
  9. package/circom/utils/{calculateTotal.circom → CalculateTotal.circom} +2 -0
  10. package/circom/utils/{verifySignature.circom → EdDSAPoseidonVerifier.circom} +40 -66
  11. package/circom/utils/MessageHasher.circom +57 -0
  12. package/circom/utils/MessageToCommand.circom +107 -0
  13. package/circom/utils/PoseidonHasher.circom +29 -0
  14. package/circom/utils/{privToPubKey.circom → PrivateToPublicKey.circom} +11 -9
  15. package/circom/utils/VerifySignature.circom +39 -0
  16. package/circom/utils/non-qv/messageValidator.circom +3 -3
  17. package/circom/utils/non-qv/stateLeafAndBallotTransformer.circom +2 -2
  18. package/circom/utils/qv/messageValidator.circom +3 -3
  19. package/circom/utils/qv/stateLeafAndBallotTransformer.circom +2 -2
  20. package/circom/utils/trees/BinaryMerkleRoot.circom +62 -0
  21. package/circom/utils/trees/CheckRoot.circom +49 -0
  22. package/circom/utils/trees/LeafExists.circom +27 -0
  23. package/circom/utils/trees/MerkleGeneratePathIndices.circom +44 -0
  24. package/circom/utils/trees/MerkleTreeInclusionProof.circom +50 -0
  25. package/circom/utils/trees/incrementalQuinaryTree.circom +2 -2
  26. package/circom/voter/PollJoined.circom +43 -0
  27. package/circom/voter/PollJoining.circom +54 -0
  28. package/package.json +11 -10
  29. package/circom/utils/hashers.circom +0 -78
  30. package/circom/utils/messageToCommand.circom +0 -78
  31. package/circom/utils/trees/incrementalMerkleTree.circom +0 -198
  32. 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 computedPrivBits[253] = Num2Bits(253)(privateKey);
31
33
 
32
34
  // Perform scalar multiplication with the basepoint.
33
35
  var computedEscalarMulFix[2] = EscalarMulFix(253, BASE8)(computedPrivBits);
34
36
 
35
- pubKey <== computedEscalarMulFix;
37
+ publicKey <== computedEscalarMulFix;
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
+ }
@@ -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.
@@ -28,7 +28,7 @@ template MessageValidatorNonQv() {
28
28
  // Packed command.
29
29
  signal input cmd[PACKED_CMD_LENGTH];
30
30
  // Public key of the state leaf (user).
31
- signal input pubKey[2];
31
+ signal input publicKey[2];
32
32
  // ECDSA signature of the command (R part).
33
33
  signal input sigR8[2];
34
34
  // ECDSA signature of the command (S part).
@@ -60,7 +60,7 @@ template MessageValidatorNonQv() {
60
60
  var computedIsNonceValid = IsEqual()([originalNonce + 1, nonce]);
61
61
 
62
62
  // Check (4) - The signature must be correct.
63
- var computedIsSignatureValid = VerifySignature()(pubKey, sigR8, sigS, cmd);
63
+ var computedIsSignatureValid = VerifySignature()(publicKey, sigR8, sigS, cmd);
64
64
 
65
65
  // Check (5) - There must be sufficient voice credits.
66
66
  // The check ensure that currentVoiceCreditBalance + (currentVotesForOption) >= (voteWeight).
@@ -85,8 +85,8 @@ template StateLeafAndBallotTransformerNonQv() {
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].
88
+ // This means using a Mux1() for publicKey[0] and another one
89
+ // for publicKey[1].
90
90
  var computedNewSlPubKey0Mux = Mux1()([slPubKey[0], cmdNewPubKey[0]], computedMessageValidator);
91
91
  var computedNewSlPubKey1Mux = Mux1()([slPubKey[1], cmdNewPubKey[1]], computedMessageValidator);
92
92
 
@@ -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.
@@ -28,7 +28,7 @@ template MessageValidator() {
28
28
  // Packed command.
29
29
  signal input cmd[PACKED_CMD_LENGTH];
30
30
  // Public key of the state leaf (user).
31
- signal input pubKey[2];
31
+ signal input publicKey[2];
32
32
  // ECDSA signature of the command (R part).
33
33
  signal input sigR8[2];
34
34
  // ECDSA signature of the command (S part).
@@ -60,7 +60,7 @@ template MessageValidator() {
60
60
  var computedIsNonceValid = IsEqual()([originalNonce + 1, nonce]);
61
61
 
62
62
  // Check (4) - The signature must be correct.
63
- var computedIsSignatureValid = VerifySignature()(pubKey, sigR8, sigS, cmd);
63
+ var computedIsSignatureValid = VerifySignature()(publicKey, sigR8, sigS, cmd);
64
64
 
65
65
  // Check (5) - There must be sufficient voice credits.
66
66
  // The check ensure that the voteWeight is < sqrt(field size)
@@ -85,8 +85,8 @@ template StateLeafAndBallotTransformer() {
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].
88
+ // This means using a Mux1() for publicKey[0] and another one
89
+ // for publicKey[1].
90
90
  var computedNewSlPubKey0Mux = Mux1()([slPubKey[0], cmdNewPubKey[0]], computedMessageValidator);
91
91
  var computedNewSlPubKey1Mux = Mux1()([slPubKey[1], cmdNewPubKey[1]], computedMessageValidator);
92
92
 
@@ -0,0 +1,62 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // circomlib import
4
+ include "./mux1.circom";
5
+ include "./comparators.circom";
6
+ // local import
7
+ include "../PoseidonHasher.circom";
8
+
9
+ // @note taken from @zk-kit/circuits
10
+ // if used directly in processMessages circom complains about duplicated
11
+ // templates (Ark, Poseidon, etc.)
12
+ // This circuit is designed to calculate the root of a binary Merkle
13
+ // tree given a leaf, its depth, and the necessary sibling
14
+ // information (aka proof of membership).
15
+ // A circuit is designed without the capability to iterate through
16
+ // a dynamic array. To address this, a parameter with the static maximum
17
+ // tree depth is defined (i.e. 'MAX_DEPTH'). And additionally, the circuit
18
+ // receives a dynamic depth as an input, which is utilized in calculating the
19
+ // true root of the Merkle tree. The actual depth of the Merkle tree
20
+ // may be equal to or less than the static maximum depth.
21
+ // NOTE: This circuit will successfully verify `out = 0` for `depth > MAX_DEPTH`.
22
+ // Make sure to enforce `depth <= MAX_DEPTH` outside the circuit.
23
+ template BinaryMerkleRoot(MAX_DEPTH) {
24
+ // The leaf node of the Merkle tree.
25
+ signal input leaf;
26
+ // The depth of the Merkle tree.
27
+ signal input depth;
28
+ // The indices of the leaf node in the Merkle tree.
29
+ signal input indices[MAX_DEPTH];
30
+ // The sibling nodes of the leaf node in the Merkle tree.
31
+ signal input siblings[MAX_DEPTH][1];
32
+
33
+ // The output of the Merkle tree root.
34
+ signal output out;
35
+
36
+ signal nodes[MAX_DEPTH + 1];
37
+ nodes[0] <== leaf;
38
+
39
+ signal roots[MAX_DEPTH];
40
+ var root = 0;
41
+
42
+ for (var i = 0; i < MAX_DEPTH; i++) {
43
+ var isDepth = IsEqual()([depth, i]);
44
+
45
+ roots[i] <== isDepth * nodes[i];
46
+
47
+ root += roots[i];
48
+
49
+ var c[2][2] = [
50
+ [nodes[i], siblings[i][0]],
51
+ [siblings[i][0], nodes[i]]
52
+ ];
53
+
54
+ var childNodes[2] = MultiMux1(2)(c, indices[i]);
55
+
56
+ nodes[i + 1] <== PoseidonHasher(2)(childNodes);
57
+ }
58
+
59
+ var isDepth = IsEqual()([depth, MAX_DEPTH]);
60
+
61
+ out <== root + isDepth * nodes[MAX_DEPTH];
62
+ }
@@ -0,0 +1,49 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // local import
4
+ include "../PoseidonHasher.circom";
5
+
6
+ /**
7
+ * Verifies the correct construction of a Merkle tree from a set of leaves.
8
+ * Given a Merkle root and a list of leaves, check if the root is the
9
+ * correct result of inserting all the leaves into the tree (in the given order).
10
+ */
11
+ template CheckRoot(levels) {
12
+ // The total number of leaves in the Merkle tree, calculated as 2 to the power of `levels`.
13
+ var TOTAL_LEVELS = 2 ** levels;
14
+ // The number of first-level hashers needed, equal to half the total leaves, as each hasher combines two leaves.
15
+ var LEAF_HASHERS = TOTAL_LEVELS / 2;
16
+ // The number of intermediate hashers, one less than the number of leaf hashers,
17
+ // as each level of hashing reduces the number of hash elements by about half.
18
+ var INTERMEDIATE_HASHERS = LEAF_HASHERS - 1;
19
+
20
+ // Array of leaf values input to the circuit.
21
+ signal input leaves[TOTAL_LEVELS];
22
+
23
+ // Output signal for the Merkle root that results from hashing all the input leaves.
24
+ signal output root;
25
+
26
+ // Total number of hashers used in constructing the tree, one less than the total number of leaves,
27
+ // since each level of the tree combines two elements into one.
28
+ var hashersLength = TOTAL_LEVELS - 1;
29
+ var computedLevelHashers[hashersLength];
30
+
31
+ // Initialize hashers for the leaves, each taking two adjacent leaves as inputs.
32
+ for (var i = 0; i < LEAF_HASHERS; i++){
33
+ computedLevelHashers[i] = PoseidonHasher(2)([leaves[i * 2], leaves[i * 2 + 1]]);
34
+ }
35
+
36
+ // Initialize hashers for intermediate levels, each taking the outputs of two hashers from the previous level.
37
+ var index = 0;
38
+
39
+ for (var i = LEAF_HASHERS; i < LEAF_HASHERS + INTERMEDIATE_HASHERS; i++) {
40
+ computedLevelHashers[i] = PoseidonHasher(2)([
41
+ computedLevelHashers[index * 2],
42
+ computedLevelHashers[index * 2 + 1]
43
+ ]);
44
+ index++;
45
+ }
46
+
47
+ // Connect the output of the final hasher in the array to the root output signal.
48
+ root <== computedLevelHashers[hashersLength - 1];
49
+ }
@@ -0,0 +1,27 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // local import
4
+ include "./MerkleTreeInclusionProof.circom";
5
+
6
+ /**
7
+ * Ensures that a leaf exists within a Merkle tree with a given root.
8
+ */
9
+ template LeafExists(levels) {
10
+ // The leaf whose existence within the tree is being verified.
11
+ signal input leaf;
12
+
13
+ // The elements along the path needed for the inclusion proof.
14
+ signal input path_elements[levels][1];
15
+ // The indices indicating the path taken through the tree for the leaf.
16
+ signal input path_index[levels];
17
+ // The root of the Merkle tree, against which the inclusion is verified.
18
+ signal input root;
19
+
20
+ var computedMerkleRoot = MerkleTreeInclusionProof(levels)(
21
+ leaf,
22
+ path_index,
23
+ path_elements
24
+ );
25
+
26
+ root === computedMerkleRoot;
27
+ }
@@ -0,0 +1,44 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // zk-kit imports
4
+ include "./safe-comparators.circom";
5
+ // local import
6
+ include "../CalculateTotal.circom";
7
+
8
+ /**
9
+ * Calculates the path indices required for Merkle proof verifications.
10
+ * Given a node index within an IMT and the total tree levels, it outputs the path indices leading to that node.
11
+ * The template handles the modulo and division operations to break down the tree index into its constituent path indices.
12
+ */
13
+ template MerkleGeneratePathIndices(levels) {
14
+ // The base used for the modulo and division operations, set to 2 for binary trees.
15
+ var BASE = 2;
16
+
17
+ // The total sum of the path indices.
18
+ signal input indices;
19
+
20
+ // The generated path indices.
21
+ signal output out[levels];
22
+
23
+ var computedIndices = indices;
24
+ var computedResults[levels];
25
+
26
+ for (var i = 0; i < levels; i++) {
27
+ // circom's best practices suggests to avoid using <-- unless you
28
+ // are aware of what's going on. This is the only way to do modulo operation.
29
+ out[i] <-- computedIndices % BASE;
30
+ computedIndices = computedIndices \ BASE;
31
+
32
+ // Check that each output element is less than the base.
33
+ var computedIsOutputElementLessThanBase = SafeLessThan(3)([out[i], BASE]);
34
+ computedIsOutputElementLessThanBase === 1;
35
+
36
+ // Re-compute the total sum.
37
+ computedResults[i] = out[i] * (BASE ** i);
38
+ }
39
+
40
+ // Check that the total sum matches the index.
41
+ var computedCalculateTotal = CalculateTotal(levels)(computedResults);
42
+
43
+ computedCalculateTotal === indices;
44
+ }
@@ -0,0 +1,50 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // circomlib import
4
+ include "./mux1.circom";
5
+ // local import
6
+ include "../PoseidonHasher.circom";
7
+
8
+ /**
9
+ * Recomputes a Merkle root from a given leaf and its path in a Merkle tree.
10
+ */
11
+ template MerkleTreeInclusionProof(n_levels) {
12
+ // The leaf node from which the Merkle root is calculated.
13
+ signal input leaf;
14
+ // Indices indicating left or right child for each level of the tree.
15
+ signal input path_index[n_levels];
16
+ // Sibling node values required to compute the hash at each level.
17
+ signal input path_elements[n_levels][1];
18
+
19
+ // The merkle root.
20
+ signal output root;
21
+
22
+ // Stores the hash at each level starting from the leaf to the root.
23
+ signal levelHashes[n_levels + 1];
24
+ // Initialize the first level with the given leaf.
25
+ levelHashes[0] <== leaf;
26
+
27
+ for (var i = 0; i < n_levels; i++) {
28
+ // Validate path_index to be either 0 or 1, ensuring no other values.
29
+ path_index[i] * (1 - path_index[i]) === 0;
30
+
31
+ // Configure the multiplexer based on the path index for the current level.
32
+ var multiplexer[2][2] = [
33
+ [levelHashes[i], path_elements[i][0]],
34
+ [path_elements[i][0], levelHashes[i]]
35
+ ];
36
+
37
+ var multiplexerResult[2] = MultiMux1(2)(
38
+ multiplexer,
39
+ path_index[i]
40
+ );
41
+
42
+ var computedLevelHash = PoseidonHasher(2)([multiplexerResult[0], multiplexerResult[1]]);
43
+
44
+ // Store the resulting hash as the next level's hash.
45
+ levelHashes[i + 1] <== computedLevelHash;
46
+ }
47
+
48
+ // Set the final level hash as the root.
49
+ root <== levelHashes[n_levels];
50
+ }
@@ -6,8 +6,8 @@ include "./mux1.circom";
6
6
  // zk-kit import
7
7
  include "./safe-comparators.circom";
8
8
  // local imports
9
- include "../calculateTotal.circom";
10
- include "../hashers.circom";
9
+ include "../CalculateTotal.circom";
10
+ include "../PoseidonHasher.circom";
11
11
 
12
12
  // Incremental Quintary Merkle Tree (IQT) verification circuits.
13
13
  // Since each node contains 5 leaves, we are using PoseidonT6 for hashing them.
@@ -0,0 +1,43 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // local imports
4
+ include "../utils/PoseidonHasher.circom";
5
+ include "../utils/PrivateToPublicKey.circom";
6
+ include "../utils/trees/BinaryMerkleRoot.circom";
7
+
8
+ // Poll Joined Circuit
9
+ // Allows a user to prove that they have joined a MACI poll.
10
+ // This is to be used with the MACI offchain implementation to allow
11
+ // users to authenticate to the relayer service (to reduce spamming).
12
+ template PollJoined(stateTreeDepth) {
13
+ // Constants defining the tree structure
14
+ var STATE_TREE_ARITY = 2;
15
+
16
+ // User's private key
17
+ signal input privateKey;
18
+ // User's voice credits balance
19
+ signal input voiceCreditsBalance;
20
+ // Path elements
21
+ signal input pathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
22
+ // Path indices
23
+ signal input pathIndices[stateTreeDepth];
24
+ // Poll State tree root which proves the user is joined
25
+ signal input stateRoot;
26
+ // The actual tree depth (might be <= stateTreeDepth) Used in BinaryMerkleRoot
27
+ signal input actualStateTreeDepth;
28
+
29
+ // User private to public key
30
+ var derivedPublicKey[2] = PrivateToPublicKey()(privateKey);
31
+
32
+ var stateLeaf = PoseidonHasher(3)([derivedPublicKey[0], derivedPublicKey[1], voiceCreditsBalance]);
33
+
34
+ // Inclusion proof
35
+ var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
36
+ stateLeaf,
37
+ actualStateTreeDepth,
38
+ pathIndices,
39
+ pathElements
40
+ );
41
+
42
+ stateLeafQip === stateRoot;
43
+ }
@@ -0,0 +1,54 @@
1
+ pragma circom 2.0.0;
2
+
3
+ // local imports
4
+ include "../utils/PoseidonHasher.circom";
5
+ include "../utils/PrivateToPublicKey.circom";
6
+ include "../utils/trees/BinaryMerkleRoot.circom";
7
+
8
+ // Poll Joining Circuit
9
+ // Allows a user to prove knowledge of a private key that is signed up to
10
+ // a MACI contract.
11
+ template PollJoining(stateTreeDepth) {
12
+ // Constants defining the tree structure
13
+ var STATE_TREE_ARITY = 2;
14
+
15
+ // User's private key
16
+ signal input privateKey;
17
+ // Poll's public key
18
+ signal input pollPublicKey[2];
19
+ // Siblings
20
+ signal input siblings[stateTreeDepth][STATE_TREE_ARITY - 1];
21
+ // Indices
22
+ signal input indices[stateTreeDepth];
23
+ // User's hashed private key
24
+ signal input nullifier;
25
+ // MACI State tree root which proves the user is signed up
26
+ signal input stateRoot;
27
+ // The actual tree depth (might be <= stateTreeDepth) used in BinaryMerkleRoot
28
+ signal input actualStateTreeDepth;
29
+ // The poll id
30
+ signal input pollId;
31
+
32
+ // Compute the nullifier (hash of private key and poll id)
33
+ var computedNullifier = PoseidonHasher(2)([privateKey, pollId]);
34
+ nullifier === computedNullifier;
35
+
36
+ // User private to public key
37
+ var derivedPublicKey[2] = PrivateToPublicKey()(privateKey);
38
+ // Hash the public key
39
+ var publicKeyHash = PoseidonHasher(2)([derivedPublicKey[0], derivedPublicKey[1]]);
40
+
41
+ // Ensure the poll public key is the same as the maci one (public input)
42
+ derivedPublicKey[0] === pollPublicKey[0];
43
+ derivedPublicKey[1] === pollPublicKey[1];
44
+
45
+ // Inclusion proof
46
+ var calculatedRoot = BinaryMerkleRoot(stateTreeDepth)(
47
+ publicKeyHash,
48
+ actualStateTreeDepth,
49
+ indices,
50
+ siblings
51
+ );
52
+
53
+ calculatedRoot === stateRoot;
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maci-protocol/circuits",
3
- "version": "0.0.0-ci.3dedbc5",
3
+ "version": "0.0.0-ci.3ff6873",
4
4
  "private": false,
5
5
  "description": "zk-SNARK circuits for MACI",
6
6
  "main": "build/ts/index.js",
@@ -28,12 +28,13 @@
28
28
  "mocha-test": "NODE_OPTIONS=--max-old-space-size=4096 ts-mocha --exit -g '^(?!.*\\[fuzz\\]).*$'",
29
29
  "test": "pnpm run mocha-test ts/__tests__/*.test.ts",
30
30
  "test:fuzz": "NODE_OPTIONS=--max-old-space-size=4096 ts-mocha --exit -g '\\[fuzz\\]' ./ts/__tests__/*.test.ts",
31
- "test:hasher": "pnpm run mocha-test ts/__tests__/Hasher.test.ts",
31
+ "test:poseidonHasher": "pnpm run mocha-test ts/__tests__/PoseidonHasher.test.ts",
32
+ "test:messageHasher": "pnpm run mocha-test ts/__tests__/MessageHasher.test.ts",
32
33
  "test:slAndBallotTransformer": "pnpm run mocha-test ts/__tests__/StateLeafAndBallotTransformer.test.ts",
33
34
  "test:messageToCommand": "pnpm run mocha-test ts/__tests__/MessageToCommand.test.ts",
34
35
  "test:messageValidator": "pnpm run mocha-test ts/__tests__/MessageValidator.test.ts",
35
36
  "test:verifySignature": "pnpm run mocha-test ts/__tests__/VerifySignature.test.ts",
36
- "test:privToPubKey": "pnpm run mocha-test ts/__tests__/PrivToPubKey.test.ts",
37
+ "test:privateToPublicKey": "pnpm run mocha-test ts/__tests__/PrivateToPublicKey.test.ts",
37
38
  "test:calculateTotal": "pnpm run mocha-test ts/__tests__/CalculateTotal.test.ts",
38
39
  "test:processMessages": "pnpm run mocha-test ts/__tests__/ProcessMessages.test.ts",
39
40
  "test:tallyVotes": "pnpm run mocha-test ts/__tests__/TallyVotes.test.ts",
@@ -43,10 +44,10 @@
43
44
  "test:pollJoined": "pnpm run mocha-test ts/__tests__/PollJoined.test.ts"
44
45
  },
45
46
  "dependencies": {
46
- "@maci-protocol/core": "0.0.0-ci.3dedbc5",
47
- "@maci-protocol/crypto": "0.0.0-ci.3dedbc5",
48
- "@maci-protocol/domainobjs": "0.0.0-ci.3dedbc5",
49
- "@maci-protocol/sdk": "0.0.0-ci.3dedbc5",
47
+ "@maci-protocol/core": "0.0.0-ci.3ff6873",
48
+ "@maci-protocol/crypto": "0.0.0-ci.3ff6873",
49
+ "@maci-protocol/domainobjs": "0.0.0-ci.3ff6873",
50
+ "@maci-protocol/sdk": "0.0.0-ci.3ff6873",
50
51
  "@zk-kit/circuits": "^0.4.0",
51
52
  "circomkit": "^0.3.2",
52
53
  "circomlib": "^2.0.5"
@@ -60,12 +61,12 @@
60
61
  "@zk-kit/baby-jubjub": "^1.0.3",
61
62
  "chai": "^4.3.10",
62
63
  "chai-as-promised": "^7.1.2",
63
- "fast-check": "^4.0.0",
64
+ "fast-check": "^4.1.1",
64
65
  "glob": "^11.0.1",
65
66
  "mocha": "^11.1.0",
66
67
  "ts-mocha": "^11.1.0",
67
68
  "ts-node": "^10.9.1",
68
- "typescript": "^5.8.2"
69
+ "typescript": "^5.8.3"
69
70
  },
70
- "gitHead": "ef701a2ae278f54e95f8112974b77fd6742429f8"
71
+ "gitHead": "23a575cd7bd2acb5136aee338b252239be603c1c"
71
72
  }
@@ -1,78 +0,0 @@
1
- pragma circom 2.0.0;
2
-
3
- // zk-kit imports
4
- include "./poseidon-cipher.circom";
5
-
6
- /**
7
- * Computes the Poseidon hash for an array of n inputs, including a default initial state
8
- * of zero not counted in n. First, extends the inputs by prepending a zero, creating an array [0, inputs].
9
- * Then, the Poseidon hash of the extended inputs is calculated, with the first element of the
10
- * result assigned as the output.
11
- */
12
- template PoseidonHasher(n) {
13
- signal input inputs[n];
14
- signal output out;
15
-
16
- // [0, inputs].
17
- var computedExtendedInputs[n + 1];
18
- computedExtendedInputs[0] = 0;
19
-
20
- for (var i = 0; i < n; i++) {
21
- computedExtendedInputs[i + 1] = inputs[i];
22
- }
23
-
24
- // Compute the Poseidon hash of the extended inputs.
25
- var computedPoseidonPerm[n + 1];
26
- computedPoseidonPerm = PoseidonPerm(n + 1)(computedExtendedInputs);
27
-
28
- out <== computedPoseidonPerm[0];
29
- }
30
-
31
- /**
32
- * Hashes a MACI message and the public key used for message encryption.
33
- * This template processes 10 message inputs and a 2-element public key
34
- * combining them using the Poseidon hash function. The hashing process involves two stages:
35
- * 1. hashing message parts in groups of five and,
36
- * 2. hashing the grouped results alongside the first message input and
37
- * the encryption public key to produce a final hash output.
38
- */
39
- template MessageHasher() {
40
- // The MACI message is composed of 10 parts.
41
- signal input in[10];
42
- // the public key used to encrypt the message.
43
- signal input encPubKey[2];
44
- // we output an hash.
45
- signal output hash;
46
-
47
- // Hasher4(
48
- // Hasher5_1(in[1], in[2], in[3], in[4], in[5]),
49
- // Hasher5_2(in[6], in[7], in[8], in[9], in[10])
50
- // in[11],
51
- // in[12]
52
- // )
53
-
54
- var computedHasher5_1;
55
- computedHasher5_1 = PoseidonHasher(5)([
56
- in[0],
57
- in[1],
58
- in[2],
59
- in[3],
60
- in[4]
61
- ]);
62
-
63
- var computedHasher5_2;
64
- computedHasher5_2 = PoseidonHasher(5)([
65
- in[5],
66
- in[6],
67
- in[7],
68
- in[8],
69
- in[9]
70
- ]);
71
-
72
- hash <== PoseidonHasher(4)([
73
- computedHasher5_1,
74
- computedHasher5_2,
75
- encPubKey[0],
76
- encPubKey[1]
77
- ]);
78
- }