Skip to content

Commit

Permalink
feat: updated tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Nov 28, 2024
1 parent 34823d7 commit eea682a
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 47 deletions.
28 changes: 22 additions & 6 deletions contracts/tasks/etherscanVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from 'dotenv';
import fs from 'fs';
import { task } from 'hardhat/config';

task('task:verifyContracts').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvACL = dotenv.parse(fs.readFileSync('addresses/.env.acl'));
task('task:verifyACL').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvACL = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.acl'));
const proxyACLAddress = parsedEnvACL.ACL_CONTRACT_ADDRESS;
const implementationACLAddress = await upgrades.erc1967.getImplementationAddress(proxyACLAddress);
await run('verify:verify', {
Expand All @@ -14,8 +14,10 @@ task('task:verifyContracts').setAction(async function (taskArguments, { upgrades
address: proxyACLAddress,
constructorArguments: [],
});
});

const parsedEnvTFHEExecutor = dotenv.parse(fs.readFileSync('addresses/.env.exec'));
task('task:verifyTFHEExecutor').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvTFHEExecutor = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.exec'));
const proxyTFHEExecutorAddress = parsedEnvTFHEExecutor.TFHE_EXECUTOR_CONTRACT_ADDRESS;
const implementationTFHEExecutorAddress = await upgrades.erc1967.getImplementationAddress(proxyTFHEExecutorAddress);
await run('verify:verify', {
Expand All @@ -26,8 +28,12 @@ task('task:verifyContracts').setAction(async function (taskArguments, { upgrades
address: proxyTFHEExecutorAddress,
constructorArguments: [],
});
});

const parsedEnvKMSVerifier = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier'));
task('task:verifyKMSVerifier').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvKMSVerifier = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
);
const proxyKMSVerifier = parsedEnvKMSVerifier.KMS_VERIFIER_CONTRACT_ADDRESS;
const implementationKMSVerifierAddress = await upgrades.erc1967.getImplementationAddress(proxyKMSVerifier);
await run('verify:verify', {
Expand All @@ -38,8 +44,12 @@ task('task:verifyContracts').setAction(async function (taskArguments, { upgrades
address: proxyKMSVerifier,
constructorArguments: [],
});
});

const parsedEnvInputVerifier = dotenv.parse(fs.readFileSync('addresses/.env.inputverifier'));
task('task:verifyInputVerifier').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvInputVerifier = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.inputverifier'),
);
const proxyInputVerifier = parsedEnvInputVerifier.INPUT_VERIFIER_CONTRACT_ADDRESS;
const implementationInputVerifierAddress = await upgrades.erc1967.getImplementationAddress(proxyInputVerifier);
await run('verify:verify', {
Expand All @@ -50,8 +60,12 @@ task('task:verifyContracts').setAction(async function (taskArguments, { upgrades
address: proxyInputVerifier,
constructorArguments: [],
});
});

const parsedEnvFHEPayment = dotenv.parse(fs.readFileSync('addresses/.env.fhepayment'));
task('task:verifyFHEPayment').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvFHEPayment = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.fhepayment'),
);
const proxyFHEPayment = parsedEnvFHEPayment.FHE_PAYMENT_CONTRACT_ADDRESS;
const implementationFHEPaymentAddress = await upgrades.erc1967.getImplementationAddress(proxyFHEPayment);
await run('verify:verify', {
Expand All @@ -62,7 +76,9 @@ task('task:verifyContracts').setAction(async function (taskArguments, { upgrades
address: proxyFHEPayment,
constructorArguments: [],
});
});

task('task:verifyGatewayContract').setAction(async function (taskArguments, { upgrades, run }) {
const parsedEnvGateway = dotenv.parse(fs.readFileSync('gateway/.env.gateway'));
const proxyGateway = parsedEnvGateway.GATEWAY_CONTRACT_PREDEPLOY_ADDRESS;
const implementationGatewayAddress = await upgrades.erc1967.getImplementationAddress(proxyGateway);
Expand Down
34 changes: 34 additions & 0 deletions contracts/tasks/getEthereumAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import dotenv from 'dotenv';
import { ethers } from 'ethers';
import { task } from 'hardhat/config';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

dotenv.config();

const getEthereumAddress =
(index: number = 0) =>
async (_taskArgs: unknown, _: HardhatRuntimeEnvironment) => {
const words = process.env.MNEMONIC!;
const mnemonic = ethers.Mnemonic.fromPhrase(words);
if (!mnemonic) {
throw new Error('No MNEMONIC in .env file');
}
const wallet = ethers.HDNodeWallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0`);
console.log(wallet.deriveChild(index).address);
};

task(
'task:getEthereumAddress',
'Gets the first address derived from a mnemonic phrase defined in .env',
getEthereumAddress(0),
);

const accounts = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve'];

accounts.forEach((name, index) => {
task(
`task:getEthereumAddress${name}`,
'Gets the first address derived from a mnemonic phrase defined in .env',
getEthereumAddress(index),
);
});
88 changes: 74 additions & 14 deletions contracts/tasks/taskDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import fs from 'fs';
import { task, types } from 'hardhat/config';
import type { TaskArguments } from 'hardhat/types';

import { KMSVerifier } from '../types';

task('task:deployGateway')
.addParam('privateKey', 'The deployer private key')
.addParam('ownerAddress', 'The owner address')
Expand All @@ -28,11 +30,11 @@ task('task:deployACL')
.addParam('privateKey', 'The deployer private key')
.setAction(async function (taskArguments: TaskArguments, { ethers, upgrades }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('ACL', deployer);
const factory = await ethers.getContractFactory('fhevmTemp/contracts/ACL.sol:ACL', deployer);
const acl = await upgrades.deployProxy(factory, [deployer.address], { initializer: 'initialize', kind: 'uups' });
await acl.waitForDeployment();
const address = await acl.getAddress();
const envConfigAcl = dotenv.parse(fs.readFileSync('addresses/.env.acl'));
const envConfigAcl = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.acl'));
if (address !== envConfigAcl.ACL_CONTRACT_ADDRESS) {
throw new Error(
`The nonce of the deployer account is not correct. Please relaunch a clean instance of the fhEVM`,
Expand All @@ -47,14 +49,14 @@ task('task:deployTFHEExecutor')
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
let factory;
if (process.env.HARDHAT_TFHEEXECUTOR_EVENTS !== '1') {
factory = await ethers.getContractFactory('contracts/TFHEExecutor.sol:TFHEExecutor', deployer);
factory = await ethers.getContractFactory('fhevmTemp/contracts/TFHEExecutor.sol:TFHEExecutor', deployer);
} else {
factory = await ethers.getContractFactory('contracts/TFHEExecutor.events.sol:TFHEExecutor', deployer);
factory = await ethers.getContractFactory('fhevmTemp/contracts/TFHEExecutor.events.sol:TFHEExecutor', deployer);
}
const exec = await upgrades.deployProxy(factory, [deployer.address], { initializer: 'initialize', kind: 'uups' });
await exec.waitForDeployment();
const address = await exec.getAddress();
const envConfig = dotenv.parse(fs.readFileSync('addresses/.env.exec'));
const envConfig = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.exec'));
if (address !== envConfig.TFHE_EXECUTOR_CONTRACT_ADDRESS) {
throw new Error(
`The nonce of the deployer account is not correct. Please relaunch a clean instance of the fhEVM`,
Expand All @@ -67,11 +69,11 @@ task('task:deployKMSVerifier')
.addParam('privateKey', 'The deployer private key')
.setAction(async function (taskArguments: TaskArguments, { ethers, upgrades }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('KMSVerifier', deployer);
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier', deployer);
const kms = await upgrades.deployProxy(factory, [deployer.address], { initializer: 'initialize', kind: 'uups' });
await kms.waitForDeployment();
const address = await kms.getAddress();
const envConfig = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier'));
const envConfig = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'));
if (address !== envConfig.KMS_VERIFIER_CONTRACT_ADDRESS) {
throw new Error(
`The nonce of the deployer account is not correct. Please relaunch a clean instance of the fhEVM`,
Expand All @@ -86,14 +88,17 @@ task('task:deployInputVerifier')
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
let factory;
if (process.env.IS_COPROCESSOR === 'true') {
factory = await ethers.getContractFactory('contracts/InputVerifier.coprocessor.sol:InputVerifier', deployer);
factory = await ethers.getContractFactory(
'fhevmTemp/contracts/InputVerifier.coprocessor.sol:InputVerifier',
deployer,
);
} else {
factory = await ethers.getContractFactory('contracts/InputVerifier.native.sol:InputVerifier', deployer);
factory = await ethers.getContractFactory('fhevmTemp/contracts/InputVerifier.native.sol:InputVerifier', deployer);
}
const kms = await upgrades.deployProxy(factory, [deployer.address], { initializer: 'initialize', kind: 'uups' });
await kms.waitForDeployment();
const address = await kms.getAddress();
const envConfig = dotenv.parse(fs.readFileSync('addresses/.env.inputverifier'));
const envConfig = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.inputverifier'));
if (address !== envConfig.INPUT_VERIFIER_CONTRACT_ADDRESS) {
throw new Error(
`The nonce of the deployer account is not correct. Please relaunch a clean instance of the fhEVM`,
Expand All @@ -106,14 +111,14 @@ task('task:deployFHEPayment')
.addParam('privateKey', 'The deployer private key')
.setAction(async function (taskArguments: TaskArguments, { ethers, upgrades }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('FHEPayment', deployer);
const factory = await ethers.getContractFactory('fhevmTemp/contracts/FHEPayment.sol:FHEPayment', deployer);
const payment = await upgrades.deployProxy(factory, [deployer.address], {
initializer: 'initialize',
kind: 'uups',
});
await payment.waitForDeployment();
const address = await payment.getAddress();
const envConfig = dotenv.parse(fs.readFileSync('addresses/.env.fhepayment'));
const envConfig = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.fhepayment'));
if (address !== envConfig.FHE_PAYMENT_CONTRACT_ADDRESS) {
throw new Error(
`The nonce of the deployer account is not correct. Please relaunch a clean instance of the fhEVM`,
Expand All @@ -131,10 +136,21 @@ task('task:addSigners')
false,
types.boolean,
)
.addOptionalParam(
'customKmsVerifierAddress',
'Use a custom address for the KMSVerifier contract instead of the default one - ie stored inside .env.kmsverifier',
)
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('KMSVerifier', deployer);
const kmsAdd = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier')).KMS_VERIFIER_CONTRACT_ADDRESS;
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier', deployer);
let kmsAdd;
if (taskArguments.customKmsVerifierAddress) {
kmsAdd = taskArguments.customKmsVerifierAddress;
} else {
kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
}
const kmsVerifier = await factory.attach(kmsAdd);
for (let idx = 0; idx < taskArguments.numSigners; idx++) {
if (!taskArguments.useAddress) {
Expand All @@ -151,3 +167,47 @@ task('task:addSigners')
}
}
});

task('task:getAllSigners')
.addOptionalParam(
'customKmsVerifierAddress',
'Use a custom address for the KMSVerifier contract instead of the default one - ie stored inside .env.kmsverifier',
)
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier');
let kmsAdd;
if (taskArguments.customKmsVerifierAddress) {
kmsAdd = taskArguments.customKmsVerifierAddress;
} else {
kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
}
const kmsVerifier = (await factory.attach(kmsAdd).connect(ethers.provider)) as KMSVerifier;
const listCurrentKMSSigners = await kmsVerifier.getSigners();
console.log('The list of current KMS Signers stored inside KMSVerifier contract is: ', listCurrentKMSSigners);
});

task('task:removeSigner')
.addParam('privateKey', 'The KMSVerifier owner private key')
.addParam('kmsSignerAddress', 'The KMS Signer address you wish to remove')
.addOptionalParam(
'customKmsVerifierAddress',
'Use a custom address for the KMSVerifier contract instead of the default one - ie stored inside .env.kmsverifier',
)
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
const deployer = new ethers.Wallet(taskArguments.privateKey).connect(ethers.provider);
const factory = await ethers.getContractFactory('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier', deployer);
let kmsAdd;
if (taskArguments.customKmsVerifierAddress) {
kmsAdd = taskArguments.customKmsVerifierAddress;
} else {
kmsAdd = dotenv.parse(
fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'),
).KMS_VERIFIER_CONTRACT_ADDRESS;
}
const kmsVerifier = (await factory.attach(kmsAdd)) as KMSVerifier;
const tx = await kmsVerifier.removeSigner(taskArguments.kmsSignerAddress);
await tx.wait();
console.log(`KMS signer with address (${taskArguments.kmsSignerAddress}) was removed from KMSVerifier contract`);
});
Loading

0 comments on commit eea682a

Please sign in to comment.