Skip to content

Commit

Permalink
chore: add deployment files for coprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
0xawaz committed Feb 18, 2025
1 parent fd690ba commit fffcc81
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const chainIds = {
devnetNative: 9000,
localCoprocessor: 12345,
sepolia: 11155111,
staging: 12345,
mainnet: 1,
};

Expand All @@ -91,6 +92,9 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
case 'sepolia':
jsonRpcUrl = process.env.SEPOLIA_RPC_URL!;
break;
case 'staging':
jsonRpcUrl = process.env.STAGING_RPC_URL!;
break;
case 'localCoprocessor':
jsonRpcUrl = 'http://localhost:8745';
break;
Expand All @@ -102,7 +106,7 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
}
return {
accounts: {
count: 10,
count: 15,
mnemonic,
path: "m/44'/60'/0'/0",
},
Expand Down Expand Up @@ -133,6 +137,7 @@ const config: HardhatUserConfig = {
path: "m/44'/60'/0'/0",
},
},
staging: getChainConfig('staging'),
sepolia: getChainConfig('sepolia'),
localNative: getChainConfig('localNative'),
localCoprocessor: getChainConfig('localCoprocessor'),
Expand Down
31 changes: 31 additions & 0 deletions contracts/launch-fhevm-staging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
npx hardhat clean
npx hardhat compile:specific --contract contracts/emptyProxy

mkdir -p addresses

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 task:deployEmptyUUPSProxies --use-coprocessor-address true --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging

npx hardhat compile
npx hardhat compile:specific --contract decryptionOracle

npx hardhat task:deployACL --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging
npx hardhat task:deployTFHEExecutor --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging
npx hardhat task:deployKMSVerifier --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging
npx hardhat task:deployInputVerifier --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging
npx hardhat task:deployFHEGasLimit --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging
npx hardhat task:deployDecryptionOracle --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --network staging

npx hardhat task:addSigners --num-signers "$NUM_KMS_SIGNERS" --private-key "$PRIVATE_KEY_FHEVM_DEPLOYER" --use-address true --network staging

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 staging
npx hardhat task:verifyTFHEExecutor --network staging
npx hardhat task:verifyKMSVerifier --network staging
npx hardhat task:verifyInputVerifier --network staging
npx hardhat task:verifyFHEGasLimit --network staging
npx hardhat task:verifyDecryptionOracle --network staging
2 changes: 2 additions & 0 deletions deployments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
layer1-data
layer2-data
4 changes: 4 additions & 0 deletions deployments/config/.env.staging.coprocessor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export DATABASE_URL=postgresql://postgres:postgres@db:5432/coprocessor
export TENANT_API_KEY="a1503fb6-d79b-4e9e-826d-44cf262f3e05"
export ACL_CONTRACT_ADDRESS="0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c"
export INPUT_VERIFIER_ADDRESS="0xa1880e99d86F081E8D3868A8C4732C8f65dfdB11"
17 changes: 17 additions & 0 deletions deployments/config/.env.staging.layer1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export MNEMONIC="adapt mosquito move limb mobile illegal tree voyage juice mosquito burger raise father hope layer"
export PRIVATE_KEY_FHEVM_DEPLOYER="2d24c36c57e6bfbf90c43173481cc00edcbd1a3922de5e5fdb9aba5fc4e0fafd" # accounts[9]
export PRIVATE_KEY_DECRYPTION_ORACLE_RELAYER="527bd7b9f1150dc8a0936e8b5a3ba6a62bbdfd7ef0bcecbbf4d140f6c5cb5d85" # accounts[10]
export NUM_KMS_SIGNERS="1"
export PRIVATE_KEY_KMS_SIGNER_0="30d45b1c5a771e20d0ec15097c3b6ac7153bc1992bc78c42af37725dd93f096a" # accounts[11]
export ADDRESS_KMS_SIGNER_0="0x6518D50aDc9036Df37119eA465a8159E34417E2E"
export PRIVATE_KEY_KMS_SIGNER_1="52d5c715e2b9e05f7ddaf4d390adc7b5c31829d0a015d7d0eb35e4679a4a30a3" # accounts[12]
export ADDRESS_KMS_SIGNER_1="0xa5eE8292dA52d8234248709F3E217ffEBA5E8312"
export PRIVATE_KEY_KMS_SIGNER_2="8f26a6ed27d0d6239f6b984dceeb3480f8c224a398de4c84826ba180c809c45a" # accounts[13]
export ADDRESS_KMS_SIGNER_2="0xCFbF539CB91c92ace0343c5B0487149Ad0b82078"
export PRIVATE_KEY_KMS_SIGNER_3="30d2f81c5a1d20660d2941490d733116e2628f0067085f267c76d3597f468f45" # accounts[14]
export ADDRESS_KMS_SIGNER_3="0xA951F315d5FD35Cac111dFB5250DF231FB8eF905"
export PRIVATE_KEY_COPROCESSOR_ACCOUNT="5e114f8857db80ce527af9f3b215d61f32882efc5d30c6d9c7de7a17cef560cd" # accounts[8]
export ADDRESS_COPROCESSOR_ACCOUNT="0x466f26442DD182C9A1b018Cd06671F9791DdE8Ef" # accounts[8]
export IS_COPROCESSOR="true"
export SEPOLIA_RPC_URL="https://sepolia.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export STAGING_RPC_URL="http://layer1-node:8545"
13 changes: 13 additions & 0 deletions deployments/config/.env.staging.layer2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Default mnemonic for local gateway L2 (same as fhevm)
export MNEMONIC="coyote sketch defense hover finger envelope celery urge panther venue verb cheese"

# Get local addresses and public keys by running `make get-accounts`
# Deployer
export DEPLOYER_ADDRESS="0xCf28E90D4A6dB23c34E1881aEF5fd9fF2e478634" # accounts[1]
export DEPLOYER_PRIVATE_KEY="0xe746bc71f6bee141a954e6a49bc9384d334e393a7ea1e70b50241cb2e78e9e4c" # accounts[1]

export RPC_URL="http://layer2-node:8546"

# Contracts addresses
export HTTPZ_ADDRESS=0xc1D733116990ce3D9e54F9eCf48a1cdD441Af4f9
export ZKPOK_MANAGER_ADDRESS=0xa50F5243C70c80a8309e3D39d8c9d958cDa83979
1 change: 1 addition & 0 deletions deployments/config/coprocessor.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x7ec8ada6642fc4ccfb7729bc29c17cf8d21b61abd5642d1db992c0b8672ab901
111 changes: 111 additions & 0 deletions deployments/coprocessor-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: fhevm
services:
####################### DATABASE SETUP #######################
db:
container_name: db
image: postgres:15.7
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 3
volumes:
- db:/var/lib/postgresql/data

migration:
container_name: db-migration
build:
context: ../.
dockerfile: fhevm-engine/fhevm-db/Dockerfile
tags:
- "fhevm-db-migration:v0.7.0-local"
image: ghcr.io/zama-ai/fhevm-db-migration:v0.7.0-rc0
environment:
DATABASE_URL: ${DATABASE_URL}
TENANT_API_KEY: ${TENANT_API_KEY}
ACL_CONTRACT_ADDRESS: ${ACL_CONTRACT_ADDRESS}
INPUT_VERIFIER_ADDRESS: ${INPUT_VERIFIER_ADDRESS}
volumes:
- ../fhevm-engine/fhevm-keys:/fhevm-keys
depends_on:
db:
condition: service_healthy

####################### COPROCESSOR SERVICES #######################
coprocessor:
container_name: coprocessor
build:
context: ../.
dockerfile: fhevm-engine/coprocessor/Dockerfile
tags:
- "ghcr.io/zama-ai/fhevm-coprocessor:v0.7.0-local"
image: ghcr.io/zama-ai/fhevm-coprocessor:v0.7.0-rc0
environment:
DATABASE_URL: ${DATABASE_URL}
ports:
- '50051:50051'
volumes:
- ./config/coprocessor.key:/usr/share/coprocessor.key
command:
- coprocessor
- --run-server
- --server-addr=0.0.0.0:50051
- --coprocessor-private-key=/usr/share/coprocessor.key
depends_on:
migration:
condition: service_completed_successfully
fhevm-listener:
container_name: "fhevm-listener"
build:
context: ../.
dockerfile: fhevm-engine/coprocessor/Dockerfile
tags:
- "ghcr.io/zama-ai/fhevm-coprocessor:v0.7.0-local"
image: ghcr.io/zama-ai/fhevm-coprocessor:v0.7.0-rc0
environment:
DATABASE_URL: ${DATABASE_URL}
ACL_CONTRACT_ADDRESS: ${ACL_CONTRACT_ADDRESS}
INPUT_VERIFIER_ADDRESS: ${INPUT_VERIFIER_ADDRESS}
ports:
- '50052:50052'
volumes:
- ./config/coprocessor.key:/usr/share/coprocessor.key
command:
- fhevm_listener
- --database-url=$DATABASE_URL
- --acl-contract-address=$ACL_CONTRACT_ADDRESS
- --tfhe-contract-address=$INPUT_VERIFIER_ADDRESS
- --url=ws://layer2-node:8546
depends_on:
migration:
condition: service_completed_successfully

# sns-worker:
# container_name: "sns-worker"
# build:
# context: ../.
# dockerfile: fhevm-engine/coprocessor/Dockerfile
# tags:
# - "ghcr.io/zama-ai/fhevm-coprocessor:v0.7.0-local"
# # image: ghcr.io/zama-ai/fhevm-coprocessor:v0.7.0-rc0
# environment:
# DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor
# command:
# - sns_worker
# - --pg-listen-channel="event_pbs_new_work"
# - --pg-notify-channel="event_pbs_computed"
# ports:
# - '50053:50053'
# depends_on:
# migration:
# condition: service_completed_successfully


volumes:
db:
34 changes: 34 additions & 0 deletions deployments/layer1-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
layer1-node:
container_name: layer1-node
image: ghcr.io/foundry-rs/foundry:stable
environment:
MNEMONIC: ${MNEMONIC}
entrypoint:
[
"anvil",
"--block-time",
"0.1",
"--host",
"0.0.0.0",
"--port",
"8545",
"--chain-id",
"12345",
"--accounts",
"15",
"--mnemonic",
"${MNEMONIC}",
]
ports:
- "8545:8545"

layer1-sc-deploy:
container_name: layer1-sc-deploy
image: ghcr.io/zama-ai/fhevm-smart-contracts-dev:v0.7.0-rc0
volumes:
- ./config/.env.staging.layer1:/app/.env
- ../contracts/hardhat.config.ts:/app/hardhat.config.ts
- ../contracts/launch-fhevm-staging.sh:/app/launch-fhevm-staging.sh
- ../contracts/addressesL2:/app/addressesL2
entrypoint: ["/app/launch-fhevm-staging.sh"]
31 changes: 31 additions & 0 deletions deployments/layer2-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
layer2-node:
container_name: layer2-node
image: ghcr.io/foundry-rs/foundry:stable
environment:
MNEMONIC: ${MNEMONIC}
entrypoint:
[
"anvil",
"--block-time",
"0.1",
"--host",
"0.0.0.0",
"--port",
"8546",
"--chain-id",
"54321",
"--accounts",
"15",
"--mnemonic",
"${MNEMONIC}"
]
ports:
- "8546:8546"

layer2-sc-deploy:
container_name: layer2-sc-deploy
image: ghcr.io/zama-ai/gateway-l2/sc-bundle:b479cf8
volumes:
- ./config/.env.staging.layer2:/app/.env
entrypoint: ["/app/launch-staging-gateway-layer2.sh"]
12 changes: 12 additions & 0 deletions deployments/run-fhevm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -o errexit

# run layer 1 and deploy sc
docker compose --env-file ./config/.env.staging.layer1 -p fhevm -f layer1-docker-compose.yml up -d

# run layer 2 and deploy sc
docker compose --env-file ./config/.env.staging.layer2 -p fhevm -f layer2-docker-compose.yml up -d

# run coprocessor
docker compose --env-file ./config/.env.staging.coprocessor -p fhevm -f coprocessor-docker-compose.yml up -d

0 comments on commit fffcc81

Please sign in to comment.