From 7fb332725181fcf6e2ec24923a88d81c1acee362 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 10 Dec 2024 16:12:12 +0000 Subject: [PATCH 1/7] fix: pass salt to deploy-l1-contracts.sh --- .../files/config/deploy-l1-contracts.sh | 7 ++++--- .../aztec-network/templates/boot-node.yaml | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/spartan/aztec-network/files/config/deploy-l1-contracts.sh b/spartan/aztec-network/files/config/deploy-l1-contracts.sh index 74f8e3c6bfc..87f48b95a25 100644 --- a/spartan/aztec-network/files/config/deploy-l1-contracts.sh +++ b/spartan/aztec-network/files/config/deploy-l1-contracts.sh @@ -1,7 +1,8 @@ #!/bin/bash set -exu -CHAIN_ID=$1 +SALT=$1 +CHAIN_ID=$2 # Run the deploy-l1-contracts command and capture the output @@ -11,9 +12,9 @@ RETRY_DELAY=60 for attempt in $(seq 1 $MAX_RETRIES); do # if INIT_VALIDATORS is true, then we need to pass the validators flag to the deploy-l1-contracts command if [ "${INIT_VALIDATORS:-false}" = "true" ]; then - output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --mnemonic "$MNEMONIC" --validators $2 --l1-chain-id $CHAIN_ID) && break + output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --mnemonic "$MNEMONIC" --validators $3 --l1-chain-id $CHAIN_ID --salt $SALT) && break else - output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --mnemonic "$MNEMONIC" --l1-chain-id $CHAIN_ID) && break + output=$(node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --mnemonic "$MNEMONIC" --l1-chain-id $CHAIN_ID --salt $SALT) && break fi echo "Attempt $attempt failed. Retrying in $RETRY_DELAY seconds..." sleep "$RETRY_DELAY" diff --git a/spartan/aztec-network/templates/boot-node.yaml b/spartan/aztec-network/templates/boot-node.yaml index 3a5d2103f9a..b8a3662dc18 100644 --- a/spartan/aztec-network/templates/boot-node.yaml +++ b/spartan/aztec-network/templates/boot-node.yaml @@ -56,14 +56,15 @@ spec: - name: deploy-l1-contracts image: {{ .Values.images.aztec.image }} command: - [ - "/bin/bash", - "-c", - "cp /scripts/deploy-l1-contracts.sh /tmp/deploy-l1-contracts.sh && \ - chmod +x /tmp/deploy-l1-contracts.sh && \ - source /shared/config/service-addresses && \ - /tmp/deploy-l1-contracts.sh {{ .Values.ethereum.chainId }} \"{{ join "," .Values.validator.validatorAddresses }}\"" - ] + - /bin/bash + - -c + - | + cp /scripts/deploy-l1-contracts.sh /tmp/deploy-l1-contracts.sh + chmod +x /tmp/deploy-l1-contracts.sh + source /shared/config/service-addresses + HASH=$(echo "$RELEASE_NAME-$RELEASE_REVISION" | sha256sum | head -c 8) # first 4 hex characters = 4 bytes + SALT=$((16#$HASH)) # convert to decimal + /tmp/deploy-l1-contracts.sh $SALT {{ .Values.ethereum.chainId }} "{{ join "," .Values.validator.validatorAddresses }}" volumeMounts: - name: scripts-output mountPath: /shared/contracts @@ -72,6 +73,10 @@ spec: - name: scripts mountPath: /scripts env: + - name: RELEASE_NAME + value: "{{ .Release.Name }}" # e.g. rough-rhino + - name: RELEASE_REVISION + value: "{{ .Release.Revision }}" # e.g. 1, 2, 3. Increased with every helm install of the same name - name: TELEMETRY value: "{{ .Values.telemetry.enabled }}" - name: INIT_VALIDATORS From d2d293c14503dfe55f454bd32c109c556a5ba5d8 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Thu, 12 Dec 2024 14:01:50 +0000 Subject: [PATCH 2/7] refactor: use random salt --- .github/workflows/network-deploy.yml | 11 +++++++++++ spartan/aztec-network/templates/boot-node.yaml | 11 +++++------ spartan/aztec-network/values.yaml | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/network-deploy.yml b/.github/workflows/network-deploy.yml index bb76c24a73d..4a43e80f2f0 100644 --- a/.github/workflows/network-deploy.yml +++ b/.github/workflows/network-deploy.yml @@ -20,6 +20,11 @@ on: required: true type: string default: testnet-deployment-mnemonic + deployment_salt: + description: The salt to use for this deployment. Defaults to random + required: false + type: string + default: "" respect_tf_lock: description: Whether to respect the Terraform lock required: false @@ -53,6 +58,10 @@ on: description: The name of the secret which holds the boot node's contract deployment mnemonic required: true default: testnet-deployment-mnemonic + deployment_salt: + description: The salt to use for this deployment. Defaults to random + required: false + default: "" respect_tf_lock: description: Whether to respect the Terraform lock required: false @@ -82,6 +91,7 @@ jobs: NAMESPACE: ${{ inputs.namespace }} VALUES_FILE: ${{ inputs.values_file }} DEPLOYMENT_MNEMONIC_SECRET_NAME: ${{ inputs.deployment_mnemonic_secret_name }} + DEPLOYMENT_SALT: ${{ inputs.deployment_salt }} CHART_PATH: ./spartan/aztec-network CLUSTER_NAME: aztec-gke REGION: us-west1-a @@ -153,6 +163,7 @@ jobs: -var="GKE_CLUSTER_CONTEXT=${{ env.GKE_CLUSTER_CONTEXT }}" \ -var="AZTEC_DOCKER_IMAGE=${{ env.AZTEC_DOCKER_IMAGE }}" \ -var="L1_DEPLOYMENT_MNEMONIC=${{ steps.get-mnemonic.outputs.mnemonic }}" \ + -var="L1_SALT=${DEPLOYMENT_SALT:-$RANDOM}" \ -out=tfplan \ -lock=${{ inputs.respect_tf_lock }} diff --git a/spartan/aztec-network/templates/boot-node.yaml b/spartan/aztec-network/templates/boot-node.yaml index b8a3662dc18..b8e7a14ec02 100644 --- a/spartan/aztec-network/templates/boot-node.yaml +++ b/spartan/aztec-network/templates/boot-node.yaml @@ -62,8 +62,9 @@ spec: cp /scripts/deploy-l1-contracts.sh /tmp/deploy-l1-contracts.sh chmod +x /tmp/deploy-l1-contracts.sh source /shared/config/service-addresses - HASH=$(echo "$RELEASE_NAME-$RELEASE_REVISION" | sha256sum | head -c 8) # first 4 hex characters = 4 bytes - SALT=$((16#$HASH)) # convert to decimal + + SALT=${SALT:-$RANDOM} + echo "Using SALT=$SALT" /tmp/deploy-l1-contracts.sh $SALT {{ .Values.ethereum.chainId }} "{{ join "," .Values.validator.validatorAddresses }}" volumeMounts: - name: scripts-output @@ -73,10 +74,8 @@ spec: - name: scripts mountPath: /scripts env: - - name: RELEASE_NAME - value: "{{ .Release.Name }}" # e.g. rough-rhino - - name: RELEASE_REVISION - value: "{{ .Release.Revision }}" # e.g. 1, 2, 3. Increased with every helm install of the same name + - name: SALT + value: "{{ .Values.aztec.l1Salt }}" - name: TELEMETRY value: "{{ .Values.telemetry.enabled }}" - name: INIT_VALIDATORS diff --git a/spartan/aztec-network/values.yaml b/spartan/aztec-network/values.yaml index a9596657a6f..4879fe109c5 100644 --- a/spartan/aztec-network/values.yaml +++ b/spartan/aztec-network/values.yaml @@ -35,6 +35,7 @@ aztec: epochProofClaimWindow: 13 # in L2 slots realProofs: false l1DeploymentMnemonic: "test test test test test test test test test test test junk" # the mnemonic used when deploying contracts + l1Salt: "" # leave empty for random salt bootNode: peerIdPrivateKey: "" From fb30f6ef3ff829793838132cddd4bd755090940d Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Thu, 12 Dec 2024 14:14:20 +0000 Subject: [PATCH 3/7] refactor: pass salt directly --- spartan/aztec-network/files/config/deploy-l1-contracts.sh | 4 ++-- spartan/aztec-network/templates/boot-node.yaml | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/spartan/aztec-network/files/config/deploy-l1-contracts.sh b/spartan/aztec-network/files/config/deploy-l1-contracts.sh index 87f48b95a25..5d33946f1e7 100644 --- a/spartan/aztec-network/files/config/deploy-l1-contracts.sh +++ b/spartan/aztec-network/files/config/deploy-l1-contracts.sh @@ -1,14 +1,14 @@ #!/bin/bash set -exu -SALT=$1 +SALT=${1:-$RANDOM} CHAIN_ID=$2 - # Run the deploy-l1-contracts command and capture the output output="" MAX_RETRIES=5 RETRY_DELAY=60 + for attempt in $(seq 1 $MAX_RETRIES); do # if INIT_VALIDATORS is true, then we need to pass the validators flag to the deploy-l1-contracts command if [ "${INIT_VALIDATORS:-false}" = "true" ]; then diff --git a/spartan/aztec-network/templates/boot-node.yaml b/spartan/aztec-network/templates/boot-node.yaml index b8e7a14ec02..c3b8b715b27 100644 --- a/spartan/aztec-network/templates/boot-node.yaml +++ b/spartan/aztec-network/templates/boot-node.yaml @@ -63,9 +63,7 @@ spec: chmod +x /tmp/deploy-l1-contracts.sh source /shared/config/service-addresses - SALT=${SALT:-$RANDOM} - echo "Using SALT=$SALT" - /tmp/deploy-l1-contracts.sh $SALT {{ .Values.ethereum.chainId }} "{{ join "," .Values.validator.validatorAddresses }}" + /tmp/deploy-l1-contracts.sh "{{ .Values.aztec.l1Salt }}" "{{ .Values.ethereum.chainId }}" "{{ join "," .Values.validator.validatorAddresses }}" volumeMounts: - name: scripts-output mountPath: /shared/contracts @@ -74,8 +72,6 @@ spec: - name: scripts mountPath: /scripts env: - - name: SALT - value: "{{ .Values.aztec.l1Salt }}" - name: TELEMETRY value: "{{ .Values.telemetry.enabled }}" - name: INIT_VALIDATORS From da7c3de5211e3e404a4116be75bb0557b108a404 Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 12 Dec 2024 12:58:47 -0500 Subject: [PATCH 4/7] chore: add a log line --- yarn-project/ethereum/src/deploy_l1_contracts.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index c2c731bb978..cbd5376b092 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -673,6 +673,8 @@ export async function deployL1Contract( const l1TxUtils = new L1TxUtils(publicClient, walletClient, logger); + logger?.info(`Deploying contract with salt [${maybeSalt}] and args ${args}`); + if (libraries) { // Note that this does NOT work well for linked libraries having linked libraries. From 943c3c09821a314ce0187bd6937822cc64014478 Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 12 Dec 2024 15:50:21 -0500 Subject: [PATCH 5/7] chore: init universal deployer --- .../aztec-network/files/config/deploy-l1-contracts.sh | 1 + spartan/aztec-network/templates/boot-node.yaml | 11 +++++++++++ spartan/aztec-network/templates/reth.yaml | 9 +++++++++ yarn-project/ethereum/package.json | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/spartan/aztec-network/files/config/deploy-l1-contracts.sh b/spartan/aztec-network/files/config/deploy-l1-contracts.sh index 5d33946f1e7..1f4c56599f7 100644 --- a/spartan/aztec-network/files/config/deploy-l1-contracts.sh +++ b/spartan/aztec-network/files/config/deploy-l1-contracts.sh @@ -8,6 +8,7 @@ CHAIN_ID=$2 output="" MAX_RETRIES=5 RETRY_DELAY=60 +export LOG_LEVEL=debug for attempt in $(seq 1 $MAX_RETRIES); do # if INIT_VALIDATORS is true, then we need to pass the validators flag to the deploy-l1-contracts command diff --git a/spartan/aztec-network/templates/boot-node.yaml b/spartan/aztec-network/templates/boot-node.yaml index c3b8b715b27..931651a0113 100644 --- a/spartan/aztec-network/templates/boot-node.yaml +++ b/spartan/aztec-network/templates/boot-node.yaml @@ -53,6 +53,17 @@ spec: - name: config mountPath: /shared/config {{- if .Values.bootNode.deployContracts }} + - name: deploy-create2-delpoyer + image: {{ .Values.images.foundry.image }} + command: + - /bin/sh + - -c + - | + source /shared/config/service-addresses + cast publish --rpc-url ${ETHEREUM_HOST} 0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222 + volumeMounts: + - name: config + mountPath: /shared/config - name: deploy-l1-contracts image: {{ .Values.images.aztec.image }} command: diff --git a/spartan/aztec-network/templates/reth.yaml b/spartan/aztec-network/templates/reth.yaml index 8a3e28728bf..938d48b649a 100644 --- a/spartan/aztec-network/templates/reth.yaml +++ b/spartan/aztec-network/templates/reth.yaml @@ -42,6 +42,15 @@ spec: balance: '0x3635c9adc5dea00000' // 1000 ETH in wei }; + // We rely on the deterministic deployment proxy to deploy the contracts + // It comes preloaded on anvil (https://book.getfoundry.sh/tutorials/create2-tutorial) + // But we need to do it ourselves for reth + // Addresses/tx in https://github.com/Arachnid/deterministic-deployment-proxy/tree/master + const deployer = '0x3fab184622dc19b6109349b94811493bf2a45362' + genesis.alloc[deployer] = { + balance: '0x3635c9adc5dea00000' // 1000 ETH in wei + }; + fs.writeFileSync('/genesis-output/genesis.json', JSON.stringify(genesis, null, 2)); } diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 0e34d8dcbf1..3300f21bba8 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -91,4 +91,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} From 00296fe325405f0c3546be60301df8b27c3a0568 Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 12 Dec 2024 16:14:57 -0500 Subject: [PATCH 6/7] chore: remove log line --- yarn-project/ethereum/src/deploy_l1_contracts.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index cbd5376b092..c2c731bb978 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -673,8 +673,6 @@ export async function deployL1Contract( const l1TxUtils = new L1TxUtils(publicClient, walletClient, logger); - logger?.info(`Deploying contract with salt [${maybeSalt}] and args ${args}`); - if (libraries) { // Note that this does NOT work well for linked libraries having linked libraries. From 32a4e601bd2a619f125b5e72c0601101c431a9dd Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 12 Dec 2024 16:40:02 -0500 Subject: [PATCH 7/7] fix: terraform deploy --- .github/workflows/devnet-deploy.yml | 6 ++++++ .github/workflows/network-deploy.yml | 2 +- spartan/terraform/deploy-release/main.tf | 5 +++++ spartan/terraform/deploy-release/variables.tf | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/devnet-deploy.yml b/.github/workflows/devnet-deploy.yml index 31f710afe03..83496bc3be0 100644 --- a/.github/workflows/devnet-deploy.yml +++ b/.github/workflows/devnet-deploy.yml @@ -13,6 +13,11 @@ on: description: The name of the secret which holds the boot node's contract deployment mnemonic required: true default: testnet-deployment-mnemonic + deployment_salt: + description: The salt to use for this deployment. Defaults to random + required: false + type: string + default: "" respect_tf_lock: description: Whether to respect the Terraform lock required: false @@ -39,6 +44,7 @@ jobs: values_file: release-devnet.yaml aztec_docker_image: ${{ github.event.inputs.aztec_docker_image }} deployment_mnemonic_secret_name: ${{ github.event.inputs.deployment_mnemonic_secret_name }} + deployment_salt: ${{ github.event.inputs.deployment_salt }} respect_tf_lock: ${{ github.event.inputs.respect_tf_lock }} secrets: GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} diff --git a/.github/workflows/network-deploy.yml b/.github/workflows/network-deploy.yml index 4a43e80f2f0..de58c089398 100644 --- a/.github/workflows/network-deploy.yml +++ b/.github/workflows/network-deploy.yml @@ -163,7 +163,7 @@ jobs: -var="GKE_CLUSTER_CONTEXT=${{ env.GKE_CLUSTER_CONTEXT }}" \ -var="AZTEC_DOCKER_IMAGE=${{ env.AZTEC_DOCKER_IMAGE }}" \ -var="L1_DEPLOYMENT_MNEMONIC=${{ steps.get-mnemonic.outputs.mnemonic }}" \ - -var="L1_SALT=${DEPLOYMENT_SALT:-$RANDOM}" \ + -var="L1_DEPLOYMENT_SALT=${DEPLOYMENT_SALT:-$RANDOM}" \ -out=tfplan \ -lock=${{ inputs.respect_tf_lock }} diff --git a/spartan/terraform/deploy-release/main.tf b/spartan/terraform/deploy-release/main.tf index 73eba9e5b37..84d44bae93e 100644 --- a/spartan/terraform/deploy-release/main.tf +++ b/spartan/terraform/deploy-release/main.tf @@ -52,6 +52,11 @@ resource "helm_release" "aztec-gke-cluster" { value = var.L1_DEPLOYMENT_MNEMONIC } + set { + name = "aztec.l1Salt" + value = var.L1_DEPLOYMENT_SALT + } + # Setting timeout and wait conditions timeout = 1200 # 20 minutes in seconds wait = true diff --git a/spartan/terraform/deploy-release/variables.tf b/spartan/terraform/deploy-release/variables.tf index 0dff0d4509b..7a5fbc364aa 100644 --- a/spartan/terraform/deploy-release/variables.tf +++ b/spartan/terraform/deploy-release/variables.tf @@ -24,3 +24,9 @@ variable "L1_DEPLOYMENT_MNEMONIC" { type = string sensitive = true } + +variable "L1_DEPLOYMENT_SALT" { + description = "Salt to use for the L1 contract deployments" + type = string + default = "" +}