@crisp-e3/contracts 0.5.6 → 0.5.8
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.
|
@@ -10,7 +10,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
|
|
10
10
|
import { IE3Program } from "@enclave-e3/contracts/contracts/interfaces/IE3Program.sol";
|
|
11
11
|
import { IEnclave } from "@enclave-e3/contracts/contracts/interfaces/IEnclave.sol";
|
|
12
12
|
import { E3 } from "@enclave-e3/contracts/contracts/interfaces/IE3.sol";
|
|
13
|
-
import { LazyIMTData, InternalLazyIMT
|
|
13
|
+
import { LazyIMTData, InternalLazyIMT } from "@zk-kit/lazy-imt.sol/InternalLazyIMT.sol";
|
|
14
14
|
import { HonkVerifier } from "./CRISPVerifier.sol";
|
|
15
15
|
|
|
16
16
|
contract CRISPProgram is IE3Program, Ownable {
|
|
@@ -53,9 +53,10 @@ contract CRISPProgram is IE3Program, Ownable {
|
|
|
53
53
|
error MerkleRootAlreadySet();
|
|
54
54
|
error InvalidTallyLength();
|
|
55
55
|
error SlotIsEmpty();
|
|
56
|
+
error MerkleRootNotSet();
|
|
56
57
|
|
|
57
58
|
// Events
|
|
58
|
-
event InputPublished(uint256 indexed e3Id, bytes
|
|
59
|
+
event InputPublished(uint256 indexed e3Id, bytes encryptedVote, uint256 index);
|
|
59
60
|
|
|
60
61
|
/// @notice Initialize the contract, binding it to a specified RISC Zero verifier.
|
|
61
62
|
/// @param _enclave The enclave address
|
|
@@ -123,32 +124,35 @@ contract CRISPProgram is IE3Program, Ownable {
|
|
|
123
124
|
if (!authorizedContracts[msg.sender] && msg.sender != owner()) revert CallerNotAuthorized();
|
|
124
125
|
|
|
125
126
|
// We need to ensure that the CRISP admin set the merkle root of the census.
|
|
126
|
-
|
|
127
|
-
// if (e3Data[e3Id].merkleRoot == 0) revert MerkleRootNotSet();
|
|
127
|
+
if (e3Data[e3Id].merkleRoot == 0) revert MerkleRootNotSet();
|
|
128
128
|
|
|
129
129
|
if (data.length == 0) revert EmptyInputData();
|
|
130
130
|
|
|
131
|
-
(bytes memory noirProof, bytes32
|
|
131
|
+
(bytes memory noirProof, address slotAddress, bytes32 encryptedVoteCommitment, bytes memory encryptedVote) = abi.decode(
|
|
132
|
+
data,
|
|
133
|
+
(bytes, address, bytes32, bytes)
|
|
134
|
+
);
|
|
132
135
|
|
|
133
|
-
|
|
136
|
+
(uint40 voteIndex, bytes32 previousEncryptedVoteCommitment) = _processVote(e3Id, slotAddress, encryptedVoteCommitment);
|
|
134
137
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// Set public inputs for the proof. Order must match Noir circuit.
|
|
138
|
-
bytes32[] memory noirPublicInputs = new bytes32[](2 + vote.length);
|
|
138
|
+
// Fetch E3 to get committee public key
|
|
139
|
+
E3 memory e3 = enclave.getE3(e3Id);
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
// Set the public inputs for the proof. Order must match Noir circuit.
|
|
142
|
+
bytes32[] memory noirPublicInputs = new bytes32[](6);
|
|
143
|
+
noirPublicInputs[0] = previousEncryptedVoteCommitment;
|
|
144
|
+
noirPublicInputs[1] = e3.committeePublicKey;
|
|
145
|
+
noirPublicInputs[2] = bytes32(e3Data[e3Id].merkleRoot);
|
|
146
|
+
noirPublicInputs[3] = bytes32(uint256(uint160(slotAddress)));
|
|
147
|
+
noirPublicInputs[4] = bytes32(uint256(previousEncryptedVoteCommitment == bytes32(0) ? 1 : 0));
|
|
148
|
+
noirPublicInputs[5] = encryptedVoteCommitment;
|
|
145
149
|
|
|
146
150
|
// Check if the ciphertext was encrypted correctly
|
|
147
151
|
if (!honkVerifier.verify(noirProof, noirPublicInputs)) {
|
|
148
152
|
revert InvalidNoirProof();
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
emit InputPublished(e3Id,
|
|
155
|
+
emit InputPublished(e3Id, encryptedVote, voteIndex);
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
/// @notice Decode the tally from the plaintext output
|
|
@@ -215,22 +219,26 @@ contract CRISPProgram is IE3Program, Ownable {
|
|
|
215
219
|
|
|
216
220
|
/// @notice Process a vote: insert or update in the merkle tree depending
|
|
217
221
|
/// on whether it's the first vote or an override.
|
|
218
|
-
function _processVote(
|
|
222
|
+
function _processVote(
|
|
223
|
+
uint256 e3Id,
|
|
224
|
+
address slotAddress,
|
|
225
|
+
bytes32 encryptedVoteCommitment
|
|
226
|
+
) internal returns (uint40 voteIndex, bytes32 previousEncryptedVoteCommitment) {
|
|
219
227
|
uint40 storedIndexPlusOne = e3Data[e3Id].voteSlots[slotAddress];
|
|
220
228
|
|
|
221
229
|
// we treat the index 0 as not voted yet
|
|
222
230
|
// any valid index will be index + 1
|
|
223
231
|
if (storedIndexPlusOne == 0) {
|
|
224
232
|
// FIRST VOTE
|
|
225
|
-
|
|
233
|
+
previousEncryptedVoteCommitment = bytes32(0);
|
|
226
234
|
voteIndex = e3Data[e3Id].votes.numberOfLeaves;
|
|
227
235
|
e3Data[e3Id].voteSlots[slotAddress] = voteIndex + 1;
|
|
228
|
-
e3Data[e3Id].votes._insert(
|
|
236
|
+
e3Data[e3Id].votes._insert(uint256(encryptedVoteCommitment));
|
|
229
237
|
} else {
|
|
230
238
|
// RE-VOTE
|
|
231
|
-
isFirstVote = false;
|
|
232
239
|
voteIndex = storedIndexPlusOne - 1;
|
|
233
|
-
e3Data[e3Id].votes.
|
|
240
|
+
previousEncryptedVoteCommitment = bytes32(e3Data[e3Id].votes.elements[voteIndex]);
|
|
241
|
+
e3Data[e3Id].votes._update(uint256(encryptedVoteCommitment), voteIndex);
|
|
234
242
|
}
|
|
235
243
|
}
|
|
236
244
|
|
|
@@ -7,85 +7,85 @@ pragma solidity >=0.8.21;
|
|
|
7
7
|
|
|
8
8
|
uint256 constant N = 262144;
|
|
9
9
|
uint256 constant LOG_N = 18;
|
|
10
|
-
uint256 constant NUMBER_OF_PUBLIC_INPUTS =
|
|
11
|
-
uint256 constant VK_HASH =
|
|
10
|
+
uint256 constant NUMBER_OF_PUBLIC_INPUTS = 22;
|
|
11
|
+
uint256 constant VK_HASH = 0x0d53ba57f65358b21e53cf07b91c27906ac4d24b9205fda35494e1a44ba7242a;
|
|
12
12
|
library HonkVerificationKey {
|
|
13
13
|
function loadVerificationKey() internal pure returns (Honk.VerificationKey memory) {
|
|
14
14
|
Honk.VerificationKey memory vk = Honk.VerificationKey({
|
|
15
15
|
circuitSize: uint256(262144),
|
|
16
16
|
logCircuitSize: uint256(18),
|
|
17
|
-
publicInputsSize: uint256(
|
|
17
|
+
publicInputsSize: uint256(22),
|
|
18
18
|
ql: Honk.G1Point({
|
|
19
|
-
x: uint256(
|
|
20
|
-
y: uint256(
|
|
19
|
+
x: uint256(0x112a6aa13787457ce92f268d8f6719287c1add28a224712ea3e2e7d96e2bc70b),
|
|
20
|
+
y: uint256(0x14dcf6e306f1dc722638d4984332053df53689114040ccd69d5926f485219e15)
|
|
21
21
|
}),
|
|
22
22
|
qr: Honk.G1Point({
|
|
23
|
-
x: uint256(
|
|
24
|
-
y: uint256(
|
|
23
|
+
x: uint256(0x22a648530332803c4a992d98fd94a036c8ff1341c3d0ba385210b8851049206c),
|
|
24
|
+
y: uint256(0x0b891280448cdaee82da9caec22fb4820e3140558570c252669508b4f90fba2b)
|
|
25
25
|
}),
|
|
26
26
|
qo: Honk.G1Point({
|
|
27
|
-
x: uint256(
|
|
28
|
-
y: uint256(
|
|
27
|
+
x: uint256(0x1ca6c37b9177a348c574f214e0683da82632df5c0d10addde3f372cda3f8978a),
|
|
28
|
+
y: uint256(0x22ce8ff67ba39a26d4ad603fbe668d9eb3f34f80b4e21e5cbf421d873f6ca040)
|
|
29
29
|
}),
|
|
30
30
|
q4: Honk.G1Point({
|
|
31
|
-
x: uint256(
|
|
32
|
-
y: uint256(
|
|
31
|
+
x: uint256(0x0af0446ba584e461430e07a1f990aaee46d7b5088ad9f54d4a1350d57fa37ab6),
|
|
32
|
+
y: uint256(0x152ab3b635c7f88c62d6bb37fdff5bed5e42e01e0f9894058c10deea1994e4ef)
|
|
33
33
|
}),
|
|
34
34
|
qm: Honk.G1Point({
|
|
35
|
-
x: uint256(
|
|
36
|
-
y: uint256(
|
|
35
|
+
x: uint256(0x2493bb0b6575f4240fa4ca66ab503effe7ad653c552cfe608e662e18e8ce5eb8),
|
|
36
|
+
y: uint256(0x1b5829dbe6ee24d5f1a776ddc4e27a90888310a3f384fe8f70cd86c2f9eebf7e)
|
|
37
37
|
}),
|
|
38
38
|
qc: Honk.G1Point({
|
|
39
|
-
x: uint256(
|
|
40
|
-
y: uint256(
|
|
39
|
+
x: uint256(0x2ccaa4f079bfc85f3887807ba17bffd69c73402d557395f6730d31cf1f208e53),
|
|
40
|
+
y: uint256(0x11e38adba343d4c9839c5b4ed4d54c38d7d0e17b0c3890add1544aa18a53f805)
|
|
41
41
|
}),
|
|
42
42
|
qLookup: Honk.G1Point({
|
|
43
|
-
x: uint256(
|
|
44
|
-
y: uint256(
|
|
43
|
+
x: uint256(0x111ada27d4243c5df982e1cd77f2d9aff394ba4f2ba2faf8ec1a8e5b6d78d1e7),
|
|
44
|
+
y: uint256(0x1cf81a5fe339ef18222213e43155e149d0211317fe0a68d795681f31ef25ad0f)
|
|
45
45
|
}),
|
|
46
46
|
qArith: Honk.G1Point({
|
|
47
|
-
x: uint256(
|
|
48
|
-
y: uint256(
|
|
47
|
+
x: uint256(0x2771f716f503f8552b69271a62ec8cd7ab492b67f4859d8ff0321ce075e0361e),
|
|
48
|
+
y: uint256(0x0a7762803ccc6145a73d9df81cb83b8d7125f07f998525b8ec888bb39ff32658)
|
|
49
49
|
}),
|
|
50
50
|
qDeltaRange: Honk.G1Point({
|
|
51
|
-
x: uint256(
|
|
52
|
-
y: uint256(
|
|
51
|
+
x: uint256(0x0188abc30c433d60b371a87b89bef69474c4de9748b2b4b4e01d3e423cc2e975),
|
|
52
|
+
y: uint256(0x2bbddad8b0e16ca7d71b0ca54b0f6251ea7c4457d76ba3327982171026423a40)
|
|
53
53
|
}),
|
|
54
54
|
qElliptic: Honk.G1Point({
|
|
55
|
-
x: uint256(
|
|
56
|
-
y: uint256(
|
|
55
|
+
x: uint256(0x1a2e2850cfbe3912c8f6a4c0099bc93bc50841ce22d665b83b081753ce664a24),
|
|
56
|
+
y: uint256(0x1976524b69c879a83c4d704ff5cb39397679528681ad378e6753e8b63457c40e)
|
|
57
57
|
}),
|
|
58
58
|
qMemory: Honk.G1Point({
|
|
59
|
-
x: uint256(
|
|
60
|
-
y: uint256(
|
|
59
|
+
x: uint256(0x2e569e263fc7a1cfa7b839e1d01a24bb6e07a396cbe93280eaa5f428f9bfcda3),
|
|
60
|
+
y: uint256(0x232683b772e71e0839c2c22a0325540c142df09d86ad281e95c9a8526c8a8b1d)
|
|
61
61
|
}),
|
|
62
62
|
qNnf: Honk.G1Point({
|
|
63
|
-
x: uint256(
|
|
64
|
-
y: uint256(
|
|
63
|
+
x: uint256(0x21cdfcabf16e6fa296718413cc974b48e44c715143907a9c5cc722aa737b74b0),
|
|
64
|
+
y: uint256(0x2280bd00b21340373b65aa88a619fa5f770435b772e1620701f76d769d041ea4)
|
|
65
65
|
}),
|
|
66
66
|
qPoseidon2External: Honk.G1Point({
|
|
67
|
-
x: uint256(
|
|
68
|
-
y: uint256(
|
|
67
|
+
x: uint256(0x0e5cb0521c16b7e51540251b51adb95e4ce6d507a75c32e0c33377c21853d058),
|
|
68
|
+
y: uint256(0x2ca91c89d04305640dcd8eefc8d33d78d27efee8fda3ac261150c8d675dff0d3)
|
|
69
69
|
}),
|
|
70
70
|
qPoseidon2Internal: Honk.G1Point({
|
|
71
|
-
x: uint256(
|
|
72
|
-
y: uint256(
|
|
71
|
+
x: uint256(0x1e7842d12cae260b5fabe275ae67fc449e3a55615f7f83da87b1ea7c9e8f0500),
|
|
72
|
+
y: uint256(0x1ea86788529c46dc304e64c22662f3c8c4e3e2e347500ccf539780071a293aad)
|
|
73
73
|
}),
|
|
74
74
|
s1: Honk.G1Point({
|
|
75
|
-
x: uint256(
|
|
76
|
-
y: uint256(
|
|
75
|
+
x: uint256(0x0e90e964ef25f8c1aec26541f31cc9320b50fd36e39520d025d13e032037727e),
|
|
76
|
+
y: uint256(0x1089017a718fae9b93f24789f8ef17aeed176bf9d16edb535a63d32648528a92)
|
|
77
77
|
}),
|
|
78
78
|
s2: Honk.G1Point({
|
|
79
|
-
x: uint256(
|
|
80
|
-
y: uint256(
|
|
79
|
+
x: uint256(0x1aacf9506f5763680928c04b60d8217d4db189f8e148fd444a114ea18338fc8c),
|
|
80
|
+
y: uint256(0x0b260dbc5d61e1b32e055570a5dd0a835b4f9672cd12dad8314aaa58eea62dd4)
|
|
81
81
|
}),
|
|
82
82
|
s3: Honk.G1Point({
|
|
83
|
-
x: uint256(
|
|
84
|
-
y: uint256(
|
|
83
|
+
x: uint256(0x00357d87f2822ca4102863d9736d121154762e65008fb88d0851b22f7d564c5f),
|
|
84
|
+
y: uint256(0x261b2a08cf2c8f3df7c5758aa7532df230d3348c1ad7b6ff1cf75dce3e8a03c7)
|
|
85
85
|
}),
|
|
86
86
|
s4: Honk.G1Point({
|
|
87
|
-
x: uint256(
|
|
88
|
-
y: uint256(
|
|
87
|
+
x: uint256(0x063add626791aade9be4f0371c6bb601295f7715cd35c540a64881892bb9015f),
|
|
88
|
+
y: uint256(0x242cfc11084db62679ffc86ae33655c2adf2c60ee9a18c3fda51910194358f18)
|
|
89
89
|
}),
|
|
90
90
|
t1: Honk.G1Point({
|
|
91
91
|
x: uint256(0x1f16b037f0b4c96ea2a30a118a44e139881c0db8a4d6c9fde7db5c1c1738e61f),
|
|
@@ -104,28 +104,28 @@ library HonkVerificationKey {
|
|
|
104
104
|
y: uint256(0x2d7e8c1ecb92e2490049b50efc811df63f1ca97e58d5e82852dbec0c29715d71)
|
|
105
105
|
}),
|
|
106
106
|
id1: Honk.G1Point({
|
|
107
|
-
x: uint256(
|
|
108
|
-
y: uint256(
|
|
107
|
+
x: uint256(0x1dab2791b5e739b6eda84ec6578132dd1f9295f16540f1a221a615f137c750d0),
|
|
108
|
+
y: uint256(0x0be694840789fada394fb3182a06d50f0c313775cea2b52e6ec3d09705d4ed13)
|
|
109
109
|
}),
|
|
110
110
|
id2: Honk.G1Point({
|
|
111
|
-
x: uint256(
|
|
112
|
-
y: uint256(
|
|
111
|
+
x: uint256(0x2922506083c612268913dac1af860cae5d49406ce01679ccfc17f95f1ab2a95f),
|
|
112
|
+
y: uint256(0x29b3e2aa20c02de724c5142a941fdc7578c80fa8e2984882ffdf2c3a98ab8877)
|
|
113
113
|
}),
|
|
114
114
|
id3: Honk.G1Point({
|
|
115
|
-
x: uint256(
|
|
116
|
-
y: uint256(
|
|
115
|
+
x: uint256(0x021afc0b974f923bb6e3116b7a7d04af835678e17a0e8ef3e9e723ca2c2122e9),
|
|
116
|
+
y: uint256(0x1a1a18df93aba1975b374fd27695da35bbc0e243edbbcf67ec6e58c3441198fb)
|
|
117
117
|
}),
|
|
118
118
|
id4: Honk.G1Point({
|
|
119
|
-
x: uint256(
|
|
120
|
-
y: uint256(
|
|
119
|
+
x: uint256(0x22c8713ddae54a7bb0751e8e2d97049735a71cf2e840c5a8c4e3d94af4bad28b),
|
|
120
|
+
y: uint256(0x12b05267a7d72d33761c4742e8b03365cbdb383efd91743447b64d1714259595)
|
|
121
121
|
}),
|
|
122
122
|
lagrangeFirst: Honk.G1Point({
|
|
123
123
|
x: uint256(0x0000000000000000000000000000000000000000000000000000000000000001),
|
|
124
124
|
y: uint256(0x0000000000000000000000000000000000000000000000000000000000000002)
|
|
125
125
|
}),
|
|
126
126
|
lagrangeLast: Honk.G1Point({
|
|
127
|
-
x: uint256(
|
|
128
|
-
y: uint256(
|
|
127
|
+
x: uint256(0x23322d7d1115f6d1ee1e781cf348e56fbdf96c6853625397732a472b0711fa65),
|
|
128
|
+
y: uint256(0x0359cc7c66a45d683d935dfaac2ada72634fd94dec1136ddf9dda711219be516)
|
|
129
129
|
})
|
|
130
130
|
});
|
|
131
131
|
return vk;
|
|
@@ -11,11 +11,16 @@ import { IDecryptionVerifier } from "@enclave-e3/contracts/contracts/interfaces/
|
|
|
11
11
|
|
|
12
12
|
contract MockEnclave {
|
|
13
13
|
bytes public plaintextOutput;
|
|
14
|
+
bytes32 public committeePublicKey;
|
|
14
15
|
|
|
15
16
|
function setPlaintextOutput(bytes memory plaintext) external {
|
|
16
17
|
plaintextOutput = plaintext;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
function setCommitteePublicKey(bytes32 publicKeyHash) external {
|
|
21
|
+
committeePublicKey = publicKeyHash;
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
function getE3(uint256 e3Id) external view returns (E3 memory) {
|
|
20
25
|
return
|
|
21
26
|
E3({
|
|
@@ -30,9 +35,10 @@ contract MockEnclave {
|
|
|
30
35
|
e3ProgramParams: bytes(""),
|
|
31
36
|
customParams: bytes(""),
|
|
32
37
|
decryptionVerifier: IDecryptionVerifier(address(0)),
|
|
33
|
-
committeePublicKey:
|
|
38
|
+
committeePublicKey: committeePublicKey,
|
|
34
39
|
ciphertextOutput: bytes32(0),
|
|
35
|
-
plaintextOutput: plaintextOutput
|
|
40
|
+
plaintextOutput: plaintextOutput,
|
|
41
|
+
requester: address(0)
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crisp-e3/contracts",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"contracts",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"typechain": "^8.3.0",
|
|
60
60
|
"typescript": "5.8.3",
|
|
61
61
|
"viem": "2.30.6",
|
|
62
|
-
"@crisp-e3/sdk": "^0.5.
|
|
63
|
-
"@crisp-e3/zk-inputs": "^0.5.
|
|
62
|
+
"@crisp-e3/sdk": "^0.5.8",
|
|
63
|
+
"@crisp-e3/zk-inputs": "^0.5.8"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"compile": "hardhat compile",
|