@maci-protocol/circuits 0.0.0-ci.044d30d → 0.0.0-ci.0bef05d
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/ts/{genZkeys.d.ts → generateZkeys.d.ts} +1 -1
- package/build/ts/generateZkeys.d.ts.map +1 -0
- package/build/ts/{genZkeys.js → generateZkeys.js} +1 -1
- package/build/ts/generateZkeys.js.map +1 -0
- package/build/ts/types.d.ts +8 -8
- package/build/ts/types.d.ts.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/circom/circuits.json +7 -7
- package/circom/coordinator/non-qv/processMessages.circom +92 -95
- package/circom/coordinator/non-qv/tallyVotes.circom +35 -32
- package/circom/coordinator/qv/processMessages.circom +94 -94
- package/circom/coordinator/qv/tallyVotes.circom +37 -37
- package/circom/utils/{calculateTotal.circom → CalculateTotal.circom} +2 -0
- package/circom/utils/{verifySignature.circom → EdDSAPoseidonVerifier.circom} +40 -66
- package/circom/utils/MessageHasher.circom +57 -0
- package/circom/utils/MessageToCommand.circom +107 -0
- package/circom/utils/PoseidonHasher.circom +29 -0
- package/circom/utils/{privToPubKey.circom → PrivateToPublicKey.circom} +11 -9
- package/circom/utils/VerifySignature.circom +39 -0
- package/circom/utils/non-qv/{messageValidator.circom → MessageValidator.circom} +13 -11
- package/circom/utils/non-qv/{stateLeafAndBallotTransformer.circom → StateLeafAndBallotTransformer.circom} +32 -32
- package/circom/utils/qv/{messageValidator.circom → MessageValidator.circom} +13 -11
- package/circom/utils/qv/{stateLeafAndBallotTransformer.circom → StateLeafAndBallotTransformer.circom} +32 -32
- package/circom/utils/trees/BinaryMerkleRoot.circom +11 -3
- package/circom/utils/trees/CheckRoot.circom +18 -14
- package/circom/utils/trees/LeafExists.circom +1 -1
- package/circom/utils/trees/{MerkleGeneratePathIndices.circom → MerklePathIndicesGenerator.circom} +11 -7
- package/circom/utils/trees/MerkleTreeInclusionProof.circom +6 -5
- package/circom/utils/trees/incrementalQuinaryTree.circom +2 -2
- package/circom/voter/PollJoined.circom +43 -0
- package/circom/voter/PollJoining.circom +54 -0
- package/package.json +12 -11
- package/build/ts/genZkeys.d.ts.map +0 -1
- package/build/ts/genZkeys.js.map +0 -1
- package/circom/utils/hashers.circom +0 -78
- package/circom/utils/messageToCommand.circom +0 -78
- package/circom/voter/poll.circom +0 -92
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
pragma circom 2.0.0;
|
|
2
|
-
|
|
3
|
-
// circomlib import
|
|
4
|
-
include "./bitify.circom";
|
|
5
|
-
// zk-kit imports
|
|
6
|
-
include "./ecdh.circom";
|
|
7
|
-
include "./unpack-element.circom";
|
|
8
|
-
include "./poseidon-cipher.circom";
|
|
9
|
-
// local imports
|
|
10
|
-
include "./hashers.circom";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Converts a MACI message to a command by decrypting it.
|
|
14
|
-
* Processes encrypted MACI messages into structured MACI commands
|
|
15
|
-
* by decrypting using a shared key derived from ECDH. After decryption,
|
|
16
|
-
* unpacks and assigns decrypted values to specific command components.
|
|
17
|
-
*/
|
|
18
|
-
template MessageToCommand() {
|
|
19
|
-
var MSG_LENGTH = 7;
|
|
20
|
-
var PACKED_CMD_LENGTH = 4;
|
|
21
|
-
var UNPACKED_CMD_LENGTH = 8;
|
|
22
|
-
var UNPACK_ELEM_LENGTH = 5;
|
|
23
|
-
var DECRYPTED_LENGTH = 9;
|
|
24
|
-
var MESSAGE_PARTS = 10;
|
|
25
|
-
|
|
26
|
-
// The message is an array of 10 parts.
|
|
27
|
-
signal input message[MESSAGE_PARTS];
|
|
28
|
-
signal input encPrivKey;
|
|
29
|
-
signal input encPubKey[2];
|
|
30
|
-
|
|
31
|
-
// Command parts.
|
|
32
|
-
signal output stateIndex;
|
|
33
|
-
signal output newPubKey[2];
|
|
34
|
-
signal output voteOptionIndex;
|
|
35
|
-
signal output newVoteWeight;
|
|
36
|
-
signal output nonce;
|
|
37
|
-
signal output pollId;
|
|
38
|
-
signal output salt;
|
|
39
|
-
signal output sigR8[2];
|
|
40
|
-
signal output sigS;
|
|
41
|
-
// Packed command.
|
|
42
|
-
signal output packedCommandOut[PACKED_CMD_LENGTH];
|
|
43
|
-
|
|
44
|
-
// Generate the shared key for decrypting the message.
|
|
45
|
-
var computedEcdh[2] = Ecdh()(encPrivKey, encPubKey);
|
|
46
|
-
|
|
47
|
-
// Decrypt the message using Poseidon decryption.
|
|
48
|
-
var computedDecryptor[DECRYPTED_LENGTH] = PoseidonDecryptWithoutCheck(MSG_LENGTH)(
|
|
49
|
-
message,
|
|
50
|
-
0,
|
|
51
|
-
computedEcdh
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// Save the decrypted message into a packed command signal.
|
|
55
|
-
signal packedCommand[PACKED_CMD_LENGTH];
|
|
56
|
-
for (var i = 0; i < PACKED_CMD_LENGTH; i++) {
|
|
57
|
-
packedCommand[i] <== computedDecryptor[i];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
var computedUnpackElement[UNPACK_ELEM_LENGTH] = UnpackElement(UNPACK_ELEM_LENGTH)(packedCommand[0]);
|
|
61
|
-
|
|
62
|
-
// Everything below were packed into the first element.
|
|
63
|
-
stateIndex <== computedUnpackElement[4];
|
|
64
|
-
voteOptionIndex <== computedUnpackElement[3];
|
|
65
|
-
newVoteWeight <== computedUnpackElement[2];
|
|
66
|
-
nonce <== computedUnpackElement[1];
|
|
67
|
-
pollId <== computedUnpackElement[0];
|
|
68
|
-
|
|
69
|
-
newPubKey[0] <== packedCommand[1];
|
|
70
|
-
newPubKey[1] <== packedCommand[2];
|
|
71
|
-
salt <== packedCommand[3];
|
|
72
|
-
|
|
73
|
-
sigR8[0] <== computedDecryptor[4];
|
|
74
|
-
sigR8[1] <== computedDecryptor[5];
|
|
75
|
-
sigS <== computedDecryptor[6];
|
|
76
|
-
|
|
77
|
-
packedCommandOut <== packedCommand;
|
|
78
|
-
}
|
package/circom/voter/poll.circom
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
pragma circom 2.0.0;
|
|
2
|
-
|
|
3
|
-
// local imports
|
|
4
|
-
include "../utils/hashers.circom";
|
|
5
|
-
include "../utils/privToPubKey.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 privKey;
|
|
17
|
-
// Poll's public key
|
|
18
|
-
signal input pollPubKey[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)([privKey, pollId]);
|
|
34
|
-
nullifier === computedNullifier;
|
|
35
|
-
|
|
36
|
-
// User private to public key
|
|
37
|
-
var derivedPubKey[2] = PrivToPubKey()(privKey);
|
|
38
|
-
// Hash the public key
|
|
39
|
-
var pubKeyHash = PoseidonHasher(2)([derivedPubKey[0], derivedPubKey[1]]);
|
|
40
|
-
|
|
41
|
-
// Ensure the poll public key is the same as the maci one (public input)
|
|
42
|
-
derivedPubKey[0] === pollPubKey[0];
|
|
43
|
-
derivedPubKey[1] === pollPubKey[1];
|
|
44
|
-
|
|
45
|
-
// Inclusion proof
|
|
46
|
-
var calculatedRoot = BinaryMerkleRoot(stateTreeDepth)(
|
|
47
|
-
pubKeyHash,
|
|
48
|
-
actualStateTreeDepth,
|
|
49
|
-
indices,
|
|
50
|
-
siblings
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
calculatedRoot === stateRoot;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Poll Joined Circuit
|
|
57
|
-
// Allows a user to prove that they have joined a MACI poll.
|
|
58
|
-
// This is to be used with the MACI offchain implementation to allow
|
|
59
|
-
// users to authenticate to the relayer service (to reduce spamming).
|
|
60
|
-
template PollJoined(stateTreeDepth) {
|
|
61
|
-
// Constants defining the tree structure
|
|
62
|
-
var STATE_TREE_ARITY = 2;
|
|
63
|
-
|
|
64
|
-
// User's private key
|
|
65
|
-
signal input privKey;
|
|
66
|
-
// User's voice credits balance
|
|
67
|
-
signal input voiceCreditsBalance;
|
|
68
|
-
// Path elements
|
|
69
|
-
signal input pathElements[stateTreeDepth][STATE_TREE_ARITY - 1];
|
|
70
|
-
// Path indices
|
|
71
|
-
signal input pathIndices[stateTreeDepth];
|
|
72
|
-
// Poll State tree root which proves the user is joined
|
|
73
|
-
signal input stateRoot;
|
|
74
|
-
// The actual tree depth (might be <= stateTreeDepth) Used in BinaryMerkleRoot
|
|
75
|
-
signal input actualStateTreeDepth;
|
|
76
|
-
|
|
77
|
-
// User private to public key
|
|
78
|
-
var derivedPubKey[2] = PrivToPubKey()(privKey);
|
|
79
|
-
|
|
80
|
-
var stateLeaf = PoseidonHasher(3)([derivedPubKey[0], derivedPubKey[1], voiceCreditsBalance]);
|
|
81
|
-
|
|
82
|
-
// Inclusion proof
|
|
83
|
-
var stateLeafQip = BinaryMerkleRoot(stateTreeDepth)(
|
|
84
|
-
stateLeaf,
|
|
85
|
-
actualStateTreeDepth,
|
|
86
|
-
pathIndices,
|
|
87
|
-
pathElements
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
stateLeafQip === stateRoot;
|
|
91
|
-
}
|
|
92
|
-
|