diff --git a/contracts/.env.example b/contracts/.env.example index 2f87338b..e3bd56db 100644 --- a/contracts/.env.example +++ b/contracts/.env.example @@ -1,4 +1,4 @@ -export MNEMONIC="resemble evidence test leaf stock situate truck umbrella boss roof stand math peanut stay supply" +export MNEMONIC="adapt mosquito move limb mobile illegal tree voyage juice mosquito burger raise father hope layer" export PRIVATE_KEY_FHEVM_DEPLOYER="0c66d8cde71d2faa29d0cb6e3a567d31279b6eace67b0a9d9ba869c119843a5e" export PRIVATE_KEY_GATEWAY_DEPLOYER="717fd99986df414889fd8b51069d4f90a50af72e542c58ee065f5883779099c6" export PRIVATE_KEY_GATEWAY_RELAYER="7ec931411ad75a7c201469a385d6f18a325d4923f9f213bd882bbea87e160b67" @@ -11,5 +11,4 @@ export PRIVATE_KEY_COPROCESSOR_ACCOUNT="7ec8ada6642fc4ccfb7729bc29c17cf8d21b61ab export IS_COPROCESSOR="true" export SEPOLIA_RPC_URL="https://sepolia.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -export MAINNET_RPC_URL="https://mainnet.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export ETHERSCAN_API_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \ No newline at end of file diff --git a/contracts/addresses/.env.acl b/contracts/addresses/.env.acl index 83c07ff7..09bde9b3 100644 --- a/contracts/addresses/.env.acl +++ b/contracts/addresses/.env.acl @@ -1 +1 @@ -ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2 +ACL_CONTRACT_ADDRESS=0x27FFa4b57D619aDF9821A82AD01b434DE25BCC71 diff --git a/contracts/addresses/.env.exec b/contracts/addresses/.env.exec index adba3fce..a18580e9 100644 --- a/contracts/addresses/.env.exec +++ b/contracts/addresses/.env.exec @@ -1 +1 @@ -TFHE_EXECUTOR_CONTRACT_ADDRESS=0x596E6682c72946AF006B27C131793F2b62527A4b +TFHE_EXECUTOR_CONTRACT_ADDRESS=0x556C1C45316Db2372f9b1b6b288D095709574705 diff --git a/contracts/addresses/.env.fhepayment b/contracts/addresses/.env.fhepayment index 2a38d176..1a6c7421 100644 --- a/contracts/addresses/.env.fhepayment +++ b/contracts/addresses/.env.fhepayment @@ -1 +1 @@ -FHE_PAYMENT_CONTRACT_ADDRESS=0x6d5A11aC509C707c00bc3A0a113ACcC26c532547 +FHE_PAYMENT_CONTRACT_ADDRESS=0x2262E4d00777b46846aA7E502Ec43DD592F932e9 diff --git a/contracts/addresses/.env.inputverifier b/contracts/addresses/.env.inputverifier index b628bb02..88725a7c 100644 --- a/contracts/addresses/.env.inputverifier +++ b/contracts/addresses/.env.inputverifier @@ -1 +1 @@ -INPUT_VERIFIER_CONTRACT_ADDRESS=0x69dE3158643e738a0724418b21a35FAA20CBb1c5 +INPUT_VERIFIER_CONTRACT_ADDRESS=0xa50829aC46Ed11158D969334def5e362E5e54Dca diff --git a/contracts/addresses/.env.kmsverifier b/contracts/addresses/.env.kmsverifier index d5db2185..2babe106 100644 --- a/contracts/addresses/.env.kmsverifier +++ b/contracts/addresses/.env.kmsverifier @@ -1 +1 @@ -KMS_VERIFIER_CONTRACT_ADDRESS=0x208De73316E44722e16f6dDFF40881A3e4F86104 +KMS_VERIFIER_CONTRACT_ADDRESS=0x3DBB223F4b5b5Ce62d3c959Cbea57584F314a713 diff --git a/contracts/addresses/ACLAddress.sol b/contracts/addresses/ACLAddress.sol index 06488813..7eecd82a 100644 --- a/contracts/addresses/ACLAddress.sol +++ b/contracts/addresses/ACLAddress.sol @@ -2,4 +2,4 @@ pragma solidity ^0.8.24; -address constant aclAdd = 0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2; +address constant aclAdd = 0x27FFa4b57D619aDF9821A82AD01b434DE25BCC71; diff --git a/contracts/addresses/FHEPaymentAddress.sol b/contracts/addresses/FHEPaymentAddress.sol index 8b0e4358..d980ed06 100644 --- a/contracts/addresses/FHEPaymentAddress.sol +++ b/contracts/addresses/FHEPaymentAddress.sol @@ -2,4 +2,4 @@ pragma solidity ^0.8.24; -address constant fhePaymentAdd = 0x6d5A11aC509C707c00bc3A0a113ACcC26c532547; +address constant fhePaymentAdd = 0x2262E4d00777b46846aA7E502Ec43DD592F932e9; diff --git a/contracts/addresses/InputVerifierAddress.sol b/contracts/addresses/InputVerifierAddress.sol index 6dfb7606..03718f79 100644 --- a/contracts/addresses/InputVerifierAddress.sol +++ b/contracts/addresses/InputVerifierAddress.sol @@ -2,4 +2,4 @@ pragma solidity ^0.8.24; -address constant inputVerifierAdd = 0x69dE3158643e738a0724418b21a35FAA20CBb1c5; +address constant inputVerifierAdd = 0xa50829aC46Ed11158D969334def5e362E5e54Dca; diff --git a/contracts/addresses/KMSVerifierAddress.sol b/contracts/addresses/KMSVerifierAddress.sol index e9293d6b..05a92c34 100644 --- a/contracts/addresses/KMSVerifierAddress.sol +++ b/contracts/addresses/KMSVerifierAddress.sol @@ -2,4 +2,4 @@ pragma solidity ^0.8.24; -address constant kmsVerifierAdd = 0x208De73316E44722e16f6dDFF40881A3e4F86104; +address constant kmsVerifierAdd = 0x3DBB223F4b5b5Ce62d3c959Cbea57584F314a713; diff --git a/contracts/addresses/TFHEExecutorAddress.sol b/contracts/addresses/TFHEExecutorAddress.sol index f13f3da8..92f93c0e 100644 --- a/contracts/addresses/TFHEExecutorAddress.sol +++ b/contracts/addresses/TFHEExecutorAddress.sol @@ -2,4 +2,4 @@ pragma solidity ^0.8.24; -address constant tfheExecutorAdd = 0x596E6682c72946AF006B27C131793F2b62527A4b; +address constant tfheExecutorAdd = 0x556C1C45316Db2372f9b1b6b288D095709574705; diff --git a/contracts/contracts/InputVerifier.native.sol b/contracts/contracts/InputVerifier.native.sol index fa1d4ffb..335feeb1 100644 --- a/contracts/contracts/InputVerifier.native.sol +++ b/contracts/contracts/InputVerifier.native.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.24; import "./KMSVerifier.sol"; import "./TFHEExecutor.sol"; import "../addresses/KMSVerifierAddress.sol"; -import "../addresses/CoprocessorAddress.sol"; // Importing OpenZeppelin contracts for cryptographic signature verification and access control. import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; diff --git a/contracts/contracts/TFHEExecutorWithEvents.sol b/contracts/contracts/TFHEExecutorWithEvents.sol index 1a3df1e3..954efb6f 100644 --- a/contracts/contracts/TFHEExecutorWithEvents.sol +++ b/contracts/contracts/TFHEExecutorWithEvents.sol @@ -216,6 +216,4 @@ contract TFHEExecutorWithEvents is TFHEExecutor { result = super.fheRandBounded(upperBound, randType); emit FheRandBounded(upperBound, randType, result); } - - function _authorizeUpgrade(address _newImplementation) internal virtual override onlyOwner {} } diff --git a/contracts/gateway/.env.gateway b/contracts/gateway/.env.gateway index 0228cb70..7cec111e 100644 --- a/contracts/gateway/.env.gateway +++ b/contracts/gateway/.env.gateway @@ -1 +1 @@ -GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=0x096b4679d45fB675d4e2c1E4565009Cec99A12B1 \ No newline at end of file +GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=0xF2251f93B168a1f49329976efF8615bDB8e24d80 \ No newline at end of file diff --git a/contracts/gateway/GatewayContract.sol b/contracts/gateway/GatewayContract.sol index d6b4ff72..a4bf551b 100644 --- a/contracts/gateway/GatewayContract.sol +++ b/contracts/gateway/GatewayContract.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.24; -import "../lib/TFHE.sol"; import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; diff --git a/contracts/gateway/lib/GatewayContractAddress.sol b/contracts/gateway/lib/GatewayContractAddress.sol index ea9d8976..315231c9 100644 --- a/contracts/gateway/lib/GatewayContractAddress.sol +++ b/contracts/gateway/lib/GatewayContractAddress.sol @@ -2,4 +2,4 @@ pragma solidity ^0.8.24; -address constant GATEWAY_CONTRACT_PREDEPLOY_ADDRESS = 0x096b4679d45fB675d4e2c1E4565009Cec99A12B1; +address constant GATEWAY_CONTRACT_PREDEPLOY_ADDRESS = 0xF2251f93B168a1f49329976efF8615bDB8e24d80; diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 4e0741f6..f8a285a2 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -39,54 +39,6 @@ if (!mnemonic) { mnemonic = 'adapt mosquito move limb mobile illegal tree voyage juice mosquito burger raise father hope layer'; // default mnemonic in case it is undefined (needed to avoid panicking when deploying on real network) } -const chainIds = { - zama: 8009, - local: 9000, - localCoprocessor: 12345, - localNetwork1: 9000, - multipleValidatorTestnet: 8009, - sepolia: 11155111, - mainnet: 1, -}; - -function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig { - let jsonRpcUrl: string; - switch (chain) { - case 'local': - jsonRpcUrl = 'http://localhost:8545'; - break; - case 'localCoprocessor': - jsonRpcUrl = 'http://localhost:8745'; - break; - case 'localNetwork1': - jsonRpcUrl = 'http://127.0.0.1:9650/ext/bc/fhevm/rpc'; - break; - case 'multipleValidatorTestnet': - jsonRpcUrl = 'https://rpc.fhe-ethermint.zama.ai'; - break; - case 'zama': - jsonRpcUrl = 'https://devnet.zama.ai'; - break; - case 'sepolia': - jsonRpcUrl = process.env.SEPOLIA_RPC_URL!; - break; - case 'mainnet': - jsonRpcUrl = process.env.MAINNET_RPC_URL!; - break; - default: - throw new Error(`unsupported chain: ${chain}`); - } - return { - accounts: { - count: 10, - mnemonic, - path: "m/44'/60'/0'/0", - }, - chainId: chainIds[chain], - url: jsonRpcUrl, - }; -} - task('coverage').setAction(async (taskArgs, hre, runSuper) => { hre.config.networks.hardhat.allowUnlimitedContractSize = true; hre.config.networks.hardhat.blockGasLimit = 1099511627775; @@ -127,8 +79,42 @@ task('test', async (taskArgs, hre, runSuper) => { await runSuper(); }); +const chainIds = { + localNative: 8009, + devnetNative: 9000, + localCoprocessor: 12345, + sepolia: 11155111, + mainnet: 1, +}; + +function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig { + let jsonRpcUrl: string; + switch (chain) { + case 'sepolia': + jsonRpcUrl = process.env.SEPOLIA_RPC_URL!; + break; + case 'localCoprocessor': + jsonRpcUrl = 'http://localhost:8745'; + break; + case 'localNative': + jsonRpcUrl = 'http://localhost:8545'; + break; + default: + throw new Error(`unsupported chain: ${chain}`); + } + return { + accounts: { + count: 10, + mnemonic, + path: "m/44'/60'/0'/0", + }, + chainId: chainIds[chain], + url: jsonRpcUrl, + }; +} + const config: HardhatUserConfig = { - defaultNetwork: 'local', + defaultNetwork: 'sepolia', namedAccounts: { deployer: 0, }, @@ -150,18 +136,13 @@ const config: HardhatUserConfig = { }, }, sepolia: getChainConfig('sepolia'), - mainnet: getChainConfig('mainnet'), - zama: getChainConfig('zama'), - localDev: getChainConfig('local'), - local: getChainConfig('local'), + localNative: getChainConfig('localNative'), localCoprocessor: getChainConfig('localCoprocessor'), - localNetwork1: getChainConfig('localNetwork1'), - multipleValidatorTestnet: getChainConfig('multipleValidatorTestnet'), }, paths: { artifacts: './artifacts', cache: './cache', - sources: './examples', + sources: './contracts', tests: './test', }, solidity: { diff --git a/contracts/launch-fhevm-sepolia.sh b/contracts/launch-fhevm-sepolia.sh new file mode 100644 index 00000000..d2955af0 --- /dev/null +++ b/contracts/launch-fhevm-sepolia.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# This script should be launched after precomputing the addresses via `precompute-addresses.sh`, and preferably after setting up the different services - KMS, Geth node, Gateway +npx hardhat clean + +PRIVATE_KEY_FHEVM_DEPLOYER=$(grep PRIVATE_KEY_FHEVM_DEPLOYER .env | cut -d '"' -f 2) +NUM_KMS_SIGNERS=$(grep NUM_KMS_SIGNERS .env | cut -d '"' -f 2) + +npx hardhat compile +npx hardhat compile:specific --contract gateway + +npx hardhat task:deployACL --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network sepolia +npx hardhat task:deployTFHEExecutor --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network sepolia +npx hardhat task:deployKMSVerifier --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network sepolia +npx hardhat task:deployInputVerifier --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network sepolia +npx hardhat task:deployFHEPayment --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network sepolia + +npx hardhat task:addSigners --num-signers "$NUM_KMS_SIGNERS" --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --use-address true --network sepolia + +npx hardhat task:launchFhevm --skip-get-coin true --use-address true --network sepolia + +echo "Waiting 2 minutes before contract verification... Please wait..." +sleep 120 # makes sure that contracts bytescode propagates on Etherscan, otherwise contracts verification might fail in next step +npx hardhat task:verifyACL --network sepolia +npx hardhat task:verifyTFHEExecutor --network sepolia +npx hardhat task:verifyKMSVerifier --network sepolia +npx hardhat task:verifyInputVerifier --network sepolia +npx hardhat task:verifyFHEPayment --network sepolia +npx hardhat task:verifyGatewayContract --network sepolia \ No newline at end of file diff --git a/contracts/tasks/etherscanVerify.ts b/contracts/tasks/etherscanVerify.ts index 0a8f8c51..1567f660 100644 --- a/contracts/tasks/etherscanVerify.ts +++ b/contracts/tasks/etherscanVerify.ts @@ -3,7 +3,7 @@ import fs from 'fs'; import { task } from 'hardhat/config'; task('task:verifyACL').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvACL = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.acl')); + const parsedEnvACL = dotenv.parse(fs.readFileSync('addresses/.env.acl')); const proxyACLAddress = parsedEnvACL.ACL_CONTRACT_ADDRESS; const implementationACLAddress = await upgrades.erc1967.getImplementationAddress(proxyACLAddress); await run('verify:verify', { @@ -17,7 +17,7 @@ task('task:verifyACL').setAction(async function (taskArguments, { upgrades, run }); task('task:verifyTFHEExecutor').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvTFHEExecutor = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.exec')); + const parsedEnvTFHEExecutor = dotenv.parse(fs.readFileSync('addresses/.env.exec')); const proxyTFHEExecutorAddress = parsedEnvTFHEExecutor.TFHE_EXECUTOR_CONTRACT_ADDRESS; const implementationTFHEExecutorAddress = await upgrades.erc1967.getImplementationAddress(proxyTFHEExecutorAddress); await run('verify:verify', { @@ -31,9 +31,7 @@ task('task:verifyTFHEExecutor').setAction(async function (taskArguments, { upgra }); task('task:verifyKMSVerifier').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvKMSVerifier = dotenv.parse( - fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'), - ); + const parsedEnvKMSVerifier = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier')); const proxyKMSVerifier = parsedEnvKMSVerifier.KMS_VERIFIER_CONTRACT_ADDRESS; const implementationKMSVerifierAddress = await upgrades.erc1967.getImplementationAddress(proxyKMSVerifier); await run('verify:verify', { @@ -47,9 +45,7 @@ task('task:verifyKMSVerifier').setAction(async function (taskArguments, { upgrad }); task('task:verifyInputVerifier').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvInputVerifier = dotenv.parse( - fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.inputverifier'), - ); + const parsedEnvInputVerifier = dotenv.parse(fs.readFileSync('addresses/.env.inputverifier')); const proxyInputVerifier = parsedEnvInputVerifier.INPUT_VERIFIER_CONTRACT_ADDRESS; const implementationInputVerifierAddress = await upgrades.erc1967.getImplementationAddress(proxyInputVerifier); await run('verify:verify', { @@ -63,9 +59,7 @@ task('task:verifyInputVerifier').setAction(async function (taskArguments, { upgr }); task('task:verifyFHEPayment').setAction(async function (taskArguments, { upgrades, run }) { - const parsedEnvFHEPayment = dotenv.parse( - fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.fhepayment'), - ); + const parsedEnvFHEPayment = dotenv.parse(fs.readFileSync('addresses/.env.fhepayment')); const proxyFHEPayment = parsedEnvFHEPayment.FHE_PAYMENT_CONTRACT_ADDRESS; const implementationFHEPaymentAddress = await upgrades.erc1967.getImplementationAddress(proxyFHEPayment); await run('verify:verify', { diff --git a/contracts/tasks/taskDeploy.ts b/contracts/tasks/taskDeploy.ts index 2bc3ebb7..bf586126 100644 --- a/contracts/tasks/taskDeploy.ts +++ b/contracts/tasks/taskDeploy.ts @@ -30,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('fhevmTemp/contracts/ACL.sol:ACL', deployer); + const factory = await ethers.getContractFactory('./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('node_modules/fhevm-core-contracts/addresses/.env.acl')); + const envConfigAcl = dotenv.parse(fs.readFileSync('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`, @@ -49,14 +49,17 @@ 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('fhevmTemp/contracts/TFHEExecutor.sol:TFHEExecutor', deployer); + factory = await ethers.getContractFactory('./contracts/TFHEExecutor.sol:TFHEExecutor', deployer); } else { - factory = await ethers.getContractFactory('contracts/TFHEExecutorWithEvents.sol:TFHEExecutorWithEvents', deployer); + factory = await ethers.getContractFactory( + './contracts/TFHEExecutorWithEvents.sol:TFHEExecutorWithEvents', + 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('node_modules/fhevm-core-contracts/addresses/.env.exec')); + const envConfig = dotenv.parse(fs.readFileSync('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`, @@ -69,11 +72,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('fhevmTemp/contracts/KMSVerifier.sol:KMSVerifier', deployer); + const factory = await ethers.getContractFactory('./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('node_modules/fhevm-core-contracts/addresses/.env.kmsverifier')); + const envConfig = dotenv.parse(fs.readFileSync('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`, @@ -88,17 +91,14 @@ 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( - 'fhevmTemp/contracts/InputVerifier.coprocessor.sol:InputVerifier', - deployer, - ); + factory = await ethers.getContractFactory('./contracts/InputVerifier.coprocessor.sol:InputVerifier', deployer); } else { - factory = await ethers.getContractFactory('fhevmTemp/contracts/InputVerifier.native.sol:InputVerifier', deployer); + factory = await ethers.getContractFactory('./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('node_modules/fhevm-core-contracts/addresses/.env.inputverifier')); + const envConfig = dotenv.parse(fs.readFileSync('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`, @@ -111,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('fhevmTemp/contracts/FHEPayment.sol:FHEPayment', deployer); + const factory = await ethers.getContractFactory('./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('node_modules/fhevm-core-contracts/addresses/.env.fhepayment')); + const envConfig = dotenv.parse(fs.readFileSync('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`, @@ -142,14 +142,12 @@ task('task:addSigners') ) .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); + const factory = await ethers.getContractFactory('./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; + kmsAdd = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier')).KMS_VERIFIER_CONTRACT_ADDRESS; } const kmsVerifier = await factory.attach(kmsAdd); for (let idx = 0; idx < taskArguments.numSigners; idx++) { @@ -174,14 +172,12 @@ task('task:getAllSigners') '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'); + const factory = await ethers.getContractFactory('./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; + kmsAdd = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier')).KMS_VERIFIER_CONTRACT_ADDRESS; } const kmsVerifier = (await factory.attach(kmsAdd).connect(ethers.provider)) as KMSVerifier; const listCurrentKMSSigners = await kmsVerifier.getSigners(); @@ -197,14 +193,12 @@ task('task:removeSigner') ) .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); + const factory = await ethers.getContractFactory('./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; + kmsAdd = dotenv.parse(fs.readFileSync('addresses/.env.kmsverifier')).KMS_VERIFIER_CONTRACT_ADDRESS; } const kmsVerifier = (await factory.attach(kmsAdd)) as KMSVerifier; const tx = await kmsVerifier.removeSigner(taskArguments.kmsSignerAddress); diff --git a/contracts/tasks/taskTFHE.ts b/contracts/tasks/taskTFHE.ts index d27d5e26..88dd2427 100644 --- a/contracts/tasks/taskTFHE.ts +++ b/contracts/tasks/taskTFHE.ts @@ -11,7 +11,7 @@ task('task:computeACLAddress') from: deployer, nonce: 1, // using nonce of 1 for the ACL contract (0 for original implementation, +1 for proxy) }); - const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.acl'); + const envFilePath = path.join(__dirname, '../addresses/.env.acl'); const content = `ACL_CONTRACT_ADDRESS=${aclAddress}\n`; try { fs.writeFileSync(envFilePath, content, { flag: 'w' }); @@ -27,13 +27,13 @@ pragma solidity ^0.8.24; address constant aclAdd = ${aclAddress};\n`; try { - fs.writeFileSync('./node_modules/fhevm-core-contracts/addresses/ACLAddress.sol', solidityTemplate, { + fs.writeFileSync('./addresses/ACLAddress.sol', solidityTemplate, { encoding: 'utf8', flag: 'w', }); - console.log('./node_modules/fhevm-core-contracts/addresses/ACLAddress.sol file generated successfully!'); + console.log('./addresses/ACLAddress.sol file generated successfully!'); } catch (error) { - console.error('Failed to write ./node_modules/fhevm-core-contracts/addresses/ACLAddress.sol', error); + console.error('Failed to write ./addresses/ACLAddress.sol', error); } }); @@ -45,7 +45,7 @@ task('task:computeTFHEExecutorAddress') from: deployer, nonce: 3, // using nonce of 3 for the TFHEExecutor contract (2 for original implementation, +1 for proxy) }); - const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.exec'); + const envFilePath = path.join(__dirname, '../addresses/.env.exec'); const content = `TFHE_EXECUTOR_CONTRACT_ADDRESS=${execAddress}\n`; try { fs.writeFileSync(envFilePath, content, { flag: 'w' }); @@ -61,14 +61,13 @@ pragma solidity ^0.8.24; address constant tfheExecutorAdd = ${execAddress};\n`; try { - fs.writeFileSync( - './node_modules/fhevm-core-contracts/addresses/TFHEExecutorAddress.sol', - solidityTemplateCoprocessor, - { encoding: 'utf8', flag: 'w' }, - ); - console.log('./node_modules/fhevm-core-contracts/addresses/TFHEExecutorAddress.sol file generated successfully!'); + fs.writeFileSync('./addresses/TFHEExecutorAddress.sol', solidityTemplateCoprocessor, { + encoding: 'utf8', + flag: 'w', + }); + console.log('./addresses/TFHEExecutorAddress.sol file generated successfully!'); } catch (error) { - console.error('Failed to write ./node_modules/fhevm-core-contracts/addresses/TFHEExecutorAddress.sol', error); + console.error('Failed to write ./addresses/TFHEExecutorAddress.sol', error); } }); @@ -80,7 +79,7 @@ task('task:computeKMSVerifierAddress') from: deployer, nonce: 5, // using nonce of 5 for the KMSVerifier contract (4 for original implementation, +1 for proxy) }); - const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.kmsverifier'); + const envFilePath = path.join(__dirname, '../addresses/.env.kmsverifier'); const content = `KMS_VERIFIER_CONTRACT_ADDRESS=${kmsVerfierAddress}\n`; try { fs.writeFileSync(envFilePath, content, { flag: 'w' }); @@ -96,13 +95,13 @@ pragma solidity ^0.8.24; address constant kmsVerifierAdd = ${kmsVerfierAddress};\n`; try { - fs.writeFileSync('./node_modules/fhevm-core-contracts/addresses/KMSVerifierAddress.sol', solidityTemplate, { + fs.writeFileSync('./addresses/KMSVerifierAddress.sol', solidityTemplate, { encoding: 'utf8', flag: 'w', }); - console.log('./node_modules/fhevm-core-contracts/addresses/KMSVerifierAddress.sol file generated successfully!'); + console.log('./addresses/KMSVerifierAddress.sol file generated successfully!'); } catch (error) { - console.error('Failed to write ./node_modules/fhevm-core-contracts/addresses/KMSVerifierAddress.sol', error); + console.error('Failed to write ./addresses/KMSVerifierAddress.sol', error); } }); @@ -121,7 +120,7 @@ task('task:computeInputVerifierAddress') from: deployer, nonce: 7, // using nonce of 7 for the InputVerifier contract (6 for original implementation, +1 for proxy) }); - const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.inputverifier'); + const envFilePath = path.join(__dirname, '../addresses/.env.inputverifier'); const content = `INPUT_VERIFIER_CONTRACT_ADDRESS=${inputVerfierAddress}\n`; try { fs.writeFileSync(envFilePath, content, { flag: 'w' }); @@ -137,15 +136,13 @@ pragma solidity ^0.8.24; address constant inputVerifierAdd = ${inputVerfierAddress};\n`; try { - fs.writeFileSync('./node_modules/fhevm-core-contracts/addresses/InputVerifierAddress.sol', solidityTemplate, { + fs.writeFileSync('./addresses/InputVerifierAddress.sol', solidityTemplate, { encoding: 'utf8', flag: 'w', }); - console.log( - './node_modules/fhevm-core-contracts/addresses/InputVerifierAddress.sol file generated successfully!', - ); + console.log('./addresses/InputVerifierAddress.sol file generated successfully!'); } catch (error) { - console.error('Failed to write ./node_modules/fhevm-core-contracts/addresses/InputVerifierAddress.sol', error); + console.error('Failed to write ./addresses/InputVerifierAddress.sol', error); } let coprocAddress; if (!taskArguments.useAddress) { @@ -153,7 +150,7 @@ address constant inputVerifierAdd = ${inputVerfierAddress};\n`; } else { coprocAddress = process.env.ADDRESS_COPROCESSOR_ACCOUNT; } - const envFilePath2 = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.coprocessor'); + const envFilePath2 = path.join(__dirname, '../addresses/.env.coprocessor'); const content2 = `COPROCESSOR_ADDRESS=${coprocAddress}\n`; try { fs.writeFileSync(envFilePath2, content2, { flag: 'w' }); @@ -169,13 +166,13 @@ pragma solidity ^0.8.24; address constant coprocessorAdd = ${coprocAddress};\n`; try { - fs.writeFileSync('./node_modules/fhevm-core-contracts/addresses/CoprocessorAddress.sol', solidityTemplate2, { + fs.writeFileSync('./addresses/CoprocessorAddress.sol', solidityTemplate2, { encoding: 'utf8', flag: 'w', }); - console.log('./node_modules/fhevm-core-contracts/addresses/CoprocessorAddress.sol file generated successfully!'); + console.log('./addresses/CoprocessorAddress.sol file generated successfully!'); } catch (error) { - console.error('Failed to write ./node_modules/fhevm-core-contracts/addresses/CoprocessorAddress.sol', error); + console.error('Failed to write ./addresses/CoprocessorAddress.sol', error); } }); @@ -187,7 +184,7 @@ task('task:computeFHEPaymentAddress') from: deployer, nonce: 9, // using nonce of 9 for the FHEPayment contract (8 for original implementation, +1 for proxy) }); - const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.fhepayment'); + const envFilePath = path.join(__dirname, '../addresses/.env.fhepayment'); const content = `FHE_PAYMENT_CONTRACT_ADDRESS=${fhePaymentAddress}\n`; try { fs.writeFileSync(envFilePath, content, { flag: 'w' }); @@ -203,12 +200,12 @@ pragma solidity ^0.8.24; address constant fhePaymentAdd = ${fhePaymentAddress};\n`; try { - fs.writeFileSync('./node_modules/fhevm-core-contracts/addresses/FHEPaymentAddress.sol', solidityTemplate, { + fs.writeFileSync('./addresses/FHEPaymentAddress.sol', solidityTemplate, { encoding: 'utf8', flag: 'w', }); - console.log('./node_modules/fhevm-core-contracts/addresses/FHEPaymentAddress.sol file generated successfully!'); + console.log('./addresses/FHEPaymentAddress.sol file generated successfully!'); } catch (error) { - console.error('Failed to write ./node_modules/fhevm-core-contracts/addresses/FHEPaymentAddress.sol', error); + console.error('Failed to write ./addresses/FHEPaymentAddress.sol', error); } });