Skip to content

Commit

Permalink
fix: pass salt to deploy-l1-contracts.sh (#10586)
Browse files Browse the repository at this point in the history
This PR adds deterministic deployment salt to deploy-l1-contracts

---------

Co-authored-by: Mitch <[email protected]>
  • Loading branch information
alexghr and just-mitch authored Dec 12, 2024
1 parent 0ba2425 commit d6be2c8
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/devnet-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -161,6 +171,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_DEPLOYMENT_SALT=${DEPLOYMENT_SALT:-$RANDOM}" \
-out=tfplan \
-lock=${{ inputs.respect_tf_lock }}
Expand Down
10 changes: 6 additions & 4 deletions spartan/aztec-network/files/config/deploy-l1-contracts.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash
set -exu

CHAIN_ID=$1

SALT=${1:-$RANDOM}
CHAIN_ID=$2

# Run the deploy-l1-contracts command and capture the output
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
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"
Expand Down
27 changes: 19 additions & 8 deletions spartan/aztec-network/templates/boot-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,28 @@ 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
{{- include "aztec-network.image" . | nindent 10 }}
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
/tmp/deploy-l1-contracts.sh "{{ .Values.aztec.l1Salt }}" "{{ .Values.ethereum.chainId }}" "{{ join "," .Values.validator.validatorAddresses }}"
volumeMounts:
- name: scripts-output
mountPath: /shared/contracts
Expand Down
9 changes: 9 additions & 0 deletions spartan/aztec-network/templates/reth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions spartan/aztec-network/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
5 changes: 5 additions & 0 deletions spartan/terraform/deploy-release/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spartan/terraform/deploy-release/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}

0 comments on commit d6be2c8

Please sign in to comment.