Skip to content

Commit 431bbea

Browse files
committed
chore(gateway-contracts): rename keygenThreshold to kmsGenThreshold
1 parent 4dae50d commit 431bbea

File tree

16 files changed

+575
-553
lines changed

16 files changed

+575
-553
lines changed

gateway-contracts/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ MPC_THRESHOLD="1" # (uint256)
2929
PUBLIC_DECRYPTION_THRESHOLD="3" # (uint256)
3030
USER_DECRYPTION_THRESHOLD="3" # (uint256)
3131

32-
# Key and CRS generation responses threshold
33-
KEYGEN_THRESHOLD="3" # (uint256)
32+
# KMS public material (FHE key, CRS) generation responses threshold
33+
KMS_GENERATION_THRESHOLD="3" # (uint256)
3434

3535
# KMS Nodes
3636
# The number of KMS nodes must be lower or equal to the number of KMS nodes' metadata defined below

gateway-contracts/contracts/GatewayConfig.sol

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
114114
mapping(address custodianSignerAddress => bool isCustodianSigner) _isCustodianSigner;
115115
/// @notice The KMS nodes' metadata (V2)
116116
mapping(address kmsTxSenderAddress => KmsNodeV2 kmsNodeV2) kmsNodesV2;
117-
/// @notice The threshold to consider for key and CRS generation consensus.
118-
uint256 keygenThreshold;
117+
/// @notice The threshold to consider for the KMS public material (FHE key, CRS) generation consensus.
118+
uint256 kmsGenThreshold;
119119
}
120120

121121
/// @dev Storage location has been computed using the following command:
@@ -146,7 +146,7 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
146146
uint256 initialMpcThreshold,
147147
uint256 initialPublicDecryptionThreshold,
148148
uint256 initialUserDecryptionThreshold,
149-
uint256 initialKeygenThreshold,
149+
uint256 initialKmsGenThreshold,
150150
KmsNodeV2[] memory initialKmsNodes,
151151
Coprocessor[] memory initialCoprocessors,
152152
Custodian[] memory initialCustodians
@@ -190,7 +190,7 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
190190
_setMpcThreshold(initialMpcThreshold);
191191
_setPublicDecryptionThreshold(initialPublicDecryptionThreshold);
192192
_setUserDecryptionThreshold(initialUserDecryptionThreshold);
193-
_setKeygenThreshold(initialKeygenThreshold);
193+
_setKmsGenThreshold(initialKmsGenThreshold);
194194

195195
/// @dev Register the coprocessors
196196
for (uint256 i = 0; i < initialCoprocessors.length; i++) {
@@ -227,7 +227,7 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
227227
/// @custom:oz-upgrades-validate-as-initializer
228228
function reinitializeV3(
229229
V3UpgradeInput[] memory v3UpgradeInputs,
230-
uint256 keygenThreshold
230+
uint256 kmsGenThreshold
231231
) public virtual reinitializer(REINITIALIZER_VERSION) {
232232
GatewayConfigStorage storage $ = _getGatewayConfigStorage();
233233

@@ -264,7 +264,7 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
264264

265265
/// @dev Setting the threshold should be done after the KMS nodes have been registered as the functions
266266
/// @dev reading the `kmsSignerAddresses` array.
267-
_setKeygenThreshold(keygenThreshold);
267+
_setKmsGenThreshold(kmsGenThreshold);
268268

269269
emit ReinitializeGatewayConfigV3(kmsNodesV1, kmsNodesV2);
270270
}
@@ -297,10 +297,10 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
297297
emit UpdateUserDecryptionThreshold(newUserDecryptionThreshold);
298298
}
299299

300-
/// @dev See {IGatewayConfig-updateKeygenThreshold}.
301-
function updateKeygenThreshold(uint256 newKeygenThreshold) external virtual onlyOwner {
302-
_setKeygenThreshold(newKeygenThreshold);
303-
emit UpdateKeygenThreshold(newKeygenThreshold);
300+
/// @dev See {IGatewayConfig-updateKmsGenThreshold}.
301+
function updateKmsGenThreshold(uint256 newKmsGenThreshold) external virtual onlyOwner {
302+
_setKmsGenThreshold(newKmsGenThreshold);
303+
emit UpdateKmsGenThreshold(newKmsGenThreshold);
304304
}
305305

306306
/// @dev See {IGatewayConfig-addHostChain}.
@@ -429,10 +429,10 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
429429
return $.userDecryptionThreshold;
430430
}
431431

432-
/// @dev See {IGatewayConfig-getKeygenThreshold}.
433-
function getKeygenThreshold() external view virtual returns (uint256) {
432+
/// @dev See {IGatewayConfig-getKmsGenThreshold}.
433+
function getKmsGenThreshold() external view virtual returns (uint256) {
434434
GatewayConfigStorage storage $ = _getGatewayConfigStorage();
435-
return $.keygenThreshold;
435+
return $.kmsGenThreshold;
436436
}
437437

438438
/// @dev See {IGatewayConfig-getCoprocessorMajorityThreshold}.
@@ -585,23 +585,23 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
585585

586586
/**
587587
* @dev Sets the key and CRS generation threshold.
588-
* @param newKeygenThreshold The new key and CRS generation threshold.
588+
* @param newKmsGenThreshold The new key and CRS generation threshold.
589589
*/
590-
function _setKeygenThreshold(uint256 newKeygenThreshold) internal virtual {
590+
function _setKmsGenThreshold(uint256 newKmsGenThreshold) internal virtual {
591591
GatewayConfigStorage storage $ = _getGatewayConfigStorage();
592592
uint256 nKmsNodes = $.kmsSignerAddresses.length;
593593

594594
/// @dev Check that the key and CRS generation threshold `t` is valid. It must verify:
595595
/// @dev - `t >= 1` : the key and CRS generation consensus should require at least one vote
596596
/// @dev - `t <= n` : it should be less than the number of registered KMS nodes
597-
if (newKeygenThreshold == 0) {
598-
revert InvalidNullKeygenThreshold();
597+
if (newKmsGenThreshold == 0) {
598+
revert InvalidNullKmsGenThreshold();
599599
}
600-
if (newKeygenThreshold > nKmsNodes) {
601-
revert InvalidHighKeygenThreshold(newKeygenThreshold, nKmsNodes);
600+
if (newKmsGenThreshold > nKmsNodes) {
601+
revert InvalidHighKmsGenThreshold(newKmsGenThreshold, nKmsNodes);
602602
}
603603

604-
$.keygenThreshold = newKeygenThreshold;
604+
$.kmsGenThreshold = newKmsGenThreshold;
605605
}
606606

607607
/**

gateway-contracts/contracts/KMSManagement.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ contract KMSManagement is
561561
* @return Whether the consensus is reached
562562
*/
563563
function _isKmsConsensusReached(uint256 kmsCounter) internal view virtual returns (bool) {
564-
uint256 consensusThreshold = GATEWAY_CONFIG.getKeygenThreshold();
564+
uint256 consensusThreshold = GATEWAY_CONFIG.getKmsGenThreshold();
565565
return kmsCounter >= consensusThreshold;
566566
}
567567

gateway-contracts/contracts/examples/GatewayConfigV3Example.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contract GatewayConfigV3Example is Ownable2StepUpgradeable, UUPSUpgradeable, Pau
4747
mapping(address custodianTxSenderAddress => bool isCustodianTxSender) _isCustodianTxSender;
4848
mapping(address custodianSignerAddress => bool isCustodianSigner) _isCustodianSigner;
4949
mapping(address kmsTxSenderAddress => KmsNodeV2 kmsNodeV2) kmsNodesV2;
50-
uint256 keygenThreshold;
50+
uint256 kmsGenThreshold;
5151
// New state variables added in the upgraded version
5252
ProtocolMetadataV2 protocolMetadataV2;
5353
}

gateway-contracts/contracts/interfaces/IGatewayConfig.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ interface IGatewayConfig {
7070

7171
/**
7272
* @notice Emitted when the key and CRS generation threshold has been updated.
73-
* @param newKeygenThreshold The new key and CRS generation threshold.
73+
* @param newKmsGenThreshold The new key and CRS generation threshold.
7474
*/
75-
event UpdateKeygenThreshold(uint256 newKeygenThreshold);
75+
event UpdateKmsGenThreshold(uint256 newKmsGenThreshold);
7676

7777
/**
7878
* @notice Emitted when a new host chain has been registered.
@@ -116,10 +116,10 @@ interface IGatewayConfig {
116116
error InvalidHighUserDecryptionThreshold(uint256 userDecryptionThreshold, uint256 nKmsNodes);
117117

118118
/// @notice Error emitted when the key and CRS generation threshold is null.
119-
error InvalidNullKeygenThreshold();
119+
error InvalidNullKmsGenThreshold();
120120

121121
/// @notice Error emitted when the key and CRS generation threshold is strictly greater than the number of KMS nodes.
122-
error InvalidHighKeygenThreshold(uint256 keygenThreshold, uint256 nKmsNodes);
122+
error InvalidHighKmsGenThreshold(uint256 kmsGenThreshold, uint256 nKmsNodes);
123123

124124
/**
125125
* @notice Emitted when all the pausable gateway contracts are paused.
@@ -234,9 +234,9 @@ interface IGatewayConfig {
234234
/**
235235
* @notice Update the key and CRS generation threshold.
236236
* @dev The new threshold must verify `1 <= t <= n`, with `n` the number of KMS nodes currently registered.
237-
* @param newKeygenThreshold The new key and CRS generation threshold.
237+
* @param newKmsGenThreshold The new key and CRS generation threshold.
238238
*/
239-
function updateKeygenThreshold(uint256 newKeygenThreshold) external;
239+
function updateKmsGenThreshold(uint256 newKmsGenThreshold) external;
240240

241241
/**
242242
* @notice Pause all pausable gateway contracts.
@@ -324,7 +324,7 @@ interface IGatewayConfig {
324324
* @notice Get the key and CRS generation threshold
325325
* @return The key and CRS generation threshold.
326326
*/
327-
function getKeygenThreshold() external view returns (uint256);
327+
function getKmsGenThreshold() external view returns (uint256);
328328

329329
/**
330330
* @notice Get the coprocessor majority threshold

gateway-contracts/contracts/mocks/GatewayConfigMock.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract GatewayConfigMock {
2727

2828
event UpdateUserDecryptionThreshold(uint256 newUserDecryptionThreshold);
2929

30-
event UpdateKeygenThreshold(uint256 newKeygenThreshold);
30+
event UpdateKmsGenThreshold(uint256 newKmsGenThreshold);
3131

3232
event AddHostChain(HostChain hostChain);
3333

@@ -41,7 +41,7 @@ contract GatewayConfigMock {
4141
uint256 initialMpcThreshold,
4242
uint256 initialPublicDecryptionThreshold,
4343
uint256 initialUserDecryptionThreshold,
44-
uint256 initialKeygenThreshold,
44+
uint256 initialKmsGenThreshold,
4545
KmsNodeV2[] memory initialKmsNodes,
4646
Coprocessor[] memory initialCoprocessors,
4747
Custodian[] memory initialCustodians
@@ -56,7 +56,7 @@ contract GatewayConfigMock {
5656
emit InitializeGatewayConfig(pauser, metadata, mpcThreshold, kmsNodes, coprocessors, custodians);
5757
}
5858

59-
function reinitializeV3(V3UpgradeInput[] memory v3UpgradeInputs, uint256 keygenThreshold) public {
59+
function reinitializeV3(V3UpgradeInput[] memory v3UpgradeInputs, uint256 kmsGenThreshold) public {
6060
KmsNodeV1[] memory kmsNodesV1 = new KmsNodeV1[](1);
6161
KmsNodeV2[] memory kmsNodesV2 = new KmsNodeV2[](1);
6262

@@ -79,8 +79,8 @@ contract GatewayConfigMock {
7979
emit UpdateUserDecryptionThreshold(newUserDecryptionThreshold);
8080
}
8181

82-
function updateKeygenThreshold(uint256 newKeygenThreshold) external {
83-
emit UpdateKeygenThreshold(newKeygenThreshold);
82+
function updateKmsGenThreshold(uint256 newKmsGenThreshold) external {
83+
emit UpdateKmsGenThreshold(newKmsGenThreshold);
8484
}
8585

8686
function addHostChain(HostChain calldata hostChain) external {

gateway-contracts/docs/getting-started/contracts/gateway_config.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ Both thresholds should be :
7070

7171
These thresholds are set at deployment and can be updated by the owner later on, as long as the above conditions are met.
7272

73+
#### KMS generation threshold
74+
75+
The KMS generation threshold `kmsGenThreshold` is used to determine the minimum number of valid responses from KMS nodes required to validate a KMS public material generation (FHE key, CRS).
76+
77+
This threshold should be :
78+
79+
- non-null: it should require at least one vote
80+
- less or equal to the number of registered KMS nodes: it should not require more than the number of registered KMS nodes
81+
82+
This threshold is set at deployment and can be updated by the owner later on, as long as the above conditions are met.
83+
7384
### Coprocessor
7485

7586
A coprocessor is also part of a set of multiple coprocessors. They are used to :

gateway-contracts/docs/getting-started/deployment/env_variables.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Here's the complete list of environment variables used for deploying the FHEVM g
2828
| `MPC_THRESHOLD` | MPC threshold (cryptographic parameter) | uint256 | - | Must be strictly less than the number of KMS nodes registered |
2929
| `PUBLIC_DECRYPTION_THRESHOLD` | Public decryption threshold | uint256 | - | Must be non-null and less than or equal to the number of KMS nodes registered |
3030
| `USER_DECRYPTION_THRESHOLD` | User decryption threshold | uint256 | - | Must be non-null and less than or equal to the number of KMS nodes registered |
31+
| `KMS_GENERATION_THRESHOLD` | KMS generation (FHE key, CRS) threshold | uint256 | - | Must be non-null and less than or equal to the number of KMS nodes registered |
3132
| `NUM_KMS_NODES` | Number of KMS nodes to register | - | - | Must be at least the number of KMS nodes registered below |
3233
| `KMS_TX_SENDER_ADDRESS_{i}` | Address of the KMS node `i` | address | - | If `i` >= `NUM_KMS_NODES`, the variable is ignored |
3334
| `KMS_SIGNER_ADDRESS_{i}` | Signer address of the KMS node `i` | address | - | If `i` >= `NUM_KMS_NODES`, the variable is ignored |
@@ -88,7 +89,7 @@ USER_DECRYPTION_THRESHOLD="3" # (uint256)
8889

8990
`PUBLIC_DECRYPTION_THRESHOLD` and `USER_DECRYPTION_THRESHOLD` must be non-null and less or equal to the number of KMS nodes registered below.
9091

91-
In practice in the FHEVM protocol, they are set to values using the following formulas:
92+
In practice in the FHEVM protocol, these thresholds are set using the following formulas:
9293

9394
- public decryption threshold: `floor(n/2) + 1`
9495
- user decryption threshold: `2*t + 1`
@@ -97,6 +98,16 @@ With `n` the number of KMS nodes registered below and `t` the MPC threshold.
9798

9899
These values might change in the future.
99100

101+
```bash
102+
KMS_GENERATION_THRESHOLD="3" # (uint256)
103+
```
104+
105+
`KMS_GENERATION_THRESHOLD` must be non-null and less or equal to the number of KMS nodes registered below.
106+
107+
In practice in the FHEVM protocol, this threshold is set to `floor(2n/3) + 1` with `n` the number of KMS nodes registered below.
108+
109+
These values might change in the future.
110+
100111
- KMS Nodes:
101112

102113
```bash

0 commit comments

Comments
 (0)