@crisp-e3/contracts 0.2.3-test → 0.3.0-test
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/LICENSE.md +92 -123
- package/README.md +30 -6
- package/contracts/CRISPProgram.sol +243 -158
- package/contracts/CRISPVerifier.sol +1230 -678
- package/contracts/Mocks/MockCRISPProgram.sol +229 -0
- package/contracts/Mocks/MockEnclave.sol +26 -27
- package/contracts/Mocks/MockRISC0Verifier.sol +1 -5
- package/contracts/Mocks/RiscZeroGroth16Verifier.sol +2 -5
- package/package.json +6 -4
- package/contracts/CRISPInputValidator.sol +0 -107
- package/contracts/CRISPInputValidatorFactory.sol +0 -28
- package/contracts/ImageID.sol +0 -26
- package/contracts/Mocks/MockCRISPInputValidator.sol +0 -35
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-only
|
|
2
|
+
//
|
|
3
|
+
// This file is provided WITHOUT ANY WARRANTY;
|
|
4
|
+
// without even the implied warranty of MERCHANTABILITY
|
|
5
|
+
// or FITNESS FOR A PARTICULAR PURPOSE.
|
|
6
|
+
pragma solidity >=0.8.27;
|
|
7
|
+
|
|
8
|
+
import {IRiscZeroVerifier} from "risc0/IRiscZeroVerifier.sol";
|
|
9
|
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
10
|
+
import {IE3Program} from "@enclave-e3/contracts/contracts/interfaces/IE3Program.sol";
|
|
11
|
+
import {IEnclave} from "@enclave-e3/contracts/contracts/interfaces/IEnclave.sol";
|
|
12
|
+
import {E3} from "@enclave-e3/contracts/contracts/interfaces/IE3.sol";
|
|
13
|
+
import {LazyIMTData, InternalLazyIMT} from "@zk-kit/lazy-imt.sol/InternalLazyIMT.sol";
|
|
14
|
+
|
|
15
|
+
import {HonkVerifier} from "../CRISPVerifier.sol";
|
|
16
|
+
|
|
17
|
+
contract MockCRISPProgram is IE3Program, Ownable {
|
|
18
|
+
using InternalLazyIMT for LazyIMTData;
|
|
19
|
+
/// @notice a structure that holds the round data
|
|
20
|
+
struct RoundData {
|
|
21
|
+
/// @notice The governance token address.
|
|
22
|
+
address token;
|
|
23
|
+
/// @notice The minimum balance required to pass the validation.
|
|
24
|
+
uint256 balanceThreshold;
|
|
25
|
+
/// @notice The Merkle root of the census.
|
|
26
|
+
uint256 censusMerkleRoot;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Constants
|
|
30
|
+
bytes32 public constant ENCRYPTION_SCHEME_ID = keccak256("fhe.rs:BFV");
|
|
31
|
+
|
|
32
|
+
// The depth of the input merkle tree
|
|
33
|
+
uint8 public constant TREE_DEPTH = 20;
|
|
34
|
+
|
|
35
|
+
// State variables
|
|
36
|
+
IEnclave public enclave;
|
|
37
|
+
IRiscZeroVerifier public verifier;
|
|
38
|
+
HonkVerifier private immutable HONK_VERIFIER;
|
|
39
|
+
bytes32 public imageId;
|
|
40
|
+
|
|
41
|
+
/// @notice the round data
|
|
42
|
+
RoundData public roundData;
|
|
43
|
+
/// @notice whether the round data has been set
|
|
44
|
+
bool public isDataSet;
|
|
45
|
+
|
|
46
|
+
/// @notice Half of the largest minimum degree used to fit votes
|
|
47
|
+
/// inside the plaintext polynomial
|
|
48
|
+
uint256 public constant HALF_LARGEST_MINIMUM_DEGREE = 28;
|
|
49
|
+
|
|
50
|
+
// Mappings
|
|
51
|
+
mapping(address => bool) public authorizedContracts;
|
|
52
|
+
mapping(uint256 e3Id => bytes32 paramsHash) public paramsHashes;
|
|
53
|
+
/// @notice Mapping to store votes slot indices. Each eligible voter has their own slot
|
|
54
|
+
/// to store their vote inside the merkle tree.
|
|
55
|
+
mapping(uint256 e3Id => mapping(address slot => uint40 index)) public voteSlots;
|
|
56
|
+
mapping(uint256 e3Id => LazyIMTData) public votes;
|
|
57
|
+
|
|
58
|
+
// Errors
|
|
59
|
+
error CallerNotAuthorized();
|
|
60
|
+
error E3AlreadyInitialized();
|
|
61
|
+
error E3DoesNotExist();
|
|
62
|
+
error EnclaveAddressZero();
|
|
63
|
+
error VerifierAddressZero();
|
|
64
|
+
|
|
65
|
+
/// @notice The error emitted when the honk verifier address is invalid.
|
|
66
|
+
error InvalidHonkVerifier();
|
|
67
|
+
/// @notice The error emitted when the input data is empty.
|
|
68
|
+
error EmptyInputData();
|
|
69
|
+
/// @notice The error emitted when the input data is invalid.
|
|
70
|
+
error InvalidInputData(bytes reason);
|
|
71
|
+
/// @notice The error emitted when the Noir proof is invalid.
|
|
72
|
+
error InvalidNoirProof();
|
|
73
|
+
/// @notice The error emitted when the round data is not set.
|
|
74
|
+
error RoundDataNotSet();
|
|
75
|
+
/// @notice The error emitted when trying to set the round data more than once.
|
|
76
|
+
error RoundDataAlreadySet();
|
|
77
|
+
|
|
78
|
+
/// @notice The event emitted when an input is published.
|
|
79
|
+
event InputPublished(uint256 indexed e3Id, bytes vote, uint256 index);
|
|
80
|
+
|
|
81
|
+
/// @notice Initialize the contract, binding it to a specified RISC Zero verifier.
|
|
82
|
+
/// @param _enclave The enclave address
|
|
83
|
+
/// @param _verifier The RISC Zero verifier address
|
|
84
|
+
/// @param _honkVerifier The honk verifier address
|
|
85
|
+
/// @param _imageId The image ID for the guest program
|
|
86
|
+
constructor(IEnclave _enclave, IRiscZeroVerifier _verifier, HonkVerifier _honkVerifier, bytes32 _imageId)
|
|
87
|
+
Ownable(msg.sender)
|
|
88
|
+
{
|
|
89
|
+
require(address(_enclave) != address(0), EnclaveAddressZero());
|
|
90
|
+
require(address(_verifier) != address(0), VerifierAddressZero());
|
|
91
|
+
require(address(_honkVerifier) != address(0), InvalidHonkVerifier());
|
|
92
|
+
|
|
93
|
+
enclave = _enclave;
|
|
94
|
+
verifier = _verifier;
|
|
95
|
+
HONK_VERIFIER = _honkVerifier;
|
|
96
|
+
authorizedContracts[address(_enclave)] = true;
|
|
97
|
+
imageId = _imageId;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// @notice Sets the Round data. Can only be set once.
|
|
101
|
+
/// @param _root The Merkle root to set.
|
|
102
|
+
/// @param _token The governance token address.
|
|
103
|
+
/// @param _balanceThreshold The minimum balance required.
|
|
104
|
+
function setRoundData(uint256 _root, address _token, uint256 _balanceThreshold)
|
|
105
|
+
external
|
|
106
|
+
onlyOwner
|
|
107
|
+
{
|
|
108
|
+
if (isDataSet) revert RoundDataAlreadySet();
|
|
109
|
+
|
|
110
|
+
isDataSet = true;
|
|
111
|
+
|
|
112
|
+
roundData = RoundData({
|
|
113
|
+
token: _token,
|
|
114
|
+
balanceThreshold: _balanceThreshold,
|
|
115
|
+
censusMerkleRoot: _root
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// @notice Set the Image ID for the guest program
|
|
120
|
+
/// @param _imageId The new image ID.
|
|
121
|
+
function setImageId(bytes32 _imageId) external onlyOwner {
|
|
122
|
+
imageId = _imageId;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// @notice Set the RISC Zero verifier address
|
|
126
|
+
/// @param _verifier The new RISC Zero verifier address
|
|
127
|
+
function setVerifier(IRiscZeroVerifier _verifier) external onlyOwner {
|
|
128
|
+
if (address(_verifier) == address(0)) revert VerifierAddressZero();
|
|
129
|
+
verifier = _verifier;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// @notice Get the params hash for an E3 program
|
|
133
|
+
/// @param e3Id The E3 program ID
|
|
134
|
+
/// @return The params hash
|
|
135
|
+
function getParamsHash(uint256 e3Id) public view returns (bytes32) {
|
|
136
|
+
return paramsHashes[e3Id];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/// @notice Validate the E3 program parameters
|
|
140
|
+
/// @param e3Id The E3 program ID
|
|
141
|
+
/// @param e3ProgramParams The E3 program parameters
|
|
142
|
+
function validate(uint256 e3Id, uint256, bytes calldata e3ProgramParams, bytes calldata)
|
|
143
|
+
external
|
|
144
|
+
returns (bytes32)
|
|
145
|
+
{
|
|
146
|
+
require(authorizedContracts[msg.sender] || msg.sender == owner(), CallerNotAuthorized());
|
|
147
|
+
require(paramsHashes[e3Id] == bytes32(0), E3AlreadyInitialized());
|
|
148
|
+
paramsHashes[e3Id] = keccak256(e3ProgramParams);
|
|
149
|
+
|
|
150
|
+
return ENCRYPTION_SCHEME_ID;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/// @inheritdoc IE3Program
|
|
154
|
+
function validateInput(uint256 e3Id, address, bytes memory data) external {
|
|
155
|
+
if (data.length == 0) revert EmptyInputData();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/// @notice Decode the tally from the plaintext output
|
|
159
|
+
/// @param e3Id The E3 program ID
|
|
160
|
+
/// @return yes The number of yes votes
|
|
161
|
+
/// @return no The number of no votes
|
|
162
|
+
function decodeTally(uint256 e3Id) public view returns (uint256 yes, uint256 no) {
|
|
163
|
+
// fetch from enclave
|
|
164
|
+
E3 memory e3 = enclave.getE3(e3Id);
|
|
165
|
+
|
|
166
|
+
// abi decode it into an array of uint256
|
|
167
|
+
uint256[] memory tally = abi.decode(e3.plaintextOutput, (uint256[]));
|
|
168
|
+
|
|
169
|
+
/// @notice We want to completely ignore anything outside of the coefficients
|
|
170
|
+
/// we agreed to store out votes on.
|
|
171
|
+
uint256 halfD = tally.length / 2;
|
|
172
|
+
uint256 START_INDEX_Y = halfD - HALF_LARGEST_MINIMUM_DEGREE;
|
|
173
|
+
uint256 START_INDEX_N = tally.length - HALF_LARGEST_MINIMUM_DEGREE;
|
|
174
|
+
|
|
175
|
+
// first weight (we are converting back from bits to integer)
|
|
176
|
+
uint256 weight = 2 ** (HALF_LARGEST_MINIMUM_DEGREE - 1);
|
|
177
|
+
|
|
178
|
+
// Convert yes votes
|
|
179
|
+
for (uint256 i = START_INDEX_Y; i < halfD; i++) {
|
|
180
|
+
yes += tally[i] * weight;
|
|
181
|
+
weight /= 2; // Right shift equivalent
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Reset weight for no votes
|
|
185
|
+
weight = 2 ** (HALF_LARGEST_MINIMUM_DEGREE - 1);
|
|
186
|
+
|
|
187
|
+
// Convert no votes
|
|
188
|
+
for (uint256 i = START_INDEX_N; i < tally.length; i++) {
|
|
189
|
+
no += tally[i] * weight;
|
|
190
|
+
weight /= 2;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return (yes, no);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/// @notice Verify the proof
|
|
197
|
+
/// @param e3Id The E3 program ID
|
|
198
|
+
/// @param ciphertextOutputHash The hash of the ciphertext output
|
|
199
|
+
/// @param proof The proof to verify
|
|
200
|
+
function verify(uint256 e3Id, bytes32 ciphertextOutputHash, bytes memory proof)
|
|
201
|
+
external
|
|
202
|
+
view
|
|
203
|
+
override
|
|
204
|
+
returns (bool)
|
|
205
|
+
{
|
|
206
|
+
require(paramsHashes[e3Id] != bytes32(0), E3DoesNotExist());
|
|
207
|
+
bytes32 inputRoot = bytes32(votes[e3Id]._root(TREE_DEPTH));
|
|
208
|
+
bytes memory journal = new bytes(396); // (32 + 1) * 4 * 3
|
|
209
|
+
|
|
210
|
+
encodeLengthPrefixAndHash(journal, 0, ciphertextOutputHash);
|
|
211
|
+
encodeLengthPrefixAndHash(journal, 132, paramsHashes[e3Id]);
|
|
212
|
+
encodeLengthPrefixAndHash(journal, 264, inputRoot);
|
|
213
|
+
|
|
214
|
+
verifier.verify(proof, imageId, sha256(journal));
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/// @notice Encode length prefix and hash
|
|
219
|
+
/// @param journal The journal to encode into
|
|
220
|
+
/// @param startIndex The start index in the journal
|
|
221
|
+
/// @param hashVal The hash value to encode
|
|
222
|
+
function encodeLengthPrefixAndHash(bytes memory journal, uint256 startIndex, bytes32 hashVal) internal pure {
|
|
223
|
+
journal[startIndex] = 0x20;
|
|
224
|
+
startIndex += 4;
|
|
225
|
+
for (uint256 i = 0; i < 32; i++) {
|
|
226
|
+
journal[startIndex + i * 4] = hashVal[i];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -5,35 +5,34 @@
|
|
|
5
5
|
// or FITNESS FOR A PARTICULAR PURPOSE.
|
|
6
6
|
pragma solidity >=0.8.27;
|
|
7
7
|
|
|
8
|
-
import {E3} from
|
|
9
|
-
import {IE3Program} from
|
|
10
|
-
import {
|
|
11
|
-
import {IDecryptionVerifier} from "@enclave-e3/contracts/contracts/interfaces/IDecryptionVerifier.sol";
|
|
8
|
+
import { E3 } from '@enclave-e3/contracts/contracts/interfaces/IE3.sol';
|
|
9
|
+
import { IE3Program } from '@enclave-e3/contracts/contracts/interfaces/IE3Program.sol';
|
|
10
|
+
import { IDecryptionVerifier } from '@enclave-e3/contracts/contracts/interfaces/IDecryptionVerifier.sol';
|
|
12
11
|
|
|
13
12
|
contract MockEnclave {
|
|
14
|
-
|
|
13
|
+
bytes public plaintextOutput;
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function setPlaintextOutput(uint256[] memory plaintext) external {
|
|
16
|
+
plaintextOutput = abi.encode(plaintext);
|
|
17
|
+
}
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
function getE3(uint256 e3Id) external view returns (E3 memory) {
|
|
20
|
+
return
|
|
21
|
+
E3({
|
|
22
|
+
seed: 0,
|
|
23
|
+
threshold: [uint32(1), uint32(2)],
|
|
24
|
+
requestBlock: 0,
|
|
25
|
+
startWindow: [uint256(0), uint256(0)],
|
|
26
|
+
duration: 0,
|
|
27
|
+
expiration: 0,
|
|
28
|
+
encryptionSchemeId: bytes32(0),
|
|
29
|
+
e3Program: IE3Program(address(0)),
|
|
30
|
+
e3ProgramParams: bytes(''),
|
|
31
|
+
customParams: bytes(''),
|
|
32
|
+
decryptionVerifier: IDecryptionVerifier(address(0)),
|
|
33
|
+
committeePublicKey: bytes32(0),
|
|
34
|
+
ciphertextOutput: bytes32(0),
|
|
35
|
+
plaintextOutput: plaintextOutput
|
|
36
|
+
});
|
|
37
|
+
}
|
|
39
38
|
}
|
|
@@ -8,11 +8,7 @@ pragma solidity ^0.8.27;
|
|
|
8
8
|
import {IRiscZeroVerifier, Receipt} from "risc0/IRiscZeroVerifier.sol";
|
|
9
9
|
|
|
10
10
|
contract MockRISC0Verifier is IRiscZeroVerifier {
|
|
11
|
-
function verify(
|
|
12
|
-
bytes calldata seal,
|
|
13
|
-
bytes32 imageId,
|
|
14
|
-
bytes32 journalDigest
|
|
15
|
-
) public view override {}
|
|
11
|
+
function verify(bytes calldata seal, bytes32 imageId, bytes32 journalDigest) public view override {}
|
|
16
12
|
|
|
17
13
|
function verifyIntegrity(Receipt calldata receipt) external view override {}
|
|
18
14
|
}
|
|
@@ -9,8 +9,5 @@ import {RiscZeroGroth16Verifier as RiscZero} from "risc0/groth16/RiscZeroGroth16
|
|
|
9
9
|
import {ControlID} from "risc0/groth16/ControlID.sol";
|
|
10
10
|
|
|
11
11
|
contract RiscZeroGroth16Verifier is RiscZero {
|
|
12
|
-
constructor() RiscZero(
|
|
13
|
-
|
|
14
|
-
ControlID.BN254_CONTROL_ID
|
|
15
|
-
) {}
|
|
16
|
-
}
|
|
12
|
+
constructor() RiscZero(ControlID.CONTROL_ROOT, ControlID.BN254_CONTROL_ID) {}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crisp-e3/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-test",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"contracts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@excubiae/contracts": "^0.4.0",
|
|
31
|
-
"@zk-kit/
|
|
31
|
+
"@zk-kit/lazy-imt.sol": "2.0.0-beta.12",
|
|
32
32
|
"poseidon-solidity": "^0.0.5",
|
|
33
33
|
"solady": "^0.1.13",
|
|
34
34
|
"@enclave-e3/contracts": "0.1.5"
|
|
@@ -59,12 +59,14 @@
|
|
|
59
59
|
"typechain": "^8.3.0",
|
|
60
60
|
"typescript": "5.8.3",
|
|
61
61
|
"viem": "2.30.6",
|
|
62
|
-
"@crisp-e3/sdk": "^0.
|
|
63
|
-
"@crisp-e3/zk-inputs": "^0.
|
|
62
|
+
"@crisp-e3/sdk": "^0.3.0-test",
|
|
63
|
+
"@crisp-e3/zk-inputs": "^0.3.0-test"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"compile": "hardhat compile",
|
|
67
67
|
"ciphernode:add": "hardhat ciphernode:admin-add",
|
|
68
|
+
"ciphernode:mint:tokens": "hardhat ciphernode:mint-tokens",
|
|
69
|
+
"ciphernode:add:self": "hardhat ciphernode:add",
|
|
68
70
|
"clean:deployments": "hardhat utils:clean-deployments",
|
|
69
71
|
"deploy:contracts": "hardhat run deploy/deploy.ts",
|
|
70
72
|
"deploy:contracts:full": "export DEPLOY_ENCLAVE=true && pnpm deploy:contracts",
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: LGPL-3.0-only
|
|
2
|
-
//
|
|
3
|
-
// This file is provided WITHOUT ANY WARRANTY;
|
|
4
|
-
// without even the implied warranty of MERCHANTABILITY
|
|
5
|
-
// or FITNESS FOR A PARTICULAR PURPOSE.
|
|
6
|
-
pragma solidity >=0.8.27;
|
|
7
|
-
|
|
8
|
-
import {IInputValidator} from "@enclave-e3/contracts/contracts/interfaces/IInputValidator.sol";
|
|
9
|
-
import {Clone} from "@excubiae/contracts/proxy/Clone.sol";
|
|
10
|
-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
11
|
-
|
|
12
|
-
import {IVerifier} from "./CRISPVerifier.sol";
|
|
13
|
-
|
|
14
|
-
/// @title CRISPInputValidator.
|
|
15
|
-
/// @notice Enclave Input Validator
|
|
16
|
-
contract CRISPInputValidator is IInputValidator, Clone, Ownable(msg.sender) {
|
|
17
|
-
/// @notice The verifier that will be used to validate the input.
|
|
18
|
-
IVerifier internal noirVerifier;
|
|
19
|
-
|
|
20
|
-
/// @notice The governance token address.
|
|
21
|
-
address public token;
|
|
22
|
-
/// @notice The minimum balance required to pass the validation.
|
|
23
|
-
uint256 public balanceThreshold;
|
|
24
|
-
/// @notice The block number at which the balance will be checked.
|
|
25
|
-
uint256 public snapshotBlock;
|
|
26
|
-
/// @notice The Merkle root of the census.
|
|
27
|
-
uint256 public censusMerkleRoot;
|
|
28
|
-
|
|
29
|
-
/// @notice Indicates if the the round data has been set.
|
|
30
|
-
bool public isDataSet;
|
|
31
|
-
|
|
32
|
-
/// @notice Mapping to store votes. Each elegible voter has their own slot
|
|
33
|
-
/// to store their vote.
|
|
34
|
-
mapping (address => bytes) public voteSlots;
|
|
35
|
-
|
|
36
|
-
/// @notice The error emitted when the input data is empty.
|
|
37
|
-
error EmptyInputData();
|
|
38
|
-
/// @notice The error emitted when the input data is invalid.
|
|
39
|
-
error InvalidInputData(bytes reason);
|
|
40
|
-
/// @notice The error emitted when the Noir proof is invalid.
|
|
41
|
-
error InvalidNoirProof();
|
|
42
|
-
/// @notice The error emitted when the round data is not set.
|
|
43
|
-
error RoundDataNotSet();
|
|
44
|
-
/// @notice The error emitted when trying to set the round data more than once.
|
|
45
|
-
error RoundDataAlreadySet();
|
|
46
|
-
|
|
47
|
-
/// @notice Initializes the contract with appended bytes data for configuration.
|
|
48
|
-
function _initialize() internal virtual override(Clone) {
|
|
49
|
-
super._initialize();
|
|
50
|
-
|
|
51
|
-
(address _verifierAddr, address _owner) = abi.decode(
|
|
52
|
-
_getAppendedBytes(),
|
|
53
|
-
(address, address)
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
noirVerifier = IVerifier(_verifierAddr);
|
|
57
|
-
_transferOwnership(_owner);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/// @notice Sets the Merkle root of the census. Can only be set once.
|
|
61
|
-
/// @param _root The Merkle root to set.
|
|
62
|
-
function setRoundData(uint256 _root, address _token, uint256 _balanceThreshold, uint256 _snapshotBlock) external onlyOwner {
|
|
63
|
-
if (isDataSet) revert RoundDataAlreadySet();
|
|
64
|
-
|
|
65
|
-
isDataSet = true;
|
|
66
|
-
token = _token;
|
|
67
|
-
balanceThreshold = _balanceThreshold;
|
|
68
|
-
snapshotBlock = _snapshotBlock;
|
|
69
|
-
censusMerkleRoot = _root;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/// @notice Validates input
|
|
73
|
-
/// @param data The input to be verified.
|
|
74
|
-
/// @return input The decoded, policy-approved application payload.
|
|
75
|
-
function validate(
|
|
76
|
-
address,
|
|
77
|
-
bytes memory data
|
|
78
|
-
) external returns (bytes memory input) {
|
|
79
|
-
// we need to ensure that the CRISP admin set the merkle root of the census
|
|
80
|
-
// @todo update this once we have all components working
|
|
81
|
-
// if (!isDataSet) revert RoundDataNotSet();
|
|
82
|
-
|
|
83
|
-
if (data.length == 0) revert EmptyInputData();
|
|
84
|
-
|
|
85
|
-
(
|
|
86
|
-
bytes memory noirProof,
|
|
87
|
-
bytes32[] memory noirPublicInputs,
|
|
88
|
-
bytes memory vote,
|
|
89
|
-
address slot
|
|
90
|
-
) = abi.decode(data, (bytes, bytes32[], bytes, address));
|
|
91
|
-
|
|
92
|
-
/// @notice we need to check whether the slot is empty.
|
|
93
|
-
/// if the slot is empty
|
|
94
|
-
/// @todo pass it to the verifier
|
|
95
|
-
// bool isFirstVote = voteSlots[slot].length == 0;
|
|
96
|
-
|
|
97
|
-
// Check if the ciphertext was encrypted correctly
|
|
98
|
-
if (!noirVerifier.verify(noirProof, noirPublicInputs))
|
|
99
|
-
revert InvalidNoirProof();
|
|
100
|
-
|
|
101
|
-
/// @notice Store the vote in the correct slot.
|
|
102
|
-
voteSlots[slot] = vote;
|
|
103
|
-
|
|
104
|
-
// return the vote so that it can be stored in Enclave's input merkle tree
|
|
105
|
-
input = vote;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: LGPL-3.0-only
|
|
2
|
-
//
|
|
3
|
-
// This file is provided WITHOUT ANY WARRANTY;
|
|
4
|
-
// without even the implied warranty of MERCHANTABILITY
|
|
5
|
-
// or FITNESS FOR A PARTICULAR PURPOSE.
|
|
6
|
-
pragma solidity >=0.8.27;
|
|
7
|
-
|
|
8
|
-
import {Factory} from "@excubiae/contracts/proxy/Factory.sol";
|
|
9
|
-
import {CRISPInputValidator} from "./CRISPInputValidator.sol";
|
|
10
|
-
|
|
11
|
-
/// @title CRISPInputValidatorFactory
|
|
12
|
-
/// @notice Factory for deploying minimal proxy instances of CRISPInputValidator.
|
|
13
|
-
contract CRISPInputValidatorFactory is Factory {
|
|
14
|
-
/// @notice Initializes the factory with the CRISPInputValidator implementation.
|
|
15
|
-
constructor(address inputValidator) Factory(inputValidator) {}
|
|
16
|
-
|
|
17
|
-
/// @notice Deploys a new CRISPInputValidator clone.
|
|
18
|
-
/// @param _verifierAddr Address of the associated verifier contract.
|
|
19
|
-
function deploy(
|
|
20
|
-
address _verifierAddr,
|
|
21
|
-
address _owner
|
|
22
|
-
) public returns (address clone) {
|
|
23
|
-
bytes memory data = abi.encode(_verifierAddr, _owner);
|
|
24
|
-
|
|
25
|
-
clone = super._deploy(data);
|
|
26
|
-
CRISPInputValidator(clone).initialize();
|
|
27
|
-
}
|
|
28
|
-
}
|
package/contracts/ImageID.sol
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 RISC Zero, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
-
|
|
17
|
-
// This file is automatically generated
|
|
18
|
-
|
|
19
|
-
pragma solidity ^0.8.20;
|
|
20
|
-
|
|
21
|
-
library ImageID {
|
|
22
|
-
bytes32 public constant PROGRAM_ID =
|
|
23
|
-
bytes32(
|
|
24
|
-
0x23734b77b0f76e85623a88d7a82f24c34c94834f2501964ea123b7a2027013a2
|
|
25
|
-
);
|
|
26
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: LGPL-3.0-only
|
|
2
|
-
//
|
|
3
|
-
// This file is provided WITHOUT ANY WARRANTY;
|
|
4
|
-
// without even the implied warranty of MERCHANTABILITY
|
|
5
|
-
// or FITNESS FOR A PARTICULAR PURPOSE.
|
|
6
|
-
pragma solidity >=0.8.27;
|
|
7
|
-
|
|
8
|
-
import {IInputValidator} from "@enclave-e3/contracts/contracts/interfaces/IInputValidator.sol";
|
|
9
|
-
import {IBasePolicy} from "@excubiae/contracts/interfaces/IBasePolicy.sol";
|
|
10
|
-
import {Clone} from "@excubiae/contracts/proxy/Clone.sol";
|
|
11
|
-
import {IVerifier} from "../CRISPVerifier.sol";
|
|
12
|
-
|
|
13
|
-
/// @title MockCRISPInputValidator.
|
|
14
|
-
/// @notice Mock Enclave Input Validator
|
|
15
|
-
contract MockCRISPInputValidator is IInputValidator, Clone {
|
|
16
|
-
/// @notice The error emitted when the input data is empty.
|
|
17
|
-
error EmptyInputData();
|
|
18
|
-
|
|
19
|
-
/// @notice Initializes the contract with appended bytes data for configuration.
|
|
20
|
-
function _initialize() internal virtual override(Clone) {
|
|
21
|
-
super._initialize();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/// @notice Validates input
|
|
25
|
-
/// @param sender The account that is submitting the input.
|
|
26
|
-
/// @param data The input to be verified.
|
|
27
|
-
/// @return input The decoded, policy-approved application payload.
|
|
28
|
-
function validate(address sender, bytes memory data) external returns (bytes memory input) {
|
|
29
|
-
if (data.length == 0) revert EmptyInputData();
|
|
30
|
-
|
|
31
|
-
(,,bytes memory vote,) = abi.decode(data, (bytes, bytes32[], bytes, address));
|
|
32
|
-
|
|
33
|
-
input = vote;
|
|
34
|
-
}
|
|
35
|
-
}
|