Skip to content

Commit

Permalink
Merge pull request #552 from zama-ai/deploymentTasks
Browse files Browse the repository at this point in the history
feat: use fhevm deployer private key for deployment
  • Loading branch information
jatZama authored Oct 4, 2024
2 parents ab6fb5a + 0943a08 commit 3823ba1
Show file tree
Hide file tree
Showing 31 changed files with 362 additions and 555 deletions.
13 changes: 9 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
export INFURA_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
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_OWNER="717fd99986df414889fd8b51069d4f90a50af72e542c58ee065f5883779099c6"
export PRIVATE_KEY_GATEWAY_RELAYER="7ec931411ad75a7c201469a385d6f18a325d4923f9f213bd882bbea87e160b67"
export NUM_KMS_SIGNERS="1"
export PRIVATE_KEY_KMS_SIGNER_0="26698d458a21b843aa1ddbd5c5b098821ddf4218bb52498c4aad3a84849275bb"
export PRIVATE_KEY_KMS_SIGNER_1="e5b998ce1e664718772fa35e8d02b2b6a267a03a8ecadab15de5b125da7fa82b"
export PRIVATE_KEY_KMS_SIGNER_2="dca817bfe824b12c92d61e56056b956617da156bcd730379cb9203c822c9ba8e"
export PRIVATE_KEY_KMS_SIGNER_3="7ac1a2886ca07b3b7393ea5ff3613bb94d72129e2c7cbedc807eb55ff971394c"
export PRIVATE_KEY_KMS_SIGNER_0="388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91"
export PRIVATE_KEY_KMS_SIGNER_1="bbaed91514fa4b7c86aa4f73becbabcf4bce0ae130240f0d6ac3f87e06812440"
export PRIVATE_KEY_KMS_SIGNER_2="1bfa3e2233b0103ad67954a728b246c528916791f7fab4894ff361e3937b47e1"
export PRIVATE_KEY_KMS_SIGNER_3="7a604eed8cf4a43277d192aa0c7894d368577a4021e52bf45420f256e34c7dd7"
export ADDRESS_KMS_SIGNER_0="0x0971C80fF03B428fD2094dd5354600ab103201C5"
export ADDRESS_KMS_SIGNER_1="0xB68deCb047B5e6Cc82280502A7E2318c6b3E5eC6"
export ADDRESS_KMS_SIGNER_2="0xfe0fB0BCceb872ee7a6ef6c455e6E127Aef55DD7"
export ADDRESS_KMS_SIGNER_3="0x2dac5193bE0AB0eD8871399E6Ae61EAe6cc8cAE1"
export PRIVATE_KEY_COPROCESSOR_ACCOUNT="7ec8ada6642fc4ccfb7729bc29c17cf8d21b61abd5642d1db992c0b8672ab901"
export IS_COPROCESSOR="true"

Expand Down
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,6 @@ npm run fhevm:start
npm run fhevm:stop
```

##### Faucet

For development purposes, we provide a ready to use wallet. In order to use
it, prepare the .env file that contains the mnemonic.

```bash
cp .env.example .env
```

This allows the developer to use a few accounts, each account can get coins:

```bash
npm run fhevm:faucet:alice
npm run fhevm:faucet:bob
npm run fhevm:faucet:carol
```

##### Run test

```bash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.24;

import "../../lib/TFHE.sol";
import "../../../lib/TFHE.sol";

contract Comp {
/// @notice EIP-20 token name for this token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.24;

import "../../lib/TFHE.sol";
import "../../../lib/TFHE.sol";

contract GovernorZama {
/// @notice The name of this contract
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.24;

import "../../lib/TFHE.sol";
import "../EncryptedERC20.sol";
import "../../../lib/TFHE.sol";
import "../../EncryptedERC20.sol";
import "./ERC20Rules.sol";
import "./IdentityRegistry.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.24;

import "../../lib/TFHE.sol";
import "../../../lib/TFHE.sol";
import "./IdentityRegistry.sol";

interface ICompliantERC20 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

import "../../lib/TFHE.sol";
import "../../../lib/TFHE.sol";

contract IdentityRegistry is Ownable2Step {
uint constant MAX_IDENTIFIERS_LENGTH = 20;
Expand Down
33 changes: 19 additions & 14 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import './tasks/getEthereumAddress';
import './tasks/mint';
import './tasks/taskDeploy';
import './tasks/taskGatewayRelayer';
import './tasks/taskIdentity';
import './tasks/taskTFHE';

extendProvider(async (provider, config, network) => {
Expand Down Expand Up @@ -87,13 +86,14 @@ task('test', async (taskArgs, hre, runSuper) => {
// Run modified test task
if (hre.network.name === 'hardhat') {
// in fhevm mode all this block is done when launching the node via `pnmp fhevm:start`
const privKeyDeployer = process.env.PRIVATE_KEY_GATEWAY_DEPLOYER;
await hre.run('task:computePredeployAddress', { privateKey: privKeyDeployer });
await hre.run('task:computeACLAddress');
await hre.run('task:computeTFHEExecutorAddress');
await hre.run('task:computeKMSVerifierAddress');
await hre.run('task:computeInputVerifierAddress');
await hre.run('task:computeFHEPaymentAddress');
const privKeyGatewayDeployer = process.env.PRIVATE_KEY_GATEWAY_DEPLOYER;
const privKeyFhevmDeployer = process.env.PRIVATE_KEY_FHEVM_DEPLOYER;
await hre.run('task:computeGatewayAddress', { privateKey: privKeyGatewayDeployer });
await hre.run('task:computeACLAddress', { privateKey: privKeyFhevmDeployer });
await hre.run('task:computeTFHEExecutorAddress', { privateKey: privKeyFhevmDeployer });
await hre.run('task:computeKMSVerifierAddress', { privateKey: privKeyFhevmDeployer });
await hre.run('task:computeInputVerifierAddress', { privateKey: privKeyFhevmDeployer });
await hre.run('task:computeFHEPaymentAddress', { privateKey: privKeyFhevmDeployer });
if (process.env.IS_COPROCESSOR === 'true') {
await fs.copyFile('lib/InputVerifier.sol.coprocessor', 'lib/InputVerifier.sol');
} else {
Expand All @@ -102,12 +102,17 @@ task('test', async (taskArgs, hre, runSuper) => {
await hre.run('compile:specific', { contract: 'lib' });
await hre.run('compile:specific', { contract: 'gateway' });
await hre.run('compile:specific', { contract: 'payment' });
await hre.run('task:deployACL');
await hre.run('task:deployTFHEExecutor');
await hre.run('task:deployKMSVerifier');
await hre.run('task:deployInputVerifier');
await hre.run('task:deployFHEPayment');
await hre.run('task:addSigners', { numSigners: +process.env.NUM_KMS_SIGNERS! });
await hre.run('task:faucetToPrivate', { privateKey: privKeyFhevmDeployer });
await hre.run('task:deployACL', { privateKey: privKeyFhevmDeployer });
await hre.run('task:deployTFHEExecutor', { privateKey: privKeyFhevmDeployer });
await hre.run('task:deployKMSVerifier', { privateKey: privKeyFhevmDeployer });
await hre.run('task:deployInputVerifier', { privateKey: privKeyFhevmDeployer });
await hre.run('task:deployFHEPayment', { privateKey: privKeyFhevmDeployer });
await hre.run('task:addSigners', {
numSigners: +process.env.NUM_KMS_SIGNERS!,
privateKey: privKeyFhevmDeployer,
useAddress: false,
});
await hre.run('task:launchFhevm', { skipGetCoin: false });
}
await hre.run('compile:specific', { contract: 'examples' });
Expand Down
53 changes: 27 additions & 26 deletions launch-fhevm.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
#!/bin/bash
npx hardhat clean

PRIVATE_KEY_GATEWAY_DEPLOYER=$(grep PRIVATE_KEY_GATEWAY_DEPLOYER .env | cut -d '"' -f 2)

npx hardhat task:computePredeployAddress --private-key "$PRIVATE_KEY_GATEWAY_DEPLOYER"

PRIVATE_KEY_GATEWAY_RELAYER=$(grep PRIVATE_KEY_GATEWAY_RELAYER .env | cut -d '"' -f 2)

GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=$(grep GATEWAY_CONTRACT_PREDEPLOY_ADDRESS gateway/.env.gateway | cut -d '=' -f2)

TFHE_EXECUTOR_CONTRACT_ADDRESS=$(grep TFHE_EXECUTOR_CONTRACT_ADDRESS lib/.env.exec | cut -d '=' -f2)

docker run -d -i -p 8545:8545 --rm --name fhevm \
-e PRIVATE_KEY_ORACLE_RELAYER="$PRIVATE_KEY_ORACLE_RELAYER" \
-e ORACLE_CONTRACT_PREDEPLOY_ADDRESS="$ORACLE_CONTRACT_PREDEPLOY_ADDRESS" \
-e TFHE_EXECUTOR_CONTRACT_ADDRESS="$TFHE_EXECUTOR_CONTRACT_ADDRESS" \
ghcr.io/zama-ai/ethermint-dev-node:v0.5.0-1

sleep 10

npx hardhat task:computeACLAddress
npx hardhat task:computeTFHEExecutorAddress
npx hardhat task:computeKMSVerifierAddress
npx hardhat task:deployACL
npx hardhat task:deployTFHEExecutor
npx hardhat task:deployKMSVerifier

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)
IS_COPROCESSOR=$(grep IS_COPROCESSOR .env | cut -d '"' -f 2)

npx hardhat task:computeGatewayAddress --private-key "$PRIVATE_KEY_GATEWAY_DEPLOYER"
npx hardhat task:computeACLAddress --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:computeTFHEExecutorAddress --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:computeKMSVerifierAddress --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:computeInputVerifierAddress --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:computeFHEPaymentAddress --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"

# [ADD DOCKER-COMPOSE COMMAND HERE] // Geth node, Gateway service, KMS service etc should be launched here, using previously precomputed addresses

if [ "$IS_COPROCESSOR" = "true" ]; then
cp lib/InputVerifier.sol.coprocessor lib/InputVerifier.sol
else
cp lib/InputVerifier.sol.native lib/InputVerifier.sol
fi
npx hardhat compile:specific --contract lib
npx hardhat compile:specific --contract gateway

npx hardhat task:launchFhevm
npx hardhat task:deployACL --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:deployTFHEExecutor --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:deployKMSVerifier --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:deployInputVerifier --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"
npx hardhat task:deployFHEPayment --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER"

npx hardhat task:addSigners --num-signers $NUM_KMS_SIGNERS --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --useAddress true

docker attach fhevm
npx hardhat task:launchFhevm --skip-get-coin true
2 changes: 1 addition & 1 deletion lib/.env.acl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ACL_CONTRACT_ADDRESS=0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c
ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2
2 changes: 1 addition & 1 deletion lib/.env.exec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TFHE_EXECUTOR_CONTRACT_ADDRESS=0xcCAe95fF1d11656358E782570dF0418F59fA40e1
TFHE_EXECUTOR_CONTRACT_ADDRESS=0x596E6682c72946AF006B27C131793F2b62527A4b
2 changes: 1 addition & 1 deletion lib/.env.fhepayment
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FHE_PAYMENT_CONTRACT_ADDRESS=0x222ea0147FF597Ff1935B2a55afeDC404425203d
FHE_PAYMENT_CONTRACT_ADDRESS=0x6d5A11aC509C707c00bc3A0a113ACcC26c532547
2 changes: 1 addition & 1 deletion lib/.env.inputverifier
Original file line number Diff line number Diff line change
@@ -1 +1 @@
INPUT_VERIFIER_CONTRACT_ADDRESS=0x52054F36036811ca418be59e41Fc6DD1b9e4F4c8
INPUT_VERIFIER_CONTRACT_ADDRESS=0x69dE3158643e738a0724418b21a35FAA20CBb1c5
2 changes: 1 addition & 1 deletion lib/.env.kmsverifier
Original file line number Diff line number Diff line change
@@ -1 +1 @@
KMS_VERIFIER_CONTRACT_ADDRESS=0x857Ca72A957920Fa0FB138602995839866Bd4005
KMS_VERIFIER_CONTRACT_ADDRESS=0x208De73316E44722e16f6dDFF40881A3e4F86104
2 changes: 1 addition & 1 deletion lib/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 = 0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c;
address constant aclAdd = 0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2;
2 changes: 1 addition & 1 deletion lib/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 = 0x222ea0147FF597Ff1935B2a55afeDC404425203d;
address constant fhePaymentAdd = 0x6d5A11aC509C707c00bc3A0a113ACcC26c532547;
2 changes: 1 addition & 1 deletion lib/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 = 0x52054F36036811ca418be59e41Fc6DD1b9e4F4c8;
address constant inputVerifierAdd = 0x69dE3158643e738a0724418b21a35FAA20CBb1c5;
2 changes: 1 addition & 1 deletion lib/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 = 0x857Ca72A957920Fa0FB138602995839866Bd4005;
address constant kmsVerifierAdd = 0x208De73316E44722e16f6dDFF40881A3e4F86104;
2 changes: 1 addition & 1 deletion lib/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 = 0xcCAe95fF1d11656358E782570dF0418F59fA40e1;
address constant tfheExecutorAdd = 0x596E6682c72946AF006B27C131793F2b62527A4b;
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@
"codegen": "npx ts-node codegen/main.ts && npm run prettier",
"codegen:overloads": "npx ts-node codegen/generateOverloads.ts",
"task:getEthereumAddress": "hardhat task:getEthereumAddress",
"task:deployIdentity": "hardhat task:deployIdentity",
"task:deployGateway": "hardhat task:deployGateway",
"task:addRelayer": "hardhat task:addRelayer",
"task:removeRelayer": "hardhat task:removeRelayer",
"fhevm:start": " ./launch-fhevm.sh",
"fhevm:stop": "docker rm -f fhevm",
"fhevm:restart": "fhevm:stop && fhevm:start",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave && sleep 5 && npm run fhevm:faucet:eve",
"fhevm:faucet:alice": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressAlice)",
"fhevm:faucet:bob": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressBob)",
"fhevm:faucet:carol": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressCarol)",
"fhevm:faucet:dave": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressDave)",
"fhevm:faucet:eve": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressEve)"
"fhevm:restart": "fhevm:stop && fhevm:start"
},
"repository": {
"type": "git",
Expand Down
20 changes: 0 additions & 20 deletions setup-local-fhevm.sh

This file was deleted.

8 changes: 8 additions & 0 deletions tasks/mint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { task } from 'hardhat/config';
import type { TaskArguments } from 'hardhat/types';

task('task:deployERC20').setAction(async function (taskArguments: TaskArguments, { ethers }) {
const signers = await ethers.getSigners();
const erc20Factory = await ethers.getContractFactory('EncryptedERC20');
const encryptedERC20 = await erc20Factory.connect(signers[0]).deploy('Naraggara', 'NARA');
await encryptedERC20.waitForDeployment();
console.log('EncryptedERC20 deployed to: ', await encryptedERC20.getAddress());
});

task('task:mint')
.addParam('mint', 'Tokens to mint')
.setAction(async function (taskArguments: TaskArguments, hre) {
Expand Down
Loading

0 comments on commit 3823ba1

Please sign in to comment.