Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sepolia deployments #12329

Merged
merged 17 commits into from
Mar 3, 2025
Merged
15 changes: 7 additions & 8 deletions .github/workflows/network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ on:
required: false
type: string
default: "false"
ref:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep this please, otherwise the values file needs to be in master in order to test a deployment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless the github.ref below does the same thing in that case all gucci

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesss workflow dispatch actions have this by default, we don't need an extra input of our own
image

description: The branch name to deploy from
required: false
type: string
default: "master"
sepolia_deployment:
description: "Whether to deploy on Sepolia network (default: false)"
required: false
Expand Down Expand Up @@ -123,7 +118,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
ref: ${{ inputs.ref || github.ref }}

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
Expand Down Expand Up @@ -174,8 +169,12 @@ jobs:
run: |
REPO=$(git rev-parse --show-toplevel)
export FUNDING_PRIVATE_KEY=${{ secrets.SEPOLIA_FUNDING_PRIVATE_KEY }}
export ETHEREUM_HOST=${{ env.EXTERNAL_ETHEREUM_HOST }}
mnemonic=$(bash $REPO/spartan/scripts/prepare_sepolia_accounts.sh ${{ env.VALUES_FILE }} 5)
export ETHEREUM_HOST="https://json-rpc.${{ secrets.GCP_SEPOLIA_URL }}?key=${{ secrets.GCP_SEPOLIA_API_KEY }}"
echo "Preparing sepolia accounts..."
MNEMONIC_FILE=$(mktemp)
$REPO/spartan/scripts/prepare_sepolia_accounts.sh ${{ env.VALUES_FILE }} 5 "$MNEMONIC_FILE"
mnemonic=$(cat "$MNEMONIC_FILE")
rm "$MNEMONIC_FILE"
echo "::add-mask::$mnemonic"
echo "mnemonic=$mnemonic" >> "$GITHUB_OUTPUT"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eu
set -exu

mnemonic=$1
# at least 2 accounts are needed for the validator and prover nodes
Expand All @@ -8,6 +8,8 @@ funding_address=${3:-"0x33D525f5ac95c2BCf98b644738C7d5673480493A"}

XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}

ETHEREUM_RPC_URL=$(echo "$ETHEREUM_HOSTS" | cut -d',' -f1)

# Install cast if needed
if ! command -v cast &>/dev/null; then
curl -L https://foundry.paradigm.xyz | bash
Expand All @@ -22,10 +24,10 @@ for i in $(seq 0 $((num_accounts - 1))); do
private_key=$(cast wallet private-key --mnemonic "$mnemonic" --mnemonic-index $i)

# Get balance
balance=$(cast balance $address --rpc-url "$ETHEREUM_HOST")
balance=$(cast balance $address --rpc-url "$ETHEREUM_RPC_URL")

if [ "$balance" != "0" ]; then
gas_price=$(cast gas-price --rpc-url "$ETHEREUM_HOST")
gas_price=$(cast gas-price --rpc-url "$ETHEREUM_RPC_URL")
gas_price=$((gas_price * 120 / 100)) # Add 20% to gas price
gas_cost=$((21000 * gas_price))

Expand All @@ -34,7 +36,7 @@ for i in $(seq 0 $((num_accounts - 1))); do

if [ "$send_amount" -gt "0" ]; then
echo "Sending $send_amount wei from $address to $funding_address"
cast send --private-key "$private_key" --rpc-url "$ETHEREUM_HOST" "$funding_address" \
cast send --private-key "$private_key" --rpc-url "$ETHEREUM_RPC_URL" "$funding_address" \
--value "$send_amount" --gas-price "$gas_price" --async
else
echo "Balance too low to cover gas costs for $address"
Expand Down
4 changes: 2 additions & 2 deletions spartan/aztec-network/templates/consolidate-balances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ spec:
chmod +x /tmp/consolidate-sepolia-balances.sh
/tmp/consolidate-sepolia-balances.sh "{{ .Values.aztec.l1DeploymentMnemonic }}" {{ add .Values.validator.replicas .Values.proverNode.replicas }}
env:
- name: ETHEREUM_HOST
value: "{{ .Values.ethereum.execution.externalHost }}"
- name: ETHEREUM_HOSTS
value: "{{ .Values.ethereum.execution.externalHosts }}"
{{ end }}
7 changes: 3 additions & 4 deletions spartan/scripts/deploy_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ set -x
namespace="$1"
values_file="${2:-default.yaml}"
sepolia_deployment="${3:-false}"
helm_instance="${4:-spartan}"
mnemonic_file="${4:-"mnemonic.tmp"}"
helm_instance="${5:-spartan}"

# Default values for environment variables
chaos_values="${CHAOS_VALUES:-}"
Expand Down Expand Up @@ -83,9 +84,7 @@ function generate_overrides {
if [ "$sepolia_deployment" = "true" ]; then
echo "Generating sepolia accounts..."
set +x
L1_ACCOUNTS_MNEMONIC=$(./prepare_sepolia_accounts.sh "$values_file")
# write the mnemonic to a file
echo "$L1_ACCOUNTS_MNEMONIC" >mnemonic.tmp
L1_ACCOUNTS_MNEMONIC=$(./prepare_sepolia_accounts.sh "$values_file" "$mnemonic_file")
set -x
else
echo "Generating devnet config..."
Expand Down
24 changes: 16 additions & 8 deletions spartan/scripts/prepare_sepolia_accounts.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
set -eu

set -euo pipefail

source $(git rev-parse --show-toplevel)/ci3/source

values_file=$1
eth_amount=${2:-"1"}
output_file=${3:-"mnemonic.tmp"}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}

value_yamls="../aztec-network/values/$values_file ../aztec-network/values.yaml"
Expand All @@ -14,31 +18,36 @@ num_accounts=$((num_validators + num_provers + num_bots))

# Install bc if needed
if ! command -v bc &>/dev/null; then
echo "Installing bc..."
apt-get update && apt-get install -y bc
fi

# Install cast if needed
if ! command -v cast &>/dev/null; then
echo "Installing cast..."
curl -L https://foundry.paradigm.xyz | bash
$HOME/.foundry/bin/foundryup && export PATH="$PATH:$HOME/.foundry/bin" ||
$XDG_CONFIG_HOME/.foundry/bin/foundryup && export PATH="$PATH:$XDG_CONFIG_HOME/.foundry/bin"
$HOME/.foundry/bin/foundryup && export PATH="$PATH:$HOME/.foundry/bin" || $XDG_CONFIG_HOME/.foundry/bin/foundryup && export PATH="$PATH:$XDG_CONFIG_HOME/.foundry/bin"
fi

# Install yq if needed
if ! command -v yq &>/dev/null; then
echo "Installing yq..."
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
chmod +x /usr/local/bin/yq
fi

# Create a new mnemonic with the required number of accounts
echo "Creating mnemonic..."
cast wallet new-mnemonic --accounts "$num_accounts" --json >output.json
MNEMONIC=$(jq -r '.mnemonic' output.json)
ADDRESSES=$(jq -r '.accounts[].address' output.json)
rm output.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security nit: it's probably safer to put cleanup like this in a traped cleanup function.


# Convert ETH to wei
wei_amount=$(cast to-wei "$eth_amount" ether)

# Get current gas price and add 25% buffer
echo "Getting gas price..."
gas_price=$(cast gas-price --rpc-url "$ETHEREUM_HOST")
gas_price=$((gas_price * 125 / 100)) # Add 25% to gas price

Expand All @@ -56,6 +65,7 @@ total_value=$(echo "$wei_amount * $num_accounts" | bc)

multicall_address="0xcA11bde05977b3631167028862bE2a173976CA11" # Sepolia Multicall3 contract

echo "Sending transaction..."
tx_hash=$(cast send "$multicall_address" \
"aggregate3Value((address,bool,uint256,bytes)[])" \
"$calls" \
Expand All @@ -64,9 +74,7 @@ tx_hash=$(cast send "$multicall_address" \
--rpc-url "$ETHEREUM_HOST" \
--json --gas-price "$gas_price")

echo >&2 "Sent ${wei_amount} wei to ${num_accounts} addresses in tx $tx_hash"

# Remove temp file
rm output.json
echo "Sent ${wei_amount} wei to ${num_accounts} addresses in tx $tx_hash"

echo "$MNEMONIC"
# Write mnemonic to output file
echo "$MNEMONIC" >"$output_file"
11 changes: 6 additions & 5 deletions spartan/scripts/test_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ set -x
# Main positional parameter
test=$1
values_file="${2:-default.yaml}"
helm_instance="${3:-spartan}"
mnemonic_file="${3:-$(mktemp)}"
helm_instance="${4:-spartan}"

# Default values for environment variables
namespace="${NAMESPACE:-test-kind}"
Expand Down Expand Up @@ -84,7 +85,7 @@ copy_stern_to_log

# uses VALUES_FILE, CHAOS_VALUES, AZTEC_DOCKER_TAG and INSTALL_TIMEOUT optional env vars
if [ "$fresh_install" != "no-deploy" ]; then
deploy_result=$(OVERRIDES="$OVERRIDES" ./deploy_kind.sh $namespace $values_file $sepolia_run $helm_instance)
deploy_result=$(OVERRIDES="$OVERRIDES" ./deploy_kind.sh $namespace $values_file $sepolia_run $mnemonic_file $helm_instance)
fi

# Find 6 free ports between 9000 and 10000
Expand Down Expand Up @@ -113,11 +114,11 @@ aztec_epoch_duration=$(./read_value.sh "aztec.epochDuration" $value_yamls)
aztec_proof_submission_window=$(./read_value.sh "aztec.proofSubmissionWindow" $value_yamls)

if [ "$sepolia_run" = "true" ]; then
# Read the mnemonic from file mnemonic.tmp
# Read the mnemonic from tmp file
set +x
l1_account_mnemonic=$(cat mnemonic.tmp)
l1_account_mnemonic=$(cat "$mnemonic_file")
set -x
rm mnemonic.tmp
rm "$mnemonic_file"
else
l1_account_mnemonic=$(./read_value.sh "aztec.l1DeploymentMnemonic" $value_yamls)
fi
Expand Down
3 changes: 2 additions & 1 deletion spartan/terraform/deploy-release/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ resource "helm_release" "aztec-gke-cluster" {
for_each = var.EXTERNAL_ETHEREUM_HOSTS != "" ? toset(["iterate"]) : toset([])
content {
name = "ethereum.execution.externalHosts"
value = var.EXTERNAL_ETHEREUM_HOSTS
value = replace(var.EXTERNAL_ETHEREUM_HOSTS, ",", "\\,")
type = "string"
}
}

Expand Down
Loading