From ffe51388925e4e08650c03cf8a6015c92ad0d4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joseph-Andr=C3=A9=20Turk?= Date: Fri, 27 Sep 2024 01:56:51 +0200 Subject: [PATCH] fix: custom .env supported also in non-mocked --- .gitignore | 2 + docker-compose/docker-compose-full.yml | 6 +- .../docker-compose-full.yml.template | 98 +++++++++++++++++++ package.json | 2 +- scripts/fund_test_addresses_docker.sh | 4 +- .../precomputeAddresses.sh | 11 +-- scripts/rewrite-docker-compose.sh | 23 +++++ test/encryptedERC20/EncryptedERC20.ts | 2 +- 8 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 docker-compose/docker-compose-full.yml.template rename precomputeAddresses.sh => scripts/precomputeAddresses.sh (83%) create mode 100755 scripts/rewrite-docker-compose.sh diff --git a/.gitignore b/.gitignore index 52aa9eb..f1fbdfd 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ yarn.lock res/ running_node/ + +docker-compose/docker-compose-full.yml diff --git a/docker-compose/docker-compose-full.yml b/docker-compose/docker-compose-full.yml index 45ba51b..d0222a4 100644 --- a/docker-compose/docker-compose-full.yml +++ b/docker-compose/docker-compose-full.yml @@ -65,12 +65,12 @@ services: - GATEWAY__ETHEREUM__WSS_URL=ws://fhevm-validator:8546 - GATEWAY__ETHEREUM__HTTP_URL=http://fhevm-validator:8545 - GATEWAY__ETHEREUM__FHE_LIB_ADDRESS=000000000000000000000000000000000000005d - - GATEWAY__ETHEREUM__ORACLE_PREDEPLOY_ADDRESS=${GATEWAY_CONTRACT_PREDEPLOY_ADDRESS} + - GATEWAY__ETHEREUM__ORACLE_PREDEPLOY_ADDRESS=D14A4da7209311e1363Aad8e6240398606c218B7 - GATEWAY__KMS__ADDRESS=http://kms-validator:9090 - GATEWAY__KMS__KEY_ID=408d8cbaa51dece7f782fe04ba0b1c1d017b1088 - GATEWAY__STORAGE__URL=http://gateway-store:8088 - ASC_CONN__BLOCKCHAIN__ADDRESSES=http://kms-validator:9090 - - GATEWAY__ETHEREUM__RELAYER_KEY=${PRIVATE_KEY_GATEWAY_RELAYER} + - GATEWAY__ETHEREUM__RELAYER_KEY=31dc342b52a60cd5efac05b7b623cba3fb96a08686bc1b99aa249f15ec3f4b00 - RUST_BACKTRACE=1 depends_on: fhevm-validator: @@ -80,7 +80,7 @@ services: fhevm-validator: environment: - - TFHE_EXECUTOR_CONTRACT_ADDRESS=${TFHE_EXECUTOR_CONTRACT_ADDRESS} + - TFHE_EXECUTOR_CONTRACT_ADDRESS=0xEDB09F6A9A2995Fc9f492e67DA84CF073184dE2e image: ghcr.io/zama-ai/ethermint-dev-node:v0.5.0-2 ports: - "26656-26657:26656-26657" diff --git a/docker-compose/docker-compose-full.yml.template b/docker-compose/docker-compose-full.yml.template new file mode 100644 index 0000000..45ba51b --- /dev/null +++ b/docker-compose/docker-compose-full.yml.template @@ -0,0 +1,98 @@ +name: zama-dev + +services: + gateway-store: + image: ghcr.io/zama-ai/kms-blockchain-gateway-dev:v0.7.1 + command: + - "kv_store" + ports: + - "8088:8088" + + kms-validator: + image: ghcr.io/zama-ai/kms-blockchain-asc-dev:v0.7.1 + ports: + - "36656:26656" + - "36657:26657" + - "1317:1317" + - "9090:9090" + entrypoint: ["/app/bootstrap.sh"] + healthcheck: + test: "wget -Sq --spider http://localhost:26657/status" + interval: 1s + timeout: 1s + retries: 5 + start_period: 10s + + connector: + image: ghcr.io/zama-ai/kms-blockchain-connector-dev:v0.7.1 + command: + - "kms-blockchain-connector" + environment: + - ASC_CONN__BLOCKCHAIN__ADDRESSES=http://kms-validator:9090 + - ASC_CONN__CORE__ADDRESSES=http://kms-core:50051 + - ASC_CONN__STORE__URL=http://gateway-store:8088 + - ASC_CONN__CORE__TIMEOUT_CONFIG__DECRYPTION__INITIAL_WAIT_TIME=1 + - ASC_CONN__CORE__TIMEOUT_CONFIG__DECRYPTION__RETRY_INTERVAL=1 + - ASC_CONN__CORE__TIMEOUT_CONFIG__REENCRYPTION__INITIAL_WAIT_TIME=1 + - ASC_CONN__CORE__TIMEOUT_CONFIG__REENCRYPTION__RETRY_INTERVAL=1 + depends_on: + kms-validator: + condition: service_healthy + kms-core: + condition: service_healthy + + kms-core: + image: ghcr.io/zama-ai/kms-service-dev:v0.7.1 + ports: + - "50051:50051" + healthcheck: + test: "grpc-health-probe --addr=localhost:50051" + interval: 1s + timeout: 1s + retries: 5 + start_period: 10s + + gateway: + image: ghcr.io/zama-ai/kms-blockchain-gateway-dev:v0.7.1 + ports: + - "7077:7077" + command: + - "gateway" + volumes: + - ../default.toml:/app/gateway/config/default.toml:Z + environment: + - GATEWAY__ETHEREUM__LISTENER_TYPE=FHEVM_V1_1 + - GATEWAY__ETHEREUM__WSS_URL=ws://fhevm-validator:8546 + - GATEWAY__ETHEREUM__HTTP_URL=http://fhevm-validator:8545 + - GATEWAY__ETHEREUM__FHE_LIB_ADDRESS=000000000000000000000000000000000000005d + - GATEWAY__ETHEREUM__ORACLE_PREDEPLOY_ADDRESS=${GATEWAY_CONTRACT_PREDEPLOY_ADDRESS} + - GATEWAY__KMS__ADDRESS=http://kms-validator:9090 + - GATEWAY__KMS__KEY_ID=408d8cbaa51dece7f782fe04ba0b1c1d017b1088 + - GATEWAY__STORAGE__URL=http://gateway-store:8088 + - ASC_CONN__BLOCKCHAIN__ADDRESSES=http://kms-validator:9090 + - GATEWAY__ETHEREUM__RELAYER_KEY=${PRIVATE_KEY_GATEWAY_RELAYER} + - RUST_BACKTRACE=1 + depends_on: + fhevm-validator: + condition: service_healthy + kms-validator: + condition: service_healthy + + fhevm-validator: + environment: + - TFHE_EXECUTOR_CONTRACT_ADDRESS=${TFHE_EXECUTOR_CONTRACT_ADDRESS} + image: ghcr.io/zama-ai/ethermint-dev-node:v0.5.0-2 + ports: + - "26656-26657:26656-26657" + - "8545-8546:8545-8546" + volumes: + - $PWD/network-fhe-keys:/network-fhe-keys:Z + - ../setup.sh:/config/setup.sh:Z + security_opt: + - no-new-privileges:true + healthcheck: + test: 'curl -s -H "Connection: Upgrade" -H "Upgrade: websocket" http://localhost:8546' + interval: 5s + timeout: 3s + retries: 5 + start_period: 20s diff --git a/package.json b/package.json index 5128871..36a251e 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "task:getEthereumAddress": "hardhat task:getEthereumAddress", "task:deployERC20": "hardhat task:deployERC20", "task:accounts": "hardhat task:accounts", - "fhevm:start": "./precomputeAddresses.sh && make run-full && ./scripts/fund_test_addresses_docker.sh && ./launch-fhevm.sh", + "fhevm:start": "./scripts/precomputeAddresses.sh && ./scripts/rewrite-docker-compose.sh && make run-full && ./scripts/fund_test_addresses_docker.sh && ./launch-fhevm.sh", "fhevm:stop": "make clean", "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", diff --git a/scripts/fund_test_addresses_docker.sh b/scripts/fund_test_addresses_docker.sh index 9acb523..d99a87a 100755 --- a/scripts/fund_test_addresses_docker.sh +++ b/scripts/fund_test_addresses_docker.sh @@ -3,8 +3,8 @@ # Read MNEMONIC from .env file, remove 'export' and quotes MNEMONIC=$(grep MNEMONIC .env | cut -d '"' -f 2) PRIVATE_KEY_GATEWAY_DEPLOYER=$(grep PRIVATE_KEY_GATEWAY_DEPLOYER .env | cut -d '"' -f 2) -PRIVATE_KEY_GATEWAY_OWNER=$(grep PRIVATE_KEY_GATEWAY_DEPLOYER .env | cut -d '"' -f 2) -PRIVATE_KEY_GATEWAY_RELAYER=$(grep PRIVATE_KEY_GATEWAY_DEPLOYER .env | cut -d '"' -f 2) +PRIVATE_KEY_GATEWAY_OWNER=$(grep PRIVATE_KEY_GATEWAY_OWNER .env | cut -d '"' -f 2) +PRIVATE_KEY_GATEWAY_RELAYER=$(grep PRIVATE_KEY_GATEWAY_RELAYER .env | cut -d '"' -f 2) # Verify that global envs are set if [ -z "$MNEMONIC" ]; then diff --git a/precomputeAddresses.sh b/scripts/precomputeAddresses.sh similarity index 83% rename from precomputeAddresses.sh rename to scripts/precomputeAddresses.sh index cb8fff0..0575ae5 100755 --- a/precomputeAddresses.sh +++ b/scripts/precomputeAddresses.sh @@ -30,10 +30,9 @@ GATEWAY_CONTRACT_PREDEPLOY_ADDRESS_NO0X=${GATEWAY_CONTRACT_PREDEPLOY_ADDRESS#0x} PRIVATE_KEY_GATEWAY_RELAYER=$(grep PRIVATE_KEY_GATEWAY_RELAYER .env | cut -d '"' -f 2) # Write to .env.docker -cat << EOF > "$ENV_DOCKER" -TFHE_EXECUTOR_CONTRACT_ADDRESS=$TFHE_EXECUTOR_CONTRACT_ADDRESS -PRIVATE_KEY_GATEWAY_RELAYER=$PRIVATE_KEY_GATEWAY_RELAYER -GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=$GATEWAY_CONTRACT_PREDEPLOY_ADDRESS_NO0X -EOF - +{ + echo "TFHE_EXECUTOR_CONTRACT_ADDRESS=$TFHE_EXECUTOR_CONTRACT_ADDRESS" + echo "GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=$GATEWAY_CONTRACT_PREDEPLOY_ADDRESS_NO0X" + echo "PRIVATE_KEY_GATEWAY_RELAYER=$PRIVATE_KEY_GATEWAY_RELAYER" +} > "$ENV_DOCKER" echo "Successfully created $ENV_DOCKER with the aggregated environment variables." \ No newline at end of file diff --git a/scripts/rewrite-docker-compose.sh b/scripts/rewrite-docker-compose.sh new file mode 100755 index 0000000..8c92da6 --- /dev/null +++ b/scripts/rewrite-docker-compose.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +INPUT_FILE="docker-compose/docker-compose-full.yml.template" +OUTPUT_FILE="docker-compose/docker-compose-full.yml" +ENV_FILE=".env.docker" + +TEMP_FILE=$(mktemp) +cp "$INPUT_FILE" "$TEMP_FILE" + +while IFS= read -r line +do + [[ $line =~ ^[[:space:]]*$ || $line =~ ^# ]] && continue + key=$(echo "$line" | cut -d= -f1) + value=$(echo "$line" | cut -d= -f2-) + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + value=$(printf '%s\n' "$value" | sed -e 's/[\/&]/\\&/g') + sed -i.bak "s|\${$key}|$value|g" "$TEMP_FILE" +done < "$ENV_FILE" + +mv "$TEMP_FILE" "$OUTPUT_FILE" + +echo "Processed $INPUT_FILE and wrote result to $OUTPUT_FILE" \ No newline at end of file diff --git a/test/encryptedERC20/EncryptedERC20.ts b/test/encryptedERC20/EncryptedERC20.ts index 5bd83fd..b210fd7 100644 --- a/test/encryptedERC20/EncryptedERC20.ts +++ b/test/encryptedERC20/EncryptedERC20.ts @@ -17,7 +17,7 @@ describe("EncryptedERC20", function () { this.instances = await createInstances(this.signers); }); - it.only("should mint the contract", async function () { + it("should mint the contract", async function () { const transaction = await this.erc20.mint(1000); await transaction.wait();