-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathIGatewayConfig.sol
More file actions
509 lines (434 loc) · 19.1 KB
/
IGatewayConfig.sol
File metadata and controls
509 lines (434 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;
import { ProtocolMetadata, KmsNode, Coprocessor, Custodian, HostChain } from "../shared/Structs.sol";
/**
* @title Interface for the GatewayConfig contract.
* @notice The GatewayConfig contract is responsible for being a point of truth for all contracts and
* components from the fhevm Gateway.
* @dev In particular, the GatewayConfig contract contains:
* - the list of KMS nodes used exclusively by this fhevm Gateway
* - the list of coprocessors used exclusively by this fhevm Gateway
* - the list of host chains using this fhevm Gateway
*
* The GatewayConfig contract has an owner and a pauser.
* The owner can call some restricted functions, such as adding or removing KMS nodes, coprocessors
* and host chains.
* The pauser can pause all contracts.
* Some view functions are accessible to everyone (ex: getting the number of KMS nodes).
*/
interface IGatewayConfig {
/**
* @notice The operator's thresholds.
*/
struct Thresholds {
/// @notice The MPC threshold
uint256 mpcThreshold;
/// @notice The threshold to consider for public decryption consensus
uint256 publicDecryptionThreshold;
/// @notice The threshold to consider for user decryption consensus
uint256 userDecryptionThreshold;
/// @notice The threshold to consider for KMS generation consensus
uint256 kmsGenThreshold;
/// @notice The threshold to consider for coprocessor consensus
uint256 coprocessorThreshold;
}
/**
* @notice Emitted when the GatewayConfig initialization is completed.
* @param metadata Metadata of the protocol.
* @param thresholds The operator's thresholds.
* @param kmsNodes List of KMS nodes.
* @param coprocessors List of coprocessors.
* @param custodians List of custodians.
*/
event InitializeGatewayConfig(
ProtocolMetadata metadata,
Thresholds thresholds,
KmsNode[] kmsNodes,
Coprocessor[] coprocessors,
Custodian[] custodians
);
/**
* @notice Emitted when the KMS nodes have been updated.
* @param newKmsNodes The new KMS nodes.
* @param newMpcThreshold The new MPC threshold.
* @param newPublicDecryptionThreshold The new public decryption threshold.
* @param newUserDecryptionThreshold The new user decryption threshold.
* @param newKmsGenThreshold The new key and CRS generation threshold.
*/
event UpdateKmsNodes(
KmsNode[] newKmsNodes,
uint256 newMpcThreshold,
uint256 newPublicDecryptionThreshold,
uint256 newUserDecryptionThreshold,
uint256 newKmsGenThreshold
);
/**
* @notice Emitted when the coprocessors have been updated.
* @param newCoprocessors The new coprocessors.
* @param newCoprocessorThreshold The new coprocessor threshold.
*/
event UpdateCoprocessors(Coprocessor[] newCoprocessors, uint256 newCoprocessorThreshold);
/**
* @notice Emitted when the custodians have been updated.
* @param newCustodians The new custodians.
*/
event UpdateCustodians(Custodian[] newCustodians);
/**
* @notice Emitted when the MPC threshold has been updated.
* @param newMpcThreshold The new MPC threshold.
*/
event UpdateMpcThreshold(uint256 newMpcThreshold);
/**
* @notice Emitted when the public decryption threshold has been updated.
* @param newPublicDecryptionThreshold The new public decryption threshold.
*/
event UpdatePublicDecryptionThreshold(uint256 newPublicDecryptionThreshold);
/**
* @notice Emitted when the user decryption threshold has been updated.
* @param newUserDecryptionThreshold The new user decryption threshold.
*/
event UpdateUserDecryptionThreshold(uint256 newUserDecryptionThreshold);
/**
* @notice Emitted when the key and CRS generation threshold has been updated.
* @param newKmsGenThreshold The new key and CRS generation threshold.
*/
event UpdateKmsGenThreshold(uint256 newKmsGenThreshold);
/**
* @notice Emitted when the coprocessor threshold has been updated.
* @param newCoprocessorThreshold The new coprocessor threshold.
*/
event UpdateCoprocessorThreshold(uint256 newCoprocessorThreshold);
/**
* @notice Emitted when a new host chain has been registered.
* @param hostChain The new host chain metadata.
*/
event AddHostChain(HostChain hostChain);
/**
* @notice Error indicating that the given account is not a pauser.
* @param account The address of the account.
*/
error NotPauser(address account);
/**
* @notice Error emitted when the KMS nodes list is empty.
*/
error EmptyKmsNodes();
/**
* @notice Error emitted when the KMS transaction sender is already registered.
* @param kmsTxSenderAddress The KMS transaction sender address.
*/
error KmsTxSenderAlreadyRegistered(address kmsTxSenderAddress);
/**
* @notice Error emitted when the KMS signer is already registered.
* @param kmsSignerAddress The KMS signer address.
*/
error KmsSignerAlreadyRegistered(address kmsSignerAddress);
/**
* @notice Error emitted when the coprocessors list is empty.
*/
error EmptyCoprocessors();
/**
* @notice Error emitted when the coprocessor transaction sender is already registered.
* @param coprocessorTxSenderAddress The coprocessor transaction sender address.
*/
error CoprocessorTxSenderAlreadyRegistered(address coprocessorTxSenderAddress);
/**
* @notice Error emitted when the coprocessor signer is already registered.
* @param coprocessorSignerAddress The coprocessor signer address.
*/
error CoprocessorSignerAlreadyRegistered(address coprocessorSignerAddress);
/**
* @notice Error emitted when the custodians list is empty.
*/
error EmptyCustodians();
/**
* @notice Error emitted when the custodian transaction sender is already registered.
* @param custodianTxSenderAddress The custodian transaction sender address.
*/
error CustodianTxSenderAlreadyRegistered(address custodianTxSenderAddress);
/**
* @notice Error emitted when the custodian signer is already registered.
* @param custodianSignerAddress The custodian signer address.
*/
error CustodianSignerAlreadyRegistered(address custodianSignerAddress);
/**
* @notice Error emitted when the MPC threshold is greater or equal to the number of KMS nodes.
* @param mpcThreshold The MPC threshold.
* @param nKmsNodes The number of KMS nodes.
*/
error InvalidHighMpcThreshold(uint256 mpcThreshold, uint256 nKmsNodes);
/**
* @notice Error emitted when the public decryption threshold is null.
*/
error InvalidNullPublicDecryptionThreshold();
/**
* @notice Error emitted when the public decryption threshold is strictly greater than the number of KMS nodes.
* @param publicDecryptionThreshold The public decryption threshold.
* @param nKmsNodes The number of KMS nodes.
*/
error InvalidHighPublicDecryptionThreshold(uint256 publicDecryptionThreshold, uint256 nKmsNodes);
/**
* @notice Error emitted when the user decryption threshold is null.
*/
error InvalidNullUserDecryptionThreshold();
/**
* @notice Error emitted when the user decryption threshold is strictly greater than the number of KMS nodes.
* @param userDecryptionThreshold The user decryption threshold.
* @param nKmsNodes The number of KMS nodes.
*/
error InvalidHighUserDecryptionThreshold(uint256 userDecryptionThreshold, uint256 nKmsNodes);
/**
* @notice Error emitted when the key and CRS generation threshold is null.
*/
error InvalidNullKmsGenThreshold();
/**
* @notice Error emitted when the key and CRS generation threshold is strictly greater than the number of KMS nodes.
* @param kmsGenThreshold The key and CRS generation threshold.
* @param nKmsNodes The number of KMS nodes.
*/
error InvalidHighKmsGenThreshold(uint256 kmsGenThreshold, uint256 nKmsNodes);
/**
* @notice Error emitted when the coprocessor threshold is null.
*/
error InvalidNullCoprocessorThreshold();
/**
* @notice Error emitted when the coprocessor threshold is strictly greater than the number of coprocessors.
* @param coprocessorThreshold The coprocessor threshold.
* @param nCoprocessors The number of coprocessors.
*/
error InvalidHighCoprocessorThreshold(uint256 coprocessorThreshold, uint256 nCoprocessors);
/**
* @notice Emitted when all the pausable gateway contracts are paused.
*/
event PauseAllGatewayContracts();
/**
* @notice Emitted when all the pausable gateway contracts are unpaused.
*/
event UnpauseAllGatewayContracts();
/**
* @notice Error emitted when trying to add a host chain that is already registered.
* @param chainId The host chain's chain ID that is already registered.
*/
error HostChainAlreadyRegistered(uint256 chainId);
/**
* @notice Error indicating that a null chain ID is not allowed.
*/
error InvalidNullChainId();
/**
* @notice Error indicating that a chain ID is not represented by a uint64.
* @param chainId The ID of the host chain that is not a valid uint64.
*/
error ChainIdNotUint64(uint256 chainId);
/**
* @notice Error emitted when all the pausable gateway contracts are already paused.
*/
error AllGatewayContractsAlreadyPaused();
/**
* @notice Error emitted when all the pausable gateway contracts are already unpaused.
*/
error AllGatewayContractsAlreadyUnpaused();
/**
* @notice Update the list of KMS nodes and their thresholds.
* @dev ⚠️ This function should be used with caution as it can lead to unexpected behavior in
* some requests and the contracts should first be paused. It will be deprecated in the future.
* @param newKmsNodes The new KMS nodes.
* @param newMpcThreshold The new MPC threshold.
* @param newPublicDecryptionThreshold The new public decryption threshold.
* @param newUserDecryptionThreshold The new user decryption threshold.
* @param newKmsGenThreshold The new key and CRS generation threshold.
*/
function updateKmsNodes(
KmsNode[] calldata newKmsNodes,
uint256 newMpcThreshold,
uint256 newPublicDecryptionThreshold,
uint256 newUserDecryptionThreshold,
uint256 newKmsGenThreshold
) external;
/**
* @notice Update the list of coprocessors and their threshold.
* @dev ⚠️ This function should be used with caution as it can lead to unexpected behavior in
* some requests and the contracts should first be paused. It will be deprecated in the future.
* @param newCoprocessors The new coprocessors.
* @param newCoprocessorThreshold The new coprocessor threshold.
*/
function updateCoprocessors(Coprocessor[] calldata newCoprocessors, uint256 newCoprocessorThreshold) external;
/**
* @notice Update the list of custodians.
* @dev ⚠️ This function should be used with caution. It will be deprecated in the future.
* @param newCustodians The new custodians.
*/
function updateCustodians(Custodian[] calldata newCustodians) external;
/**
* @notice Update the MPC threshold.
* @dev The new threshold must verify `0 <= t < n`, with `n` the number of KMS nodes currently registered.
* @param newMpcThreshold The new MPC threshold.
*/
function updateMpcThreshold(uint256 newMpcThreshold) external;
/**
* @notice Update the public decryption threshold.
* @dev The new threshold must verify `1 <= t <= n`, with `n` the number of KMS nodes currently registered.
* @param newPublicDecryptionThreshold The new public decryption threshold.
*/
function updatePublicDecryptionThreshold(uint256 newPublicDecryptionThreshold) external;
/**
* @notice Update the user decryption threshold.
* @dev The new threshold must verify `1 <= t <= n`, with `n` the number of KMS nodes currently registered.
* @param newUserDecryptionThreshold The new user decryption threshold.
*/
function updateUserDecryptionThreshold(uint256 newUserDecryptionThreshold) external;
/**
* @notice Update the key and CRS generation threshold.
* @dev The new threshold must verify `1 <= t <= n`, with `n` the number of KMS nodes currently registered.
* @param newKmsGenThreshold The new key and CRS generation threshold.
*/
function updateKmsGenThreshold(uint256 newKmsGenThreshold) external;
/**
* @notice Update the coprocessor threshold.
* @dev The new threshold must verify `1 <= t <= n`, with `n` the number of coprocessors currently registered.
* @param newCoprocessorThreshold The new coprocessor threshold.
*/
function updateCoprocessorThreshold(uint256 newCoprocessorThreshold) external;
/**
* @notice Add a new host chain metadata to the GatewayConfig contract.
* @dev The associated chain ID must be non-zero and representable by a uint64.
* @param hostChain The new host chain metadata to include.
*/
function addHostChain(HostChain calldata hostChain) external;
/**
* @notice Pause all pausable gateway contracts.
*/
function pauseAllGatewayContracts() external;
/**
* @notice Unpause all pausable gateway contracts.
*/
function unpauseAllGatewayContracts() external;
/**
* @notice Indicates if an address is a registered KMS transaction sender.
* @param kmsTxSenderAddress The address to check.
*/
function isKmsTxSender(address kmsTxSenderAddress) external view returns (bool);
/**
* @notice Indicates if an address is a registered KMS signer.
* @param signerAddress The address to check.
*/
function isKmsSigner(address signerAddress) external view returns (bool);
/**
* @notice Indicates if an address is a registered coprocessor transaction sender.
* @param coprocessorTxSenderAddress The address to check.
*/
function isCoprocessorTxSender(address coprocessorTxSenderAddress) external view returns (bool);
/**
* @notice Indicates if an address is a registered coprocessor signer.
* @param signerAddress The address to check.
*/
function isCoprocessorSigner(address signerAddress) external view returns (bool);
/**
* @notice Indicates if an address is a registered custodian transaction sender.
* @param txSenderAddress The address to check.
*/
function isCustodianTxSender(address txSenderAddress) external view returns (bool);
/**
* @notice Indicates if an address is a registered custodian signer.
* @param signerAddress The address to check.
*/
function isCustodianSigner(address signerAddress) external view returns (bool);
/**
* @notice Indicates if a chain ID corresponds to a registered host chain.
* @param chainId The chain ID to check.
*/
function isHostChainRegistered(uint256 chainId) external view returns (bool);
/**
* @notice Check if the account is a pauser.
* @return Whether or not the account is a pauser.
*/
function isPauser(address account) external view returns (bool);
/**
* @notice Get the protocol's metadata.
* @return The protocol's metadata.
*/
function getProtocolMetadata() external view returns (ProtocolMetadata memory);
/**
* @notice Get the MPC threshold.
* @return The MPC threshold.
*/
function getMpcThreshold() external view returns (uint256);
/**
* @notice Get the public decryption threshold.
* @return The public decryption threshold.
*/
function getPublicDecryptionThreshold() external view returns (uint256);
/**
* @notice Get the user decryption threshold.
* @return The user decryption threshold.
*/
function getUserDecryptionThreshold() external view returns (uint256);
/**
* @notice Get the key and CRS generation threshold
* @return The key and CRS generation threshold.
*/
function getKmsGenThreshold() external view returns (uint256);
/**
* @notice Get the coprocessor majority threshold
* @return The coprocessor majority threshold.
*/
function getCoprocessorMajorityThreshold() external view returns (uint256);
/**
* @notice Get the metadata of the KMS node with the given transaction sender address.
* @return The KMS node's metadata.
*/
function getKmsNode(address kmsTxSenderAddress) external view returns (KmsNode memory);
/**
* @notice Get the list of all KMS nodes' transaction sender addresses currently registered.
* @return The list of KMS nodes' transaction sender addresses.
*/
function getKmsTxSenders() external view returns (address[] memory);
/**
* @notice Get the list of all KMS nodes' signer addresses currently registered.
* @return The list of KMS nodes' signer addresses.
*/
function getKmsSigners() external view returns (address[] memory);
/**
* @notice Get the metadata of the coprocessor with the given transaction sender address.
* @return The coprocessor's metadata.
*/
function getCoprocessor(address coprocessorTxSenderAddress) external view returns (Coprocessor memory);
/**
* @notice Get the list of all coprocessors' transaction sender addresses currently registered.
* @return The list of coprocessors' transaction sender addresses.
*/
function getCoprocessorTxSenders() external view returns (address[] memory);
/**
* @notice Get the list of all coprocessors' signer addresses currently registered.
* @return The list of coprocessors' signer addresses.
*/
function getCoprocessorSigners() external view returns (address[] memory);
/**
* @notice Get the metadata of the host chain with the given index.
* @return The host chain's metadata.
*/
function getHostChain(uint256 index) external view returns (HostChain memory);
/**
* @notice Get the metadata of all the registered host chains.
* @return The host chains' metadata.
*/
function getHostChains() external view returns (HostChain[] memory);
/**
* @notice Get the metadata of the custodian with the given transaction sender address.
* @return The custodian's metadata.
*/
function getCustodian(address custodianTxSender) external view returns (Custodian memory);
/**
* @notice Get the list of all custodians' transaction sender addresses currently registered.
* @return The list of custodians' transaction sender addresses.
*/
function getCustodianTxSenders() external view returns (address[] memory);
/**
* @notice Get the list of all custodians' signer addresses currently registered.
* @return The list of custodians' signer addresses.
*/
function getCustodianSigners() external view returns (address[] memory);
/**
* @notice Returns the versions of the GatewayConfig contract in SemVer format.
* @dev This is conventionally used for upgrade features.
*/
function getVersion() external pure returns (string memory);
}