Skip to content

Commit

Permalink
Merge pull request #150 from zama-ai/migrationFhevm2FhevmBackend
Browse files Browse the repository at this point in the history
Migration of fhevm repo to fhevm-backend
  • Loading branch information
jatZama authored Nov 29, 2024
2 parents 511029f + e29c0f6 commit 1f9fb88
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 142 deletions.
3 changes: 1 addition & 2 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
2 changes: 1 addition & 1 deletion contracts/addresses/.env.acl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2
ACL_CONTRACT_ADDRESS=0x27FFa4b57D619aDF9821A82AD01b434DE25BCC71
2 changes: 1 addition & 1 deletion contracts/addresses/.env.exec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TFHE_EXECUTOR_CONTRACT_ADDRESS=0x596E6682c72946AF006B27C131793F2b62527A4b
TFHE_EXECUTOR_CONTRACT_ADDRESS=0x556C1C45316Db2372f9b1b6b288D095709574705
2 changes: 1 addition & 1 deletion contracts/addresses/.env.fhepayment
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FHE_PAYMENT_CONTRACT_ADDRESS=0x6d5A11aC509C707c00bc3A0a113ACcC26c532547
FHE_PAYMENT_CONTRACT_ADDRESS=0x2262E4d00777b46846aA7E502Ec43DD592F932e9
2 changes: 1 addition & 1 deletion contracts/addresses/.env.inputverifier
Original file line number Diff line number Diff line change
@@ -1 +1 @@
INPUT_VERIFIER_CONTRACT_ADDRESS=0x69dE3158643e738a0724418b21a35FAA20CBb1c5
INPUT_VERIFIER_CONTRACT_ADDRESS=0xa50829aC46Ed11158D969334def5e362E5e54Dca
2 changes: 1 addition & 1 deletion contracts/addresses/.env.kmsverifier
Original file line number Diff line number Diff line change
@@ -1 +1 @@
KMS_VERIFIER_CONTRACT_ADDRESS=0x208De73316E44722e16f6dDFF40881A3e4F86104
KMS_VERIFIER_CONTRACT_ADDRESS=0x3DBB223F4b5b5Ce62d3c959Cbea57584F314a713
2 changes: 1 addition & 1 deletion contracts/addresses/ACLAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pragma solidity ^0.8.24;

address constant aclAdd = 0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2;
address constant aclAdd = 0x27FFa4b57D619aDF9821A82AD01b434DE25BCC71;
2 changes: 1 addition & 1 deletion contracts/addresses/FHEPaymentAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pragma solidity ^0.8.24;

address constant fhePaymentAdd = 0x6d5A11aC509C707c00bc3A0a113ACcC26c532547;
address constant fhePaymentAdd = 0x2262E4d00777b46846aA7E502Ec43DD592F932e9;
2 changes: 1 addition & 1 deletion contracts/addresses/InputVerifierAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pragma solidity ^0.8.24;

address constant inputVerifierAdd = 0x69dE3158643e738a0724418b21a35FAA20CBb1c5;
address constant inputVerifierAdd = 0xa50829aC46Ed11158D969334def5e362E5e54Dca;
2 changes: 1 addition & 1 deletion contracts/addresses/KMSVerifierAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pragma solidity ^0.8.24;

address constant kmsVerifierAdd = 0x208De73316E44722e16f6dDFF40881A3e4F86104;
address constant kmsVerifierAdd = 0x3DBB223F4b5b5Ce62d3c959Cbea57584F314a713;
2 changes: 1 addition & 1 deletion contracts/addresses/TFHEExecutorAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pragma solidity ^0.8.24;

address constant tfheExecutorAdd = 0x596E6682c72946AF006B27C131793F2b62527A4b;
address constant tfheExecutorAdd = 0x556C1C45316Db2372f9b1b6b288D095709574705;
1 change: 0 additions & 1 deletion contracts/contracts/InputVerifier.native.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 0 additions & 2 deletions contracts/contracts/TFHEExecutorWithEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
2 changes: 1 addition & 1 deletion contracts/gateway/.env.gateway
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=0x096b4679d45fB675d4e2c1E4565009Cec99A12B1
GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=0xF2251f93B168a1f49329976efF8615bDB8e24d80
1 change: 0 additions & 1 deletion contracts/gateway/GatewayContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion contracts/gateway/lib/GatewayContractAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

pragma solidity ^0.8.24;

address constant GATEWAY_CONTRACT_PREDEPLOY_ADDRESS = 0x096b4679d45fB675d4e2c1E4565009Cec99A12B1;
address constant GATEWAY_CONTRACT_PREDEPLOY_ADDRESS = 0xF2251f93B168a1f49329976efF8615bDB8e24d80;
93 changes: 37 additions & 56 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
},
Expand All @@ -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: {
Expand Down
28 changes: 28 additions & 0 deletions contracts/launch-fhevm-sepolia.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 5 additions & 11 deletions contracts/tasks/etherscanVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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', {
Expand All @@ -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', {
Expand All @@ -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', {
Expand All @@ -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', {
Expand Down
Loading

0 comments on commit 1f9fb88

Please sign in to comment.