Skip to content

Commit d3f3928

Browse files
authored
Merge of #2163
2 parents afd7ee3 + ed0f3da commit d3f3928

File tree

16 files changed

+271
-283
lines changed

16 files changed

+271
-283
lines changed

gateway-contracts/tasks/addPausers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { getRequiredEnvVar, loadGatewayAddresses } from "./utils/loadVariables";
66
// Note: Internal PauserSet address is defined in the `addresses/` directory. It should be used
77
// for local testing. By default, we use the PAUSER_SET_ADDRESS env var, as done in deployment
88
task("task:addGatewayPausers")
9-
.addParam("useInternalPauserSetAddress", "If internal PauserSet address should be used", false, types.boolean)
10-
.setAction(async function ({ useInternalPauserSetAddress }, hre) {
9+
.addParam("useInternalProxyAddress", "If proxy address from the /addresses directory should be used", false, types.boolean)
10+
.setAction(async function ({ useInternalProxyAddress }, hre) {
1111
await hre.run("compile:specific", { contract: "contracts/immutable" });
1212
console.log("Adding pausers to PauserSet contract");
1313

@@ -21,7 +21,7 @@ task("task:addGatewayPausers")
2121
pausers.push(getRequiredEnvVar(`PAUSER_ADDRESS_${idx}`));
2222
}
2323

24-
if (useInternalPauserSetAddress) {
24+
if (useInternalProxyAddress) {
2525
loadGatewayAddresses();
2626
}
2727
const pauserSetAddress = getRequiredEnvVar("PAUSER_SET_ADDRESS");

gateway-contracts/tasks/getters.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
import dotenv from "dotenv";
2-
import fs from "fs";
3-
import { task } from "hardhat/config";
1+
import { task, types } from "hardhat/config";
42
import type { HardhatEthersHelpers, TaskArguments } from "hardhat/types";
53

64
import { GatewayConfig } from "../typechain-types";
75

6+
import { getRequiredEnvVar, loadGatewayAddresses } from "./utils";
7+
88
async function loadGatewayConfigContract(
9-
customGatewayConfigAddress: string | undefined,
9+
useInternalProxyAddress: boolean,
1010
ethers: HardhatEthersHelpers,
1111
): Promise<GatewayConfig> {
12+
if (useInternalProxyAddress) {
13+
loadGatewayAddresses();
14+
}
15+
const gatewayConfigAddress = getRequiredEnvVar("GATEWAY_CONFIG_ADDRESS");
1216
const gatewayConfigFactory = await ethers.getContractFactory("./contracts/GatewayConfig.sol:GatewayConfig");
13-
const gatewayConfigAddress = customGatewayConfigAddress
14-
? customGatewayConfigAddress
15-
: dotenv.parse(fs.readFileSync("addresses/.env.gateway")).GATEWAY_CONFIG_ADDRESS;
1617
return gatewayConfigFactory.attach(gatewayConfigAddress).connect(ethers.provider) as GatewayConfig;
1718
}
1819

1920
task("task:getKmsSigners")
2021
.addOptionalParam(
21-
"customGatewayConfigAddress",
22-
"Use a custom address for the GatewayConfig contract instead of the default one - ie stored inside .env.gateway",
22+
"useInternalProxyAddress",
23+
"If proxy address from the /addresses directory should be used",
24+
false,
25+
types.boolean,
2326
)
2427
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
25-
const gatewayConfig = await loadGatewayConfigContract(taskArguments.customGatewayConfigAddress, ethers);
28+
const gatewayConfig = await loadGatewayConfigContract(taskArguments.useInternalProxyAddress, ethers);
2629
const listCurrentKMSSigners = await gatewayConfig.getKmsSigners();
2730
console.log("The list of current KMS Signers stored inside GatewayConfig contract is: ", listCurrentKMSSigners);
2831
});
2932

3033
task("task:getCoprocessorSigners")
3134
.addOptionalParam(
32-
"customGatewayConfigAddress",
33-
"Use a custom address for the GatewayConfig contract instead of the default one - ie stored inside .env.gateway",
35+
"useInternalProxyAddress",
36+
"If proxy address from the /addresses directory should be used",
37+
false,
38+
types.boolean,
3439
)
3540
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
36-
const gatewayConfig = await loadGatewayConfigContract(taskArguments.customGatewayConfigAddress, ethers);
41+
const gatewayConfig = await loadGatewayConfigContract(taskArguments.useInternalProxyAddress, ethers);
3742
const listCurrentCoprocessorSigners = await gatewayConfig.getCoprocessorSigners();
3843
console.log(
3944
"The list of current Coprocessor Signers stored inside GatewayConfig contract is: ",
@@ -43,11 +48,13 @@ task("task:getCoprocessorSigners")
4348

4449
task("task:getHostChains")
4550
.addOptionalParam(
46-
"customGatewayConfigAddress",
47-
"Use a custom address for the GatewayConfig contract instead of the default one - ie stored inside .env.gateway",
51+
"useInternalProxyAddress",
52+
"If proxy address from the /addresses directory should be used",
53+
false,
54+
types.boolean,
4855
)
4956
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
50-
const gatewayConfig = await loadGatewayConfigContract(taskArguments.customGatewayConfigAddress, ethers);
57+
const gatewayConfig = await loadGatewayConfigContract(taskArguments.useInternalProxyAddress, ethers);
5158
const listCurrentHostChains = await gatewayConfig.getHostChains();
5259
console.log("The list of current host chains stored inside GatewayConfig contract is: ", listCurrentHostChains);
5360
});

gateway-contracts/tasks/reshareKeys.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import dotenv from "dotenv";
21
import { task, types } from "hardhat/config";
3-
import path from "path";
42

5-
import { ADDRESSES_DIR } from "../hardhat.config";
6-
import { getRequiredEnvVar } from "./utils/loadVariables";
3+
import { getRequiredEnvVar, loadGatewayAddresses } from "./utils/loadVariables";
74

85
task("task:prssInit")
96
.addParam(
@@ -20,7 +17,7 @@ task("task:prssInit")
2017
const deployer = new hre.ethers.Wallet(deployerPrivateKey).connect(hre.ethers.provider);
2118

2219
if (useInternalProxyAddress) {
23-
dotenv.config({ path: path.join(ADDRESSES_DIR, ".env.gateway"), override: true });
20+
loadGatewayAddresses();
2421
}
2522
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");
2623

@@ -46,7 +43,7 @@ task("task:keyReshareSameSet")
4643
const deployer = new hre.ethers.Wallet(deployerPrivateKey).connect(hre.ethers.provider);
4744

4845
if (useInternalProxyAddress) {
49-
dotenv.config({ path: path.join(ADDRESSES_DIR, ".env.gateway"), override: true });
46+
loadGatewayAddresses();
5047
}
5148
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");
5249

gateway-contracts/tasks/upgradeContracts.ts

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ async function checkImplementationArtifacts(
106106
}
107107
}
108108

109+
// Helper to perform a standard upgrade: compile, check artifacts, load address, upgrade
110+
async function upgradeContract(
111+
contractName: string,
112+
addressEnvVar: string,
113+
taskArgs: TaskArguments,
114+
hre: HardhatRuntimeEnvironment,
115+
reinitializeArgs: unknown[] = [],
116+
) {
117+
await compileImplementations(taskArgs.currentImplementation, taskArgs.newImplementation, hre);
118+
await checkImplementationArtifacts(contractName, taskArgs.currentImplementation, taskArgs.newImplementation, hre);
119+
120+
if (taskArgs.useInternalProxyAddress) {
121+
loadGatewayAddresses();
122+
}
123+
const proxyAddress = getRequiredEnvVar(addressEnvVar);
124+
125+
await upgradeCurrentToNew(
126+
proxyAddress,
127+
taskArgs.currentImplementation,
128+
taskArgs.newImplementation,
129+
taskArgs.verifyContract,
130+
hre,
131+
reinitializeArgs,
132+
);
133+
}
134+
109135
task("task:upgradeCiphertextCommits")
110136
.addParam(
111137
"currentImplementation",
@@ -127,20 +153,8 @@ task("task:upgradeCiphertextCommits")
127153
true,
128154
types.boolean,
129155
)
130-
.setAction(async function (
131-
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
132-
hre,
133-
) {
134-
await compileImplementations(currentImplementation, newImplementation, hre);
135-
136-
await checkImplementationArtifacts("CiphertextCommits", currentImplementation, newImplementation, hre);
137-
138-
if (useInternalProxyAddress) {
139-
loadGatewayAddresses();
140-
}
141-
const proxyAddress = getRequiredEnvVar("CIPHERTEXT_COMMITS_ADDRESS");
142-
143-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
156+
.setAction(async function (taskArgs: TaskArguments, hre) {
157+
await upgradeContract("CiphertextCommits", "CIPHERTEXT_COMMITS_ADDRESS", taskArgs, hre);
144158
});
145159

146160
task("task:upgradeDecryption")
@@ -164,20 +178,8 @@ task("task:upgradeDecryption")
164178
true,
165179
types.boolean,
166180
)
167-
.setAction(async function (
168-
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
169-
hre,
170-
) {
171-
await compileImplementations(currentImplementation, newImplementation, hre);
172-
173-
await checkImplementationArtifacts("Decryption", currentImplementation, newImplementation, hre);
174-
175-
if (useInternalProxyAddress) {
176-
loadGatewayAddresses();
177-
}
178-
const proxyAddress = getRequiredEnvVar("DECRYPTION_ADDRESS");
179-
180-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
181+
.setAction(async function (taskArgs: TaskArguments, hre) {
182+
await upgradeContract("Decryption", "DECRYPTION_ADDRESS", taskArgs, hre);
181183
});
182184

183185
task("task:upgradeGatewayConfig")
@@ -201,24 +203,9 @@ task("task:upgradeGatewayConfig")
201203
true,
202204
types.boolean,
203205
)
204-
.setAction(async function (
205-
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
206-
hre,
207-
) {
208-
await compileImplementations(currentImplementation, newImplementation, hre);
209-
210-
await checkImplementationArtifacts("GatewayConfig", currentImplementation, newImplementation, hre);
211-
212-
if (useInternalProxyAddress) {
213-
loadGatewayAddresses();
214-
}
215-
const proxyAddress = getRequiredEnvVar("GATEWAY_CONFIG_ADDRESS");
216-
206+
.setAction(async function (taskArgs: TaskArguments, hre) {
217207
const kmsContextId = getRequiredEnvVar("KMS_CONTEXT_ID");
218-
219-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre, [
220-
kmsContextId,
221-
]);
208+
await upgradeContract("GatewayConfig", "GATEWAY_CONFIG_ADDRESS", taskArgs, hre, [kmsContextId]);
222209
});
223210

224211
task("task:upgradeKMSGeneration")
@@ -242,20 +229,8 @@ task("task:upgradeKMSGeneration")
242229
true,
243230
types.boolean,
244231
)
245-
.setAction(async function (
246-
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
247-
hre,
248-
) {
249-
await compileImplementations(currentImplementation, newImplementation, hre);
250-
251-
await checkImplementationArtifacts("KMSGeneration", currentImplementation, newImplementation, hre);
252-
253-
if (useInternalProxyAddress) {
254-
loadGatewayAddresses();
255-
}
256-
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");
257-
258-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
232+
.setAction(async function (taskArgs: TaskArguments, hre) {
233+
await upgradeContract("KMSGeneration", "KMS_GENERATION_ADDRESS", taskArgs, hre);
259234
});
260235

261236
task("task:upgradeInputVerification")
@@ -279,18 +254,6 @@ task("task:upgradeInputVerification")
279254
true,
280255
types.boolean,
281256
)
282-
.setAction(async function (
283-
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
284-
hre,
285-
) {
286-
await compileImplementations(currentImplementation, newImplementation, hre);
287-
288-
await checkImplementationArtifacts("InputVerification", currentImplementation, newImplementation, hre);
289-
290-
if (useInternalProxyAddress) {
291-
loadGatewayAddresses();
292-
}
293-
const proxyAddress = getRequiredEnvVar("INPUT_VERIFICATION_ADDRESS");
294-
295-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
257+
.setAction(async function (taskArgs: TaskArguments, hre) {
258+
await upgradeContract("InputVerification", "INPUT_VERIFICATION_ADDRESS", taskArgs, hre);
296259
});

host-contracts/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ services:
5151
- CHAIN_ID_GATEWAY=54321
5252
- RPC_URL=http://anvil-node:8545
5353
command:
54-
- npx hardhat task:addHostPausers --use-internal-pauser-set-address true
54+
- npx hardhat task:addHostPausers --use-internal-proxy-address true
5555
depends_on:
5656
fhevm-sc-deploy:
5757
condition: service_completed_successfully

host-contracts/hardhat.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { task } from 'hardhat/config';
88
import type { NetworkUserConfig } from 'hardhat/types';
99
import { resolve } from 'path';
1010

11+
export const ADDRESSES_DIR = resolve(__dirname, 'addresses');
12+
export const HOST_ADDRESSES_ENV_FILE_NAME = '.env.host';
13+
1114
import CustomProvider from './CustomProvider';
1215
import './tasks/accounts';
1316
import './tasks/addPausers';
@@ -56,7 +59,7 @@ task('test', async (taskArgs, hre, runSuper) => {
5659
await hre.run('task:deployAllHostContracts');
5760
// Contrary to deployment, here we consider the PauserSet address from the `addresses/` directory
5861
// for local testing
59-
await hre.run('task:addHostPausers', { useInternalPauserSetAddress: true });
62+
await hre.run('task:addHostPausers', { useInternalProxyAddress: true });
6063
}
6164
await hre.run('compile:specific', { contract: 'examples' });
6265
await runSuper();

host-contracts/tasks/addPausers.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import dotenv from 'dotenv';
21
import { task, types } from 'hardhat/config';
3-
import path from 'path';
42

5-
import { getRequiredEnvVar } from './utils/loadVariables';
3+
import { getRequiredEnvVar, loadHostAddresses } from './utils/loadVariables';
64

75
// Add pausers to the PauserSet contract
86
// Note: Internal PauserSet address is defined in the `addresses/` directory. It should be used
97
// for local testing. By default, we use the PAUSER_SET_ADDRESS env var, as done in deployment
108
task('task:addHostPausers')
11-
.addParam('useInternalPauserSetAddress', 'If internal PauserSet address should be used', false, types.boolean)
12-
.setAction(async function ({ useInternalPauserSetAddress }, hre) {
9+
.addParam(
10+
'useInternalProxyAddress',
11+
'If proxy address from the /addresses directory should be used',
12+
false,
13+
types.boolean,
14+
)
15+
.setAction(async function ({ useInternalProxyAddress }, hre) {
1316
await hre.run('compile:specific', { contract: 'contracts/immutable' });
1417
console.log('Adding pausers to PauserSet contract');
1518

@@ -23,8 +26,8 @@ task('task:addHostPausers')
2326
pausers.push(getRequiredEnvVar(`PAUSER_ADDRESS_${idx}`));
2427
}
2528

26-
if (useInternalPauserSetAddress) {
27-
dotenv.config({ path: path.join('addresses/', '.env.host'), override: true });
29+
if (useInternalProxyAddress) {
30+
loadHostAddresses();
2831
}
2932
const pauserSetAddress = getRequiredEnvVar('PAUSER_SET_CONTRACT_ADDRESS');
3033

0 commit comments

Comments
 (0)