Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gateway-contracts/tasks/addPausers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getRequiredEnvVar, loadGatewayAddresses } from "./utils/loadVariables";
// Note: Internal PauserSet address is defined in the `addresses/` directory. It should be used
// for local testing. By default, we use the PAUSER_SET_ADDRESS env var, as done in deployment
task("task:addGatewayPausers")
.addParam("useInternalPauserSetAddress", "If internal PauserSet address should be used", false, types.boolean)
.setAction(async function ({ useInternalPauserSetAddress }, hre) {
.addParam("useInternalProxyAddress", "If proxy address from the /addresses directory should be used", false, types.boolean)
.setAction(async function ({ useInternalProxyAddress }, hre) {
await hre.run("compile:specific", { contract: "contracts/immutable" });
console.log("Adding pausers to PauserSet contract");

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

if (useInternalPauserSetAddress) {
if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const pauserSetAddress = getRequiredEnvVar("PAUSER_SET_ADDRESS");
Expand Down
39 changes: 23 additions & 16 deletions gateway-contracts/tasks/getters.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
import dotenv from "dotenv";
import fs from "fs";
import { task } from "hardhat/config";
import { task, types } from "hardhat/config";
import type { HardhatEthersHelpers, TaskArguments } from "hardhat/types";

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

import { getRequiredEnvVar, loadGatewayAddresses } from "./utils";

async function loadGatewayConfigContract(
customGatewayConfigAddress: string | undefined,
useInternalProxyAddress: boolean,
ethers: HardhatEthersHelpers,
): Promise<GatewayConfig> {
if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const gatewayConfigAddress = getRequiredEnvVar("GATEWAY_CONFIG_ADDRESS");
const gatewayConfigFactory = await ethers.getContractFactory("./contracts/GatewayConfig.sol:GatewayConfig");
const gatewayConfigAddress = customGatewayConfigAddress
? customGatewayConfigAddress
: dotenv.parse(fs.readFileSync("addresses/.env.gateway")).GATEWAY_CONFIG_ADDRESS;
return gatewayConfigFactory.attach(gatewayConfigAddress).connect(ethers.provider) as GatewayConfig;
}

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

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

task("task:getHostChains")
.addOptionalParam(
"customGatewayConfigAddress",
"Use a custom address for the GatewayConfig contract instead of the default one - ie stored inside .env.gateway",
"useInternalProxyAddress",
"If proxy address from the /addresses directory should be used",
false,
types.boolean,
)
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const gatewayConfig = await loadGatewayConfigContract(taskArguments.customGatewayConfigAddress, ethers);
const gatewayConfig = await loadGatewayConfigContract(taskArguments.useInternalProxyAddress, ethers);
const listCurrentHostChains = await gatewayConfig.getHostChains();
console.log("The list of current host chains stored inside GatewayConfig contract is: ", listCurrentHostChains);
});
9 changes: 3 additions & 6 deletions gateway-contracts/tasks/reshareKeys.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import dotenv from "dotenv";
import { task, types } from "hardhat/config";
import path from "path";

import { ADDRESSES_DIR } from "../hardhat.config";
import { getRequiredEnvVar } from "./utils/loadVariables";
import { getRequiredEnvVar, loadGatewayAddresses } from "./utils/loadVariables";

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

if (useInternalProxyAddress) {
dotenv.config({ path: path.join(ADDRESSES_DIR, ".env.gateway"), override: true });
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");

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

if (useInternalProxyAddress) {
dotenv.config({ path: path.join(ADDRESSES_DIR, ".env.gateway"), override: true });
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");

Expand Down
109 changes: 36 additions & 73 deletions gateway-contracts/tasks/upgradeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ async function checkImplementationArtifacts(
}
}

// Helper to perform a standard upgrade: compile, check artifacts, load address, upgrade
async function upgradeContract(
contractName: string,
addressEnvVar: string,
taskArgs: TaskArguments,
hre: HardhatRuntimeEnvironment,
reinitializeArgs: unknown[] = [],
) {
await compileImplementations(taskArgs.currentImplementation, taskArgs.newImplementation, hre);
await checkImplementationArtifacts(contractName, taskArgs.currentImplementation, taskArgs.newImplementation, hre);

if (taskArgs.useInternalProxyAddress) {
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar(addressEnvVar);

await upgradeCurrentToNew(
proxyAddress,
taskArgs.currentImplementation,
taskArgs.newImplementation,
taskArgs.verifyContract,
hre,
reinitializeArgs,
);
}

task("task:upgradeCiphertextCommits")
.addParam(
"currentImplementation",
Expand All @@ -127,20 +153,8 @@ task("task:upgradeCiphertextCommits")
true,
types.boolean,
)
.setAction(async function (
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
hre,
) {
await compileImplementations(currentImplementation, newImplementation, hre);

await checkImplementationArtifacts("CiphertextCommits", currentImplementation, newImplementation, hre);

if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("CIPHERTEXT_COMMITS_ADDRESS");

await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
.setAction(async function (taskArgs: TaskArguments, hre) {
await upgradeContract("CiphertextCommits", "CIPHERTEXT_COMMITS_ADDRESS", taskArgs, hre);
});

task("task:upgradeDecryption")
Expand All @@ -164,20 +178,8 @@ task("task:upgradeDecryption")
true,
types.boolean,
)
.setAction(async function (
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
hre,
) {
await compileImplementations(currentImplementation, newImplementation, hre);

await checkImplementationArtifacts("Decryption", currentImplementation, newImplementation, hre);

if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("DECRYPTION_ADDRESS");

await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
.setAction(async function (taskArgs: TaskArguments, hre) {
await upgradeContract("Decryption", "DECRYPTION_ADDRESS", taskArgs, hre);
});

task("task:upgradeGatewayConfig")
Expand All @@ -201,24 +203,9 @@ task("task:upgradeGatewayConfig")
true,
types.boolean,
)
.setAction(async function (
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
hre,
) {
await compileImplementations(currentImplementation, newImplementation, hre);

await checkImplementationArtifacts("GatewayConfig", currentImplementation, newImplementation, hre);

if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("GATEWAY_CONFIG_ADDRESS");

.setAction(async function (taskArgs: TaskArguments, hre) {
const kmsContextId = getRequiredEnvVar("KMS_CONTEXT_ID");

await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre, [
kmsContextId,
]);
await upgradeContract("GatewayConfig", "GATEWAY_CONFIG_ADDRESS", taskArgs, hre, [kmsContextId]);
});

task("task:upgradeKMSGeneration")
Expand All @@ -242,20 +229,8 @@ task("task:upgradeKMSGeneration")
true,
types.boolean,
)
.setAction(async function (
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
hre,
) {
await compileImplementations(currentImplementation, newImplementation, hre);

await checkImplementationArtifacts("KMSGeneration", currentImplementation, newImplementation, hre);

if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");

await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
.setAction(async function (taskArgs: TaskArguments, hre) {
await upgradeContract("KMSGeneration", "KMS_GENERATION_ADDRESS", taskArgs, hre);
});

task("task:upgradeInputVerification")
Expand All @@ -279,18 +254,6 @@ task("task:upgradeInputVerification")
true,
types.boolean,
)
.setAction(async function (
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
hre,
) {
await compileImplementations(currentImplementation, newImplementation, hre);

await checkImplementationArtifacts("InputVerification", currentImplementation, newImplementation, hre);

if (useInternalProxyAddress) {
loadGatewayAddresses();
}
const proxyAddress = getRequiredEnvVar("INPUT_VERIFICATION_ADDRESS");

await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
.setAction(async function (taskArgs: TaskArguments, hre) {
await upgradeContract("InputVerification", "INPUT_VERIFICATION_ADDRESS", taskArgs, hre);
});
2 changes: 1 addition & 1 deletion host-contracts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
- CHAIN_ID_GATEWAY=54321
- RPC_URL=http://anvil-node:8545
command:
- npx hardhat task:addHostPausers --use-internal-pauser-set-address true
- npx hardhat task:addHostPausers --use-internal-proxy-address true
depends_on:
fhevm-sc-deploy:
condition: service_completed_successfully
Expand Down
5 changes: 4 additions & 1 deletion host-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { task } from 'hardhat/config';
import type { NetworkUserConfig } from 'hardhat/types';
import { resolve } from 'path';

export const ADDRESSES_DIR = resolve(__dirname, 'addresses');
export const HOST_ADDRESSES_ENV_FILE_NAME = '.env.host';

import CustomProvider from './CustomProvider';
import './tasks/accounts';
import './tasks/addPausers';
Expand Down Expand Up @@ -56,7 +59,7 @@ task('test', async (taskArgs, hre, runSuper) => {
await hre.run('task:deployAllHostContracts');
// Contrary to deployment, here we consider the PauserSet address from the `addresses/` directory
// for local testing
await hre.run('task:addHostPausers', { useInternalPauserSetAddress: true });
await hre.run('task:addHostPausers', { useInternalProxyAddress: true });
}
await hre.run('compile:specific', { contract: 'examples' });
await runSuper();
Expand Down
17 changes: 10 additions & 7 deletions host-contracts/tasks/addPausers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import dotenv from 'dotenv';
import { task, types } from 'hardhat/config';
import path from 'path';

import { getRequiredEnvVar } from './utils/loadVariables';
import { getRequiredEnvVar, loadHostAddresses } from './utils/loadVariables';

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

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

if (useInternalPauserSetAddress) {
dotenv.config({ path: path.join('addresses/', '.env.host'), override: true });
if (useInternalProxyAddress) {
loadHostAddresses();
}
const pauserSetAddress = getRequiredEnvVar('PAUSER_SET_CONTRACT_ADDRESS');

Expand Down
Loading
Loading