Skip to content

Commit 756a304

Browse files
authored
chore(gateway-contracts): clean pausing mechanism and add documentation (#894)
* chore(gateway-contracts): clean pausing mechanism and add documentation
1 parent 0339bc0 commit 756a304

33 files changed

+720
-624
lines changed

gateway-contracts/.env.example

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ HOST_CHAIN_ACL_ADDRESS_3="0xabcdef1234567890abcdef1234567890abcdef12" # (address
118118
HOST_CHAIN_NAME_3="Host chain 2028" # (string)
119119
HOST_CHAIN_WEBSITE_3="https://host-chain-2028.com" # (string)
120120

121+
# Pausers
122+
# The number of pausers must be lower or equal to the number of pausers' address defined below
123+
NUM_PAUSERS="2"
124+
125+
# Pauser 1
126+
PAUSER_ADDRESS_0="0x6591319B97979Acc59b7191A8B4Ec381375bFc92" # accounts[23] (address)
127+
128+
# Pauser 2
129+
PAUSER_ADDRESS_1="0xb19e21437c47A541842bB84b018d3955462B35De" # accounts[24] (address)
130+
121131
# FHE Parameters
122132
FHE_PARAMS_NAME="TEST" # (string)
123133
FHE_PARAMS_DIGEST="0xd61fa44c57b6e7526a46e1072d63332ab4eb38e050fe54dd51fe995f9055c354" # (bytes32)
@@ -128,7 +138,6 @@ FHE_PARAMS_DIGEST="0xd61fa44c57b6e7526a46e1072d63332ab4eb38e050fe54dd51fe995f905
128138
# For tests, this address is read directly from the addresses/.env.gateway file, so the value in this file is ignored.
129139
GATEWAY_CONFIG_ADDRESS="0xC7D45661a345eC5cA0e8521CFEF7e32FDA0Daa68" # (address)
130140

131-
# Pausers
132-
NUM_PAUSERS="1"
133-
PAUSER_ADDRESS_0="0xa44366bAA26296c1409AD1e284264212029F02f1" # accounts[2] (address)
134-
PAUSER_PRIVATE_KEY_0="0x7ae52cf0d3011ef7fecbe22d9537aeda1a9e42a0596e8def5d49970eb59e7a40" # accounts[2], private key (bytes32)
141+
# The first pauser's private key
142+
# This is required for local tests and running the pausing task. It must correspond to one of the pauser's private key
143+
PAUSER_PRIVATE_KEY="0x3588ffb4f4d9bea785a012b895543fe68f2d580a9d449decc91a25878064079a" # accounts[22], private key (bytes32)

gateway-contracts/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ coverage: clean
2222
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat coverage
2323

2424
get-accounts:
25-
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat get-accounts --num-accounts 20
25+
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat get-accounts
2626

2727
start-local-node: clean
2828
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat node --port 8757
@@ -82,10 +82,14 @@ conformance: prettier update-bindings update-mocks update-selectors
8282
deploy-empty-proxies:
8383
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat task:deployEmptyUUPSProxies
8484

85+
# Deploy the pauser set contract
8586
deploy-pauser-set:
8687
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat compile:specific --contract contracts/immutable
8788
DOTENV_CONFIG_PATH=$(ENV_PATH) npx hardhat task:deployPauserSet
8889

90+
# Deploy the contracts needed for deploying the gateway contracts
91+
deploy-setup-contracts: deploy-empty-proxies deploy-pauser-set
92+
8993
# Ensure that the empty proxy addresses exists as these are required for contract compilation.
9094
# In addition, ensure that the addresses match the ones used in local development in order to
9195
# avoid discrepancies between local and CI (e.g., when generating and checking rust bindings).

gateway-contracts/contracts/GatewayConfig.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ contract GatewayConfig is IGatewayConfig, Ownable2StepUpgradeable, UUPSUpgradeab
4141
/// @notice The contract's variable storage struct (@dev see ERC-7201)
4242
/// @custom:storage-location erc7201:fhevm_gateway.storage.GatewayConfig
4343
struct GatewayConfigStorage {
44-
/// @notice The pauser's address
45-
/// @notice TODO: deprecated, to remove for mainnet
46-
address pauser;
44+
/// @notice DEPRECATED: to remove for mainnet
45+
address pauser; // DEPRECATED
4746
/// @notice The KMS nodes' transaction sender addresses
4847
mapping(address kmsTxSenderAddress => bool isKmsTxSender) _isKmsTxSender;
4948
/// @notice The KMS nodes' signer addresses

gateway-contracts/contracts/immutable/PauserSet.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ contract PauserSet is IPauserSet, GatewayConfigChecks {
2323

2424
/// @dev See {IPauserSet-addPauser}.
2525
function addPauser(address account) external onlyGatewayOwner {
26-
if (account == address(0)) revert PauserCannotBeNull();
27-
if (pausers[account]) revert AccountIsAlreadyPauser(account);
26+
if (account == address(0)) revert InvalidNullPauser();
27+
if (pausers[account]) revert AccountAlreadyPauser(account);
2828
pausers[account] = true;
29-
emit NewPauser(account);
29+
emit AddPauser(account);
3030
}
3131

3232
/// @dev See {IPauserSet-removePauser}.
3333
function removePauser(address account) external onlyGatewayOwner {
34-
if (account == address(0)) revert PauserCannotBeNull();
35-
if (!pausers[account]) revert AccountIsNotPauser(account);
34+
if (account == address(0)) revert InvalidNullPauser();
35+
if (!pausers[account]) revert AccountNotPauser(account);
3636
pausers[account] = false;
37-
emit RemovedPauser(account);
37+
emit RemovePauser(account);
3838
}
3939

4040
/// @dev See {IPauserSet-isPauser}.

gateway-contracts/contracts/interfaces/IGatewayConfig.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ interface IGatewayConfig {
240240

241241
/**
242242
* @notice Check if the account is a pauser.
243-
* @return whether or not the account is a pauser.
243+
* @return Whether or not the account is a pauser.
244244
*/
245245
function isPauser(address account) external view returns (bool);
246246

gateway-contracts/contracts/interfaces/IPauserSet.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ interface IPauserSet {
1111
* @notice Emitted when a new pauser is added.
1212
* @param account The address of the new pauser.
1313
*/
14-
event NewPauser(address account);
14+
event AddPauser(address account);
1515

1616
/**
1717
* @notice Emitted when an old pauser is removed.
1818
* @param account The address of the old pauser.
1919
*/
20-
event RemovedPauser(address account);
20+
event RemovePauser(address account);
2121

2222
/**
2323
* @notice Error indicating that the given account is already a pauser.
2424
* @param account The address of the account.
2525
*/
26-
error AccountIsAlreadyPauser(address account);
26+
error AccountAlreadyPauser(address account);
2727

2828
/**
2929
* @notice Error indicating that the given account is not a pauser.
3030
* @param account The address of the account.
3131
*/
32-
error AccountIsNotPauser(address account);
32+
error AccountNotPauser(address account);
3333

3434
/**
3535
* @notice Error indicating that the given account is the null address.
3636
*/
37-
error PauserCannotBeNull();
37+
error InvalidNullPauser();
3838

3939
/**
4040
* @notice Adds a new account as pauser.

gateway-contracts/contracts/mocks/GatewayConfigMock.sol

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import "../shared/Structs.sol";
44

55
contract GatewayConfigMock {
66
event InitializeGatewayConfig(
7-
address pauser,
87
ProtocolMetadata metadata,
98
uint256 mpcThreshold,
109
KmsNode[] kmsNodes,
1110
Coprocessor[] coprocessors,
1211
Custodian[] custodians
1312
);
1413

15-
event ReinitializeGatewayConfigV2(Custodian[] custodians);
16-
17-
event UpdatePauser(address newPauser);
18-
1914
event UpdateMpcThreshold(uint256 newMpcThreshold);
2015

2116
event UpdatePublicDecryptionThreshold(uint256 newPublicDecryptionThreshold);
@@ -29,7 +24,6 @@ contract GatewayConfigMock {
2924
event UnpauseAllGatewayContracts();
3025

3126
function initializeFromEmptyProxy(
32-
address initialPauser,
3327
ProtocolMetadata memory initialMetadata,
3428
uint256 initialMpcThreshold,
3529
uint256 initialPublicDecryptionThreshold,
@@ -38,22 +32,13 @@ contract GatewayConfigMock {
3832
Coprocessor[] memory initialCoprocessors,
3933
Custodian[] memory initialCustodians
4034
) public {
41-
address pauser;
4235
ProtocolMetadata memory metadata;
4336
uint256 mpcThreshold;
4437
KmsNode[] memory kmsNodes = new KmsNode[](1);
4538
Coprocessor[] memory coprocessors = new Coprocessor[](1);
4639
Custodian[] memory custodians = new Custodian[](1);
4740

48-
emit InitializeGatewayConfig(pauser, metadata, mpcThreshold, kmsNodes, coprocessors, custodians);
49-
}
50-
51-
function reinitializeV2(Custodian[] memory custodians) public {
52-
emit ReinitializeGatewayConfigV2(custodians);
53-
}
54-
55-
function updatePauser(address newPauser) external {
56-
emit UpdatePauser(newPauser);
41+
emit InitializeGatewayConfig(metadata, mpcThreshold, kmsNodes, coprocessors, custodians);
5742
}
5843

5944
function updateMpcThreshold(uint256 newMpcThreshold) external {

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Several settings are stored in the contract, which can be separated in several c
66

77
- [Protocol metadata](#protocol-metadata)
88
- [Operators](#operators)
9-
- [Governance accounts](#governance-accounts)
9+
- [Governance](#governance)
1010
- [Host chains](#host-chains)
1111

1212
Except for host chains, they are all set when deploying the `GatewayConfig` contract. Once set, some (but not all) of them can be updated.
@@ -108,34 +108,31 @@ Additionally, the transaction sender address is used for identifying an operator
108108
- `getKmsNode(address kmsTxSenderAddress)`: get a KMS node's metadata.
109109
- `getCoprocessor(address coprocessorTxSenderAddress)`: get a coprocessor's metadata.
110110

111-
## Governance accounts
111+
## Governance
112112

113-
The fhevm Gateway protocol is governed by two accounts:
113+
The fhevm Gateway protocol is governed by the following roles:
114114

115115
- `owner`: account that can perform restricted actions
116-
- `pauser`: account that can pause contract functions
116+
- `pausers`: accounts that can pause contract functions
117117

118118
### Owner
119119

120120
The owner is first set as the account that deploys the contracts (the deployer). It is allowed to perform several restricted actions :
121121

122122
- upgrade the contracts
123-
- update the [pauser](#pauser)
123+
- update the pausers (see [Pausers](./pauser_set.md))
124124
- add [host chains](#host-chains)
125125
- trigger a KMS public material generation (see [KmsManagement](./kms_management.md#public-material-generation))
126126
- update KMS-related parameters (see [KmsManagement](./kms_management.md#store-parameters))
127127

128128
The owner is handled by OpenZeppelin's `Ownable2StepUpgradeable` contract. In particular, this means that the deployer can transfer its ownership to another account in a two-step process.
129129

130-
### Pauser
130+
### Pausers
131131

132-
**Important**: currently, the pauser is not used as the pausing mechanism is not implemented yet.
132+
Details about pausers are available in the following documentation:
133133

134-
The pauser is an account that can pause contract functions. A paused function means that any transaction sent to trigger it will be reverted.
135-
136-
Nothing prevents the pauser from being the owner itself. However, in practice, it can be useful to use different accounts. For example, if they are both governed by multi-sig contracts, the pauser can be set to a lower threshold than the owner in order to pause the protocol quicker in case of emergency.
137-
138-
Currently, it is set at deployment and can be updated by the owner later on.
134+
- [PauserSet](./pauser_set.md)
135+
- [Pausing](../pausing/pausing.md)
139136

140137
### Host chains
141138

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# PauserSet contract
2+
3+
This section describes the `PauserSet` contract. It is used to manage the pausers, addresses that are allowed to pause some of the Gateway contracts.
4+
5+
## Pausers
6+
7+
Pausers are account addresses registered in the `PauserSet` contract. They are expected to be hot wallets controlled by the [operators](./gateway_config.md#operators) of the fhevm Gateway protocol.
8+
9+
They are allowed to pause some of the Gateway contracts. See [Pausing](../pausing/pausing.md) for more details.
10+
11+
## PauserSet
12+
13+
The `PauserSet` contract allows to:
14+
15+
- add a pauser: `addPauser`
16+
- remove a pauser: `removePauser`
17+
- swap a pauser with another address: `swapPauser`
18+
- check if an address is a pauser: `isPauser`
19+
20+
It is deployed as an immutable contract and its address is stored in the `GatewayConfig` contract.

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Here's the complete list of environment variables used for deploying the FHEVM g
2424
| ----------------------------------- | -------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
2525
| `PROTOCOL_NAME` | Name of the protocol to display | string | - | - |
2626
| `PROTOCOL_WEBSITE` | Website of the protocol to display | string | - | - |
27-
| `PAUSER_ADDRESS` | Address of the pauser | address | - | - |
2827
| `MPC_THRESHOLD` | MPC threshold (cryptographic parameter) | uint256 | - | Must be strictly less than the number of KMS nodes registered |
2928
| `PUBLIC_DECRYPTION_THRESHOLD` | Public decryption threshold | uint256 | - | Must be non-null and less than or equal to the number of KMS nodes registered |
3029
| `USER_DECRYPTION_THRESHOLD` | User decryption threshold | uint256 | - | Must be non-null and less than or equal to the number of KMS nodes registered |
@@ -42,6 +41,8 @@ Here's the complete list of environment variables used for deploying the FHEVM g
4241
| `HOST_CHAIN_ACL_ADDRESS_{k}` | ACL address of the host chain `k` | address | - | If `k` >= `NUM_HOST_CHAINS`, the variable is ignored |
4342
| `HOST_CHAIN_NAME_{k}` | Name of the host chain `k` | string | - | If `k` >= `NUM_HOST_CHAINS`, the variable is ignored |
4443
| `HOST_CHAIN_WEBSITE_{k}` | Website of the host chain `k` | string | - | If `k` >= `NUM_HOST_CHAINS`, the variable is ignored |
44+
| `NUM_PAUSERS` | Number of pausers to register | - | - | Must be at least the number of pausers registered below |
45+
| `PAUSER_ADDRESS_{l}` | Address of the pauser `l` | address | - | If `l` >= `NUM_PAUSERS`, the variable is ignored |
4546
| `FHE_PARAMS_NAME` | Name of the parameters to use for FHE keys | string | - | Not used yet |
4647
| `FHE_PARAMS_DIGEST` | Digest of the parameters to use for FHE keys | bytes32 | - | Not used yet |
4748
| `DEPLOYER_PRIVATE_KEY` | Private key for contract deployment | bytes32 | - | - |
@@ -68,12 +69,6 @@ PROTOCOL_NAME="Protocol" # (string)
6869
PROTOCOL_WEBSITE="https://protocol.com" # (string)
6970
```
7071

71-
- Pauser:
72-
73-
```bash
74-
PAUSER_ADDRESS="0xa44366bAA26296c1409AD1e284264212029F02f1" # (address)
75-
```
76-
7772
- KMS Thresholds:
7873

7974
```bash

0 commit comments

Comments
 (0)