Skip to content

Commit

Permalink
Merge pull request #39 from zama-ai/custom-env
Browse files Browse the repository at this point in the history
fix: custom .env supported also in non-mocked
  • Loading branch information
jatZama authored Sep 26, 2024
2 parents 79f7d5c + ffe5138 commit a1f8ee0
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ yarn.lock

res/
running_node/

docker-compose/docker-compose-full.yml
6 changes: 3 additions & 3 deletions docker-compose/docker-compose-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
98 changes: 98 additions & 0 deletions docker-compose/docker-compose-full.yml.template
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions scripts/fund_test_addresses_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions precomputeAddresses.sh → scripts/precomputeAddresses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
23 changes: 23 additions & 0 deletions scripts/rewrite-docker-compose.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion test/encryptedERC20/EncryptedERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit a1f8ee0

Please sign in to comment.