Skip to content

Commit 11ed791

Browse files
committed
chore(gateway-contracts): add upgrade test
1 parent a50fc32 commit 11ed791

File tree

5 files changed

+241
-43
lines changed

5 files changed

+241
-43
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: BSD-3-Clause-Clear
2+
3+
pragma solidity ^0.8.24;
4+
5+
import "../CoprocessorContexts.sol";
6+
7+
contract CoprocessorContextsV2Example is CoprocessorContexts {
8+
/// @notice Name of the contract
9+
string private constant CONTRACT_NAME = "CoprocessorContexts";
10+
11+
/// @notice Version of the contract
12+
uint256 private constant MAJOR_VERSION = 1000;
13+
uint256 private constant MINOR_VERSION = 0;
14+
uint256 private constant PATCH_VERSION = 0;
15+
16+
/// @notice Getter for the name and version of the contract
17+
/// @return string representing the name and the version of the contract
18+
function getVersion() external pure virtual override returns (string memory) {
19+
return
20+
string(
21+
abi.encodePacked(
22+
CONTRACT_NAME,
23+
" v",
24+
Strings.toString(MAJOR_VERSION),
25+
".",
26+
Strings.toString(MINOR_VERSION),
27+
".",
28+
Strings.toString(PATCH_VERSION)
29+
)
30+
);
31+
}
32+
}

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

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# CoprocessorContexts contract
22

3-
This section describes the `CoprocessorContexts` contract. It is used to manage the lifecycle of coprocessors for the
4-
fhevm Gateway protocol.
3+
This section describes the `CoprocessorContexts` contract. It is used to manage the lifecycle of coprocessors for the fhevm Gateway protocol.
54

65
Several settings are stored in the contract, which can be separated in several categories:
76

@@ -11,21 +10,18 @@ Several settings are stored in the contract, which can be separated in several c
1110

1211
## Coprocessor
1312

14-
A coprocessor is part of a set of multiple coprocessors, called a coprocessor [context](#coprocessor-context). They are
15-
used to :
13+
A coprocessor is part of a set of multiple coprocessors, called a coprocessor [context](#coprocessor-context). They are used to :
1614

1715
- perform FHE computations on ciphertexts
1816
- verify inputs' zero-knowledge proof of knowledge (ZKPoK) based on requests from the `InputVerification` contract
19-
- handle access controls to ciphertexts for all registered [host chains](./gateway_config.md#host-chains), which are
20-
centralized in the `MultichainAcl` contract
17+
- handle access controls to ciphertexts for all registered [host chains](./gateway_config.md#host-chains), which are centralized in the `MultichainAcl` contract
2118

2219
Several metadata are stored for each coprocessor:
2320

2421
- `name` : name of the coprocessor (indicative)
2522
- `txSenderAddress` : see [Sender and signer](#sender-and-signer) below.
2623
- `signerAddress` : see [Sender and signer](#sender-and-signer) below.
27-
- `s3BucketUrl` : URL of the S3 bucket where the ciphertexts are stored. In the fhevm protocol, this URL is fetched by
28-
the KMS connector in order to download the ciphertexts needed for decryption requests.
24+
- `s3BucketUrl` : URL of the S3 bucket where the ciphertexts are stored. In the fhevm protocol, this URL is fetched by the KMS connector in order to download the ciphertexts needed for decryption requests.
2925

3026
The current list of [active](#lifecycle) coprocessors can be retrieved using the following view function:
3127

@@ -38,34 +34,27 @@ A coprocessor has both a transaction sender and a signer assigned to it:
3834
- `txSenderAddress` : address of the account that will send transactions to the fhevm Gateway.
3935
- `signerAddress` : address associated to the public key used to sign results sent to the fhevm Gateway.
4036

41-
The current list of [active](#lifecycle) coprocessors' transaction senders and signers can be retrieved using the
42-
following view functions:
37+
The current list of [active](#lifecycle) coprocessors' transaction senders and signers can be retrieved using the following view functions:
4338

4439
- `getCoprocessorTxSenders()`: get all the active coprocessors' transaction senders.
4540
- `getCoprocessorSigners()`: get all the active coprocessors' signers.
4641

4742
The transaction sender and signer addresses are allowed to be the same for a given coprocessor.
4843

49-
Additionally, the transaction sender address is used for identifying a coprocessor and may be referred to its
50-
"identity". In particular, these addresses can be used as inputs to following view function for [active](#lifecycle)
51-
coprocessors:
44+
Additionally, the transaction sender address is used for identifying a coprocessor and may be referred to its "identity". In particular, these addresses can be used as inputs to following view function for [active](#lifecycle) coprocessors:
5245

5346
- `getCoprocessor(address coprocessorTxSenderAddress)`: get an active coprocessor's metadata.
5447

5548
## Coprocessor context
5649

57-
A set of coprocessors is called a coprocessor context and must be constituted of at least 1 coprocessor. It stores the
58-
following metadata:
50+
A set of coprocessors is called a coprocessor context and must be constituted of at least 1 coprocessor. It stores the following metadata:
5951

60-
- `contextId`: unique non-zero identifier of the coprocessor context, defined using an incremental counter within the
61-
`CoprocessorContexts` contract.
52+
- `contextId`: unique non-zero identifier of the coprocessor context, defined using an incremental counter within the `CoprocessorContexts` contract.
6253
- `previousContextId`: identifier of the previous coprocessor context.
6354
- `featureSet`: feature set of the coprocessor context, used for updating the coprocessors' software.
6455
- `coprocessors`: list of coprocessors in the coprocessor context.
6556

66-
Currently, the initial coprocessor context is set at deployment of the `CoprocessorContexts` contract and put directly
67-
in the [`active`](#lifecycle) state. In this particular case, the `previousContextId` is set to 0 since there is no
68-
previous coprocessor context to refer to.
57+
Currently, the initial coprocessor context is set at deployment of the `CoprocessorContexts` contract and put directly in the [`active`](#lifecycle) state. In this particular case, the `previousContextId` is set to 0 since there is no previous coprocessor context to refer to.
6958

7059
Coprocessor contexts can be updated over time by the owner for the following reasons:
7160

@@ -76,21 +65,17 @@ Coprocessor contexts can be updated over time by the owner for the following rea
7665

7766
### Lifecycle
7867

79-
Coprocessor context updates follow a lifecycle approach, a general concept applied to other parts of the fhevm Gateway
80-
(ex: KMS nodes, Custodians, FHE keys). It is used to ensure a linear history of contexts and that there is no disruption
81-
in the protocol when updating them.
68+
Coprocessor context updates follow a lifecycle approach, a general concept applied to other parts of the fhevm Gateway (ex: KMS nodes, Custodians, FHE keys). It is used to ensure a linear history of contexts and that there is no disruption in the protocol when updating them.
8269

83-
The lifecycle of a context is defined by the following states, although some of them are not currently used in practice
84-
for coprocessor contexts:
70+
The lifecycle of a context is defined by the following states, although some of them are not currently used in practice for coprocessor contexts:
8571

8672
- `generating`: currently not used.
8773
- `pre-activation`: the coprocessor context will be activated in a certain amount of blocks.
8874
- `active`: the coprocessor context can be used for new requests, for example:
8975
- input verification requests
9076
- adding new ciphertext materials
9177
- new allows or delegations
92-
- `suspended`: the coprocessor context cannot be used for new requests and will be deactivated after a certain amount of
93-
blocks. However, it can still be considered for on-going consensus phases, for example:
78+
- `suspended`: the coprocessor context cannot be used for new requests and will be deactivated after a certain amount of blocks. However, it can still be considered for on-going consensus phases, for example:
9479
- proof verification/rejection responses
9580
- on-going additions of ciphertext materials
9681
- on-going allows or delegations
@@ -100,20 +85,16 @@ for coprocessor contexts:
10085

10186
Additionally:
10287

103-
- in case of emergency (ex: bad software update), the owner can directly move a context from `suspended` back to
104-
`active`, which deactivates the context with issues.
105-
- an `active` context cannot be set to `compromised`,`deactivated` or `destroyed`, in order to ensure that the fhevm
106-
Gateway always has one active context.
88+
- in case of emergency (ex: bad software update), the owner can directly move a context from `suspended` back to `active`, which deactivates the context with issues.
89+
- an `active` context cannot be set to `compromised`,`deactivated` or `destroyed`, in order to ensure that the fhevm Gateway always has one active context.
10790

10891
The complete lifecycle of a coprocessor context is represented in the following diagram:
10992

11093
![Context lifecycle](../../.assets/lifecycle_contexts.png)
11194

11295
### Automatic status refresh
11396

114-
Coprocessor context statuses that need to be updated based on the current block number are refreshed using the
115-
`refreshCoprocessorContextStatuses` function. This function can be called by anyone, but most importantly, it is called
116-
by any of the following functions as a pre-hook modifier:
97+
Coprocessor context statuses that need to be updated based on the current block number are refreshed using the `refreshCoprocessorContextStatuses` function. This function can be called by anyone, but most importantly, it is called by any of the following functions as a pre-hook modifier:
11798

11899
- in `CiphertextCommits` contract:
119100
- `addCiphertextMaterial`
@@ -130,8 +111,7 @@ This ensures that the statuses are always up to date when performing the above a
130111

131112
## Owner
132113

133-
Similarly to other contracts, the `CoprocessorContexts` contract is ownable. The `owner` account is allowed to perform
134-
several restricted actions:
114+
Similarly to other contracts, the `CoprocessorContexts` contract is ownable. The `owner` account is allowed to perform several restricted actions:
135115

136116
- upgrade the contract
137117
- add a new coprocessor context

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ HOST_CHAIN_WEBSITE_0="https://host-chain-2025.com" # (string)
151151

152152
### CoprocessorContexts values
153153

154-
These values are crucial for the fhevm Gateway protocol and are set in the `CoprocessorContexts` contract at deployment.
155-
To understand what each value is used for, please refer to the
156-
[CoprocessorContexts](../contracts/coprocessor_contexts.md) documentation.
154+
These values are crucial for the fhevm Gateway protocol and are set in the `CoprocessorContexts` contract at deployment. To understand what each value is used for, please refer to the [CoprocessorContexts](../contracts/coprocessor_contexts.md) documentation.
157155

158156
#### At deployment
159157

@@ -173,10 +171,7 @@ This integer is used to identify the feature set of the coprocessors for softwar
173171
NUM_COPROCESSORS="3" # (number)
174172
```
175173

176-
`NUM_COPROCESSORS` is the number of coprocessors to register in the `CoprocessorContexts` contract. It it not stored in
177-
it and is only used within the deployment script. The following metadata variables must be set for each coprocessor,
178-
indexed by a coprocessor number starting from 0. If not enough variables are set, the deployment will fail. If, on the
179-
contrary, too many variables are set, the deployment will succeed but the extra ones will be ignored.
174+
`NUM_COPROCESSORS` is the number of coprocessors to register in the `CoprocessorContexts` contract. It it not stored in it and is only used within the deployment script. The following metadata variables must be set for each coprocessor, indexed by a coprocessor number starting from 0. If not enough variables are set, the deployment will fail. If, on the contrary, too many variables are set, the deployment will succeed but the extra ones will be ignored.
180175

181176
```bash
182177
COPROCESSOR_NAME_0="Coprocessor 1" # (string)

0 commit comments

Comments
 (0)