@crisp-e3/contracts 0.2.3-test → 0.4.0

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.
@@ -0,0 +1,214 @@
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) Ownable(msg.sender) {
87
+ require(address(_enclave) != address(0), EnclaveAddressZero());
88
+ require(address(_verifier) != address(0), VerifierAddressZero());
89
+ require(address(_honkVerifier) != address(0), InvalidHonkVerifier());
90
+
91
+ enclave = _enclave;
92
+ verifier = _verifier;
93
+ HONK_VERIFIER = _honkVerifier;
94
+ authorizedContracts[address(_enclave)] = true;
95
+ imageId = _imageId;
96
+ }
97
+
98
+ /// @notice Sets the Round data. Can only be set once.
99
+ /// @param _root The Merkle root to set.
100
+ /// @param _token The governance token address.
101
+ /// @param _balanceThreshold The minimum balance required.
102
+ function setRoundData(uint256 _root, address _token, uint256 _balanceThreshold) external onlyOwner {
103
+ if (isDataSet) revert RoundDataAlreadySet();
104
+
105
+ isDataSet = true;
106
+
107
+ roundData = RoundData({ token: _token, balanceThreshold: _balanceThreshold, censusMerkleRoot: _root });
108
+ }
109
+
110
+ /// @notice Set the Image ID for the guest program
111
+ /// @param _imageId The new image ID.
112
+ function setImageId(bytes32 _imageId) external onlyOwner {
113
+ imageId = _imageId;
114
+ }
115
+
116
+ /// @notice Set the RISC Zero verifier address
117
+ /// @param _verifier The new RISC Zero verifier address
118
+ function setVerifier(IRiscZeroVerifier _verifier) external onlyOwner {
119
+ if (address(_verifier) == address(0)) revert VerifierAddressZero();
120
+ verifier = _verifier;
121
+ }
122
+
123
+ /// @notice Get the params hash for an E3 program
124
+ /// @param e3Id The E3 program ID
125
+ /// @return The params hash
126
+ function getParamsHash(uint256 e3Id) public view returns (bytes32) {
127
+ return paramsHashes[e3Id];
128
+ }
129
+
130
+ /// @notice Validate the E3 program parameters
131
+ /// @param e3Id The E3 program ID
132
+ /// @param e3ProgramParams The E3 program parameters
133
+ function validate(uint256 e3Id, uint256, bytes calldata e3ProgramParams, bytes calldata) external returns (bytes32) {
134
+ require(authorizedContracts[msg.sender] || msg.sender == owner(), CallerNotAuthorized());
135
+ require(paramsHashes[e3Id] == bytes32(0), E3AlreadyInitialized());
136
+ paramsHashes[e3Id] = keccak256(e3ProgramParams);
137
+
138
+ return ENCRYPTION_SCHEME_ID;
139
+ }
140
+
141
+ /// @inheritdoc IE3Program
142
+ function validateInput(uint256 e3Id, address, bytes memory data) external {
143
+ if (data.length == 0) revert EmptyInputData();
144
+
145
+ (, , bytes memory vote, ) = abi.decode(data, (bytes, bytes32[], bytes, address));
146
+ }
147
+
148
+ /// @notice Decode the tally from the plaintext output
149
+ /// @param e3Id The E3 program ID
150
+ /// @return yes The number of yes votes
151
+ /// @return no The number of no votes
152
+ function decodeTally(uint256 e3Id) public view returns (uint256 yes, uint256 no) {
153
+ // fetch from enclave
154
+ E3 memory e3 = enclave.getE3(e3Id);
155
+
156
+ // abi decode it into an array of uint256
157
+ uint256[] memory tally = abi.decode(e3.plaintextOutput, (uint256[]));
158
+
159
+ /// @notice We want to completely ignore anything outside of the coefficients
160
+ /// we agreed to store out votes on.
161
+ uint256 halfD = tally.length / 2;
162
+ uint256 START_INDEX_Y = halfD - HALF_LARGEST_MINIMUM_DEGREE;
163
+ uint256 START_INDEX_N = tally.length - HALF_LARGEST_MINIMUM_DEGREE;
164
+
165
+ // first weight (we are converting back from bits to integer)
166
+ uint256 weight = 2 ** (HALF_LARGEST_MINIMUM_DEGREE - 1);
167
+
168
+ // Convert yes votes
169
+ for (uint256 i = START_INDEX_Y; i < halfD; i++) {
170
+ yes += tally[i] * weight;
171
+ weight /= 2; // Right shift equivalent
172
+ }
173
+
174
+ // Reset weight for no votes
175
+ weight = 2 ** (HALF_LARGEST_MINIMUM_DEGREE - 1);
176
+
177
+ // Convert no votes
178
+ for (uint256 i = START_INDEX_N; i < tally.length; i++) {
179
+ no += tally[i] * weight;
180
+ weight /= 2;
181
+ }
182
+
183
+ return (yes, no);
184
+ }
185
+
186
+ /// @notice Verify the proof
187
+ /// @param e3Id The E3 program ID
188
+ /// @param ciphertextOutputHash The hash of the ciphertext output
189
+ /// @param proof The proof to verify
190
+ function verify(uint256 e3Id, bytes32 ciphertextOutputHash, bytes memory proof) external view override returns (bool) {
191
+ require(paramsHashes[e3Id] != bytes32(0), E3DoesNotExist());
192
+ bytes32 inputRoot = bytes32(votes[e3Id]._root(TREE_DEPTH));
193
+ bytes memory journal = new bytes(396); // (32 + 1) * 4 * 3
194
+
195
+ encodeLengthPrefixAndHash(journal, 0, ciphertextOutputHash);
196
+ encodeLengthPrefixAndHash(journal, 132, paramsHashes[e3Id]);
197
+ encodeLengthPrefixAndHash(journal, 264, inputRoot);
198
+
199
+ verifier.verify(proof, imageId, sha256(journal));
200
+ return true;
201
+ }
202
+
203
+ /// @notice Encode length prefix and hash
204
+ /// @param journal The journal to encode into
205
+ /// @param startIndex The start index in the journal
206
+ /// @param hashVal The hash value to encode
207
+ function encodeLengthPrefixAndHash(bytes memory journal, uint256 startIndex, bytes32 hashVal) internal pure {
208
+ journal[startIndex] = 0x20;
209
+ startIndex += 4;
210
+ for (uint256 i = 0; i < 32; i++) {
211
+ journal[startIndex + i * 4] = hashVal[i];
212
+ }
213
+ }
214
+ }
@@ -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 "@enclave-e3/contracts/contracts/interfaces/IE3.sol";
9
- import {IE3Program} from "@enclave-e3/contracts/contracts/interfaces/IE3Program.sol";
10
- import {IInputValidator} from "@enclave-e3/contracts/contracts/interfaces/IInputValidator.sol";
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
- bytes public plaintextOutput;
13
+ bytes public plaintextOutput;
15
14
 
16
- function setPlaintextOutput(uint256[] memory plaintext) external {
17
- plaintextOutput = abi.encode(plaintext);
18
- }
15
+ function setPlaintextOutput(uint256[] memory plaintext) external {
16
+ plaintextOutput = abi.encode(plaintext);
17
+ }
19
18
 
20
- function getE3(uint256 e3Id) external view returns (E3 memory) {
21
- return 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
- inputValidator: IInputValidator(address(0)),
33
- decryptionVerifier: IDecryptionVerifier(address(0)),
34
- committeePublicKey: bytes32(0),
35
- ciphertextOutput: bytes32(0),
36
- plaintextOutput: plaintextOutput
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
  }
@@ -5,14 +5,10 @@
5
5
  // or FITNESS FOR A PARTICULAR PURPOSE.
6
6
  pragma solidity ^0.8.27;
7
7
 
8
- import {IRiscZeroVerifier, Receipt} from "risc0/IRiscZeroVerifier.sol";
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
- function verifyIntegrity(Receipt calldata receipt) external view override {}
13
+ function verifyIntegrity(Receipt calldata receipt) external view override {}
18
14
  }
@@ -5,12 +5,9 @@
5
5
  // or FITNESS FOR A PARTICULAR PURPOSE.
6
6
  pragma solidity >=0.8.27;
7
7
 
8
- import {RiscZeroGroth16Verifier as RiscZero} from "risc0/groth16/RiscZeroGroth16Verifier.sol";
9
- import {ControlID} from "risc0/groth16/ControlID.sol";
8
+ import { RiscZeroGroth16Verifier as RiscZero } from "risc0/groth16/RiscZeroGroth16Verifier.sol";
9
+ import { ControlID } from "risc0/groth16/ControlID.sol";
10
10
 
11
11
  contract RiscZeroGroth16Verifier is RiscZero {
12
- constructor() RiscZero(
13
- ControlID.CONTROL_ROOT,
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.2.3-test",
3
+ "version": "0.4.0",
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/lean-imt.sol": "2.0.0",
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.2.3-test",
63
- "@crisp-e3/zk-inputs": "^0.2.3-test"
62
+ "@crisp-e3/zk-inputs": "^0.4.0",
63
+ "@crisp-e3/sdk": "^0.4.0"
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
- }
@@ -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
- }