@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, PoseidonT3 } from "@zk-kit/lazy-imt.sol/InternalLazyIMT.sol";
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 vote, uint256 index);
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
- // TODO: Uncomment this when we make the merkle root a public input of the circuit.
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[] memory vote, address slotAddress) = abi.decode(data, (bytes, bytes32[], address));
131
+ (bytes memory noirProof, address slotAddress, bytes32 encryptedVoteCommitment, bytes memory encryptedVote) = abi.decode(
132
+ data,
133
+ (bytes, address, bytes32, bytes)
134
+ );
132
135
 
133
- bytes memory voteBytes = abi.encode(vote);
136
+ (uint40 voteIndex, bytes32 previousEncryptedVoteCommitment) = _processVote(e3Id, slotAddress, encryptedVoteCommitment);
134
137
 
135
- (uint40 voteIndex, bool isFirstVote) = _processVote(e3Id, slotAddress, voteBytes);
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
- noirPublicInputs[0] = bytes32(uint256(uint160(slotAddress)));
141
- noirPublicInputs[1] = bytes32(uint256(isFirstVote ? 1 : 0));
142
- for (uint256 i = 0; i < vote.length; i++) {
143
- noirPublicInputs[i + 2] = vote[i];
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, voteBytes, voteIndex);
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(uint256 e3Id, address slotAddress, bytes memory vote) internal returns (uint40 voteIndex, bool isFirstVote) {
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
- isFirstVote = true;
233
+ previousEncryptedVoteCommitment = bytes32(0);
226
234
  voteIndex = e3Data[e3Id].votes.numberOfLeaves;
227
235
  e3Data[e3Id].voteSlots[slotAddress] = voteIndex + 1;
228
- e3Data[e3Id].votes._insert(PoseidonT3.hash([uint256(keccak256(vote)), voteIndex]));
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._update(PoseidonT3.hash([uint256(keccak256(vote)), voteIndex]), voteIndex);
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 = 2066;
11
- uint256 constant VK_HASH = 0x127b37c45dfb3a6a153382a3cf931c718810df54513b449af9ade62385eeefac;
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(2066),
17
+ publicInputsSize: uint256(22),
18
18
  ql: Honk.G1Point({
19
- x: uint256(0x1a14a677dcf497132668b43dd6c2eba38ac0be2d8a55042e72ab0e431c1fca04),
20
- y: uint256(0x0e30a76f6ca16f79faa7f36c8541bac98823fce567367d5b05f6d1e1889d2dce)
19
+ x: uint256(0x112a6aa13787457ce92f268d8f6719287c1add28a224712ea3e2e7d96e2bc70b),
20
+ y: uint256(0x14dcf6e306f1dc722638d4984332053df53689114040ccd69d5926f485219e15)
21
21
  }),
22
22
  qr: Honk.G1Point({
23
- x: uint256(0x069b1a425a882deab8b2ab366567379d09dd9cc2430c896796c11e2e8be34fe4),
24
- y: uint256(0x2f4a270bd180719c0120936a6ca66c6097f378bb489db75e29e644716f6f9387)
23
+ x: uint256(0x22a648530332803c4a992d98fd94a036c8ff1341c3d0ba385210b8851049206c),
24
+ y: uint256(0x0b891280448cdaee82da9caec22fb4820e3140558570c252669508b4f90fba2b)
25
25
  }),
26
26
  qo: Honk.G1Point({
27
- x: uint256(0x24638b4ee6c5e15b721bbb29c486e913deb01588c13d0cb85da47c50c16a81e5),
28
- y: uint256(0x1bd194bdfc905dc9465a3fe4b697de6fd7d67ae421b7404b84e472c68e691e7b)
27
+ x: uint256(0x1ca6c37b9177a348c574f214e0683da82632df5c0d10addde3f372cda3f8978a),
28
+ y: uint256(0x22ce8ff67ba39a26d4ad603fbe668d9eb3f34f80b4e21e5cbf421d873f6ca040)
29
29
  }),
30
30
  q4: Honk.G1Point({
31
- x: uint256(0x019d3ad6130f74a80db6a4f6480521fb87ea52247dd96de060ffa7bb04b32885),
32
- y: uint256(0x2fed009cd6974244ed643b1214943f8f48d9033e6236457ec9a601e0005ba444)
31
+ x: uint256(0x0af0446ba584e461430e07a1f990aaee46d7b5088ad9f54d4a1350d57fa37ab6),
32
+ y: uint256(0x152ab3b635c7f88c62d6bb37fdff5bed5e42e01e0f9894058c10deea1994e4ef)
33
33
  }),
34
34
  qm: Honk.G1Point({
35
- x: uint256(0x1aa0f6fd5c3d53ae9bc8c76ad7e015a7b3a131aee52255966082dd0584a2d867),
36
- y: uint256(0x292ea51ab60890143445fd667e86ce788e24d625225d24fe6eef31d2cb8763b4)
35
+ x: uint256(0x2493bb0b6575f4240fa4ca66ab503effe7ad653c552cfe608e662e18e8ce5eb8),
36
+ y: uint256(0x1b5829dbe6ee24d5f1a776ddc4e27a90888310a3f384fe8f70cd86c2f9eebf7e)
37
37
  }),
38
38
  qc: Honk.G1Point({
39
- x: uint256(0x24cf8ec004d7a8a319a93ae7a62193e11e33cda3b072fee4cc92fbcf04e26c53),
40
- y: uint256(0x0acca02ae37ea0155238f82833cbc3727c9c10d74ae862a02b70edc2bbf53fec)
39
+ x: uint256(0x2ccaa4f079bfc85f3887807ba17bffd69c73402d557395f6730d31cf1f208e53),
40
+ y: uint256(0x11e38adba343d4c9839c5b4ed4d54c38d7d0e17b0c3890add1544aa18a53f805)
41
41
  }),
42
42
  qLookup: Honk.G1Point({
43
- x: uint256(0x056cab9e0cc90d6187f1504470e987376fb9d964f5e69f79d3dc50a3aba8b070),
44
- y: uint256(0x2a0690805846bbbba0fe533d4ec11edc41678b77983bcba8f10a71ece5298fee)
43
+ x: uint256(0x111ada27d4243c5df982e1cd77f2d9aff394ba4f2ba2faf8ec1a8e5b6d78d1e7),
44
+ y: uint256(0x1cf81a5fe339ef18222213e43155e149d0211317fe0a68d795681f31ef25ad0f)
45
45
  }),
46
46
  qArith: Honk.G1Point({
47
- x: uint256(0x18850029d66fb7379caabfcb3d3b694c550a6413b84644f0d13b9e05554329b7),
48
- y: uint256(0x216fb14305fc176ea326c69925161a0024e25d53909f3fd0c09871be5f94f8a0)
47
+ x: uint256(0x2771f716f503f8552b69271a62ec8cd7ab492b67f4859d8ff0321ce075e0361e),
48
+ y: uint256(0x0a7762803ccc6145a73d9df81cb83b8d7125f07f998525b8ec888bb39ff32658)
49
49
  }),
50
50
  qDeltaRange: Honk.G1Point({
51
- x: uint256(0x1faf3b8674c17daf3e0f63e7c9356cacb82450ef207412dcf21922e73850f746),
52
- y: uint256(0x07b754988b169db012bc034513ac4ee42746fe1bf233dc531af97d5bc2d0db0c)
51
+ x: uint256(0x0188abc30c433d60b371a87b89bef69474c4de9748b2b4b4e01d3e423cc2e975),
52
+ y: uint256(0x2bbddad8b0e16ca7d71b0ca54b0f6251ea7c4457d76ba3327982171026423a40)
53
53
  }),
54
54
  qElliptic: Honk.G1Point({
55
- x: uint256(0x04788fb295f478b04078cab13188d28645677fda3a09ec788387afce8f2b5804),
56
- y: uint256(0x29194accd4f5315943071685ff9c2b02480c0bff1c21915b16dd54ec561019fb)
55
+ x: uint256(0x1a2e2850cfbe3912c8f6a4c0099bc93bc50841ce22d665b83b081753ce664a24),
56
+ y: uint256(0x1976524b69c879a83c4d704ff5cb39397679528681ad378e6753e8b63457c40e)
57
57
  }),
58
58
  qMemory: Honk.G1Point({
59
- x: uint256(0x0bf2ec6066d37230ae861b2473bf67d5ea2fff4fe3b1ff276c71c0edab34c040),
60
- y: uint256(0x230bbf4647507639fa136c8112d8682c34686c7d62fee9899fd8a456dc19c71b)
59
+ x: uint256(0x2e569e263fc7a1cfa7b839e1d01a24bb6e07a396cbe93280eaa5f428f9bfcda3),
60
+ y: uint256(0x232683b772e71e0839c2c22a0325540c142df09d86ad281e95c9a8526c8a8b1d)
61
61
  }),
62
62
  qNnf: Honk.G1Point({
63
- x: uint256(0x27b6e6deb48b8f1510b8bc376c0d0998166587549833fc86d6cc9eef0ed465c5),
64
- y: uint256(0x072563066ec76ae4137df6971684a2904be8f2fef972f1f8ac9407bf41c044f6)
63
+ x: uint256(0x21cdfcabf16e6fa296718413cc974b48e44c715143907a9c5cc722aa737b74b0),
64
+ y: uint256(0x2280bd00b21340373b65aa88a619fa5f770435b772e1620701f76d769d041ea4)
65
65
  }),
66
66
  qPoseidon2External: Honk.G1Point({
67
- x: uint256(0x0412d71f1f86606512556c6d48194094f6f15e108cffeb5171ac5deafcf21ba5),
68
- y: uint256(0x0d92c1ab9f5838fa6bda23289f6baab5abb7fafd2505b05412be72c98eed5784)
67
+ x: uint256(0x0e5cb0521c16b7e51540251b51adb95e4ce6d507a75c32e0c33377c21853d058),
68
+ y: uint256(0x2ca91c89d04305640dcd8eefc8d33d78d27efee8fda3ac261150c8d675dff0d3)
69
69
  }),
70
70
  qPoseidon2Internal: Honk.G1Point({
71
- x: uint256(0x03a37c8f14f04a0c47b55fc372681424912f79c3ae565a2afce81587846e00c5),
72
- y: uint256(0x0dfb3edabbbd97745fea4c569bc99dd450bad935f50610a36639cae94acddf56)
71
+ x: uint256(0x1e7842d12cae260b5fabe275ae67fc449e3a55615f7f83da87b1ea7c9e8f0500),
72
+ y: uint256(0x1ea86788529c46dc304e64c22662f3c8c4e3e2e347500ccf539780071a293aad)
73
73
  }),
74
74
  s1: Honk.G1Point({
75
- x: uint256(0x22d479c6eca52747dcca3a59269018e74cb9dbd7a7bf4c0f3cd380d022896fea),
76
- y: uint256(0x0c3961f035d12e248dfa9f22f8ab9c6343c6c636d56ac5180334381e03f96c11)
75
+ x: uint256(0x0e90e964ef25f8c1aec26541f31cc9320b50fd36e39520d025d13e032037727e),
76
+ y: uint256(0x1089017a718fae9b93f24789f8ef17aeed176bf9d16edb535a63d32648528a92)
77
77
  }),
78
78
  s2: Honk.G1Point({
79
- x: uint256(0x0c5ca053933191ff3aad8b265619f6a4fe97650125d1c33d3af5513c18e3f48e),
80
- y: uint256(0x095932332027f209dc52666412aedb31121ee12d0f6ee50870d1cf8c7662b2a0)
79
+ x: uint256(0x1aacf9506f5763680928c04b60d8217d4db189f8e148fd444a114ea18338fc8c),
80
+ y: uint256(0x0b260dbc5d61e1b32e055570a5dd0a835b4f9672cd12dad8314aaa58eea62dd4)
81
81
  }),
82
82
  s3: Honk.G1Point({
83
- x: uint256(0x25b689112c3e1dd78e43260f40c2c6e6316b16f58fdf665ac727f9b7d423cdb7),
84
- y: uint256(0x2c9974d76ea25589eef8f777bceca914c3d7d145c5fba75413cf30120621fb86)
83
+ x: uint256(0x00357d87f2822ca4102863d9736d121154762e65008fb88d0851b22f7d564c5f),
84
+ y: uint256(0x261b2a08cf2c8f3df7c5758aa7532df230d3348c1ad7b6ff1cf75dce3e8a03c7)
85
85
  }),
86
86
  s4: Honk.G1Point({
87
- x: uint256(0x22ee739f9fb4fdcb29a7ed18db916919795d688ab94175ce5acb46348b0d8809),
88
- y: uint256(0x021d5b6eb780aa2015158d6039437c956079b61f8fc2c97352303458ce6f91ba)
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(0x01b858b61eaf5d54df5361d88c410ea379acb66cff9b2280dfa9e2ec57609ed1),
108
- y: uint256(0x2f764a892dc8a7efc8f9e58b4778aa8b0b94a979a7d6231ee26311a20623d2d2)
107
+ x: uint256(0x1dab2791b5e739b6eda84ec6578132dd1f9295f16540f1a221a615f137c750d0),
108
+ y: uint256(0x0be694840789fada394fb3182a06d50f0c313775cea2b52e6ec3d09705d4ed13)
109
109
  }),
110
110
  id2: Honk.G1Point({
111
- x: uint256(0x0ee58f929bb58de7d3e780126fcfac0943adab83776166c10b7626d2a0d04695),
112
- y: uint256(0x1ead787a8fbc072a941301774d04a4a590036e9db96de8432732592156a44f1a)
111
+ x: uint256(0x2922506083c612268913dac1af860cae5d49406ce01679ccfc17f95f1ab2a95f),
112
+ y: uint256(0x29b3e2aa20c02de724c5142a941fdc7578c80fa8e2984882ffdf2c3a98ab8877)
113
113
  }),
114
114
  id3: Honk.G1Point({
115
- x: uint256(0x28628c4f0e01831a2406331bc0901948f2f2bc22200b2ce26d92558502cd3b96),
116
- y: uint256(0x16d113fc0d0188deb7bcc2148bf2066003d5d2f6b7490201570d2ba5aa9b38ea)
115
+ x: uint256(0x021afc0b974f923bb6e3116b7a7d04af835678e17a0e8ef3e9e723ca2c2122e9),
116
+ y: uint256(0x1a1a18df93aba1975b374fd27695da35bbc0e243edbbcf67ec6e58c3441198fb)
117
117
  }),
118
118
  id4: Honk.G1Point({
119
- x: uint256(0x282448418450184e943367153db43c02bd17640d2a40ed1861833b63f0cef798),
120
- y: uint256(0x2dc5b559853ab1d7bf820f393e913fe435ccf95f84f9d8740d5f99bfcc3e3cea)
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(0x29b5224a64e89595783b8ed5c7d047e4d8a337cbf836ee2be2f20d7d47ce95b2),
128
- y: uint256(0x13396543d3d0ccf426d918fd2199d9507eafa2a505f0cce2d958231b29af1e66)
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: bytes32(0),
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.6",
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.6",
63
- "@crisp-e3/zk-inputs": "^0.5.6"
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",