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

feat: pre-deployed erc20 gas token #386

Merged
merged 14 commits into from
Nov 25, 2024
1 change: 1 addition & 0 deletions .github/tests/additional-services.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
additional_services:
- arpeggio
# - blockscout # blockscout experiences Out of Memory (OOM) termination when deployed inside github runners.
Expand Down
1 change: 1 addition & 0 deletions .github/tests/attach-second-cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ deployment_stages:
deploy_agglayer: false

args:
verbosity: debug
deployment_suffix: "-002"
zkevm_rollup_chain_id: 20202
zkevm_rollup_id: 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v7.0.0-rc.2-fork.11
zkevm_prover_image: hermeznetwork/zkevm-prover:v7.0.4-fork.11
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v7.0.0-rc.2-fork.11
zkevm_prover_image: hermeznetwork/zkevm-prover:v7.0.4-fork.11
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v7.0.0-rc.2-fork.11
zkevm_prover_image: hermeznetwork/zkevm-prover:v7.0.4-fork.11
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v8.0.0-rc.4-fork.12
zkevm_prover_image: hermeznetwork/zkevm-prover:v8.0.0-RC14-fork.12
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v8.0.0-rc.4-fork.12
zkevm_prover_image: hermeznetwork/zkevm-prover:v8.0.0-RC14-fork.12
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v8.1.0-rc.1-fork.13
zkevm_prover_image: hermeznetwork/zkevm-prover:v9.0.0-RC2-fork.13
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v8.1.0-rc.1-fork.13
zkevm_prover_image: hermeznetwork/zkevm-prover:v9.0.0-RC2-fork.13
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.60.0-beta10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v6.0.0-rc.1-fork.9
zkevm_prover_image: hermeznetwork/zkevm-prover:v6.0.8
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.1.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v6.0.0-rc.1-fork.9
zkevm_prover_image: hermeznetwork/zkevm-prover:v6.0.8
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.1.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v6.0.0-rc.1-fork.9
zkevm_prover_image: hermeznetwork/zkevm-prover:v6.0.8
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.1.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
args:
verbosity: debug
zkevm_contracts_image: leovct/zkevm-contracts:v6.0.0-rc.1-fork.9
zkevm_prover_image: hermeznetwork/zkevm-prover:v6.0.8
cdk_erigon_node_image: hermeznetwork/cdk-erigon:v2.1.2
Expand Down
6 changes: 6 additions & 0 deletions .github/tests/external-l1/deploy-cdk-to-local-l1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
deployment_stages:
# Disable local L1.
deploy_l1: false

args:
verbosity: debug
2 changes: 2 additions & 0 deletions .github/tests/external-l1/deploy-cdk-to-sepolia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ deployment_stages:
deploy_l1: false

args:
verbosity: debug

## L1 Config
l1_chain_id: 11155111
# TODO: Create another mnemonic seed phrase for running the contract deployment on L1.
Expand Down
3 changes: 3 additions & 0 deletions .github/tests/external-l1/deploy-local-l1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ deployment_stages:
deploy_agglayer: false
deploy_cdk_erigon_node: false
deploy_l2_contracts: false

args:
verbosity: debug
1 change: 0 additions & 1 deletion .github/tests/fork12-pessimistic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ args:
consensus_contract_type: pessimistic
sequencer_type: erigon
erigon_strict_mode: false
zkevm_use_gas_token_contract: false
#agglayer_prover_sp1_key:
enable_normalcy: true
2 changes: 2 additions & 0 deletions .github/tests/forks/fork11.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
args:
verbosity: debug

# https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags?name=fork.11
zkevm_contracts_image: leovct/zkevm-contracts:v7.0.0-rc.2-fork.11

Expand Down
2 changes: 2 additions & 0 deletions .github/tests/forks/fork12.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
args:
verbosity: debug

# https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags?name=fork.12
zkevm_contracts_image: leovct/zkevm-contracts:v8.0.0-rc.4-fork.12

Expand Down
2 changes: 2 additions & 0 deletions .github/tests/forks/fork13.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
args:
verbosity: debug

# https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags?name=fork.12
zkevm_contracts_image: leovct/zkevm-contracts:v8.1.0-rc.1-fork.13

Expand Down
2 changes: 2 additions & 0 deletions .github/tests/forks/fork9.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
args:
verbosity: debug

# https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags?name=fork.9
zkevm_contracts_image: leovct/zkevm-contracts:v6.0.0-rc.1-fork.9

Expand Down
2 changes: 0 additions & 2 deletions .github/tests/gas-token.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/tests/gas-token/auto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
args:
verbosity: debug
gas_token_enabled: true
4 changes: 4 additions & 0 deletions .github/tests/gas-token/pre-deployed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
args:
verbosity: debug
gas_token_enabled: true
gas_token_address: "0xCHANGEME"
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ deployment_stages:
deploy_l2_contracts: false

args:
verbosity: debug
additional_services:
- pless_zkevm_node
l1_rpc_url: CHANGE_ME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Only expose the datastream port of the cdk-erigon sequencer to a static public port.
# All the other ports will be allocated dynamically using Kurtosis.
args:
verbosity: debug
use_dynamic_ports: false
static_ports:
cdk_erigon_sequencer_start_port: 61700
1 change: 1 addition & 0 deletions .github/tests/static-ports/custom-static-ports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# - L1 services will be exposed on the range 60000-60999.
# - L2 services on the range 61000-61999.
args:
verbosity: debug
use_dynamic_ports: false
static_ports:
# L1 public ports (60000-60999).
Expand Down
1 change: 1 addition & 0 deletions .github/tests/static-ports/default-static-ports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# - L1 services will be exposed on the range 50000-50999.
# - L2 services on the range 51000-51999.
args:
verbosity: debug
use_dynamic_ports: false
86 changes: 84 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ jobs:
- id: set-matrix
# List all yml files in the .github/tests directory, as well as test combinations, except for the additional-services.yml file.
run: |
files=$(ls -R ./.github/tests/combinations/*.yml ./.github/tests/static-ports/custom-static-ports.yml ./.github/tests/static-ports/default-static-ports.yml | grep -v 'additional-services.yml')
files=$(ls -R \
./.github/tests/combinations/*.yml \
./.github/tests/gas-token/auto.yml \
./.github/tests/static-ports/custom-static-ports.yml \
./.github/tests/static-ports/default-static-ports.yml \
| grep -v 'additional-services.yml')
matrix=$(echo "$files" | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=$matrix" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -188,6 +193,83 @@ jobs:
name: ${{ env.ARCHIVE_NAME }}
path: ./dump

pre-deployed-gas-token:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# This step will only execute if the necessary secrets are available, preventing failures
# on pull requests from forked repositories.
if: ${{ env.DOCKERHUB_USERNAME && env.DOCKERHUB_TOKEN }}
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Install Kurtosis CDK tools
uses: ./.github/actions/setup-kurtosis-cdk

- name: Deploy L1 chain
run: kurtosis run --enclave=${{ env.ENCLAVE_NAME }} --args-file=./.github/tests/external-l1/deploy-local-l1.yml .

- name: Deploy gas token on L1
run: |
zkevm_contracts_version="v8.0.0-rc.4-fork.12"
echo "Cloning zkevm-contracts $zkevm_contracts_version..."
git clone https://github.com/0xPolygonHermez/zkevm-contracts
pushd zkevm-contracts
git checkout $zkevm_contracts_version
npm install @openzeppelin/[email protected]
printf "[profile.default]\nsrc = 'contracts'\nout = 'out'\nlibs = ['node_modules']\n" > foundry.toml

echo "Deploying gas token to L1..."
l1_rpc_url=$(kurtosis port print ${{ env.ENCLAVE_NAME }} el-1-geth-lighthouse rpc)
gas_token_address=$(forge create \
--json \
--rpc-url $l1_rpc_url \
--mnemonic "giant issue aisle success illegal bike spike question tent bar rely arctic volcano long crawl hungry vocal artwork sniff fantasy very lucky have athlete" \
contracts/mocks/ERC20PermitMock.sol:ERC20PermitMock \
--constructor-args "CDK Gas Token" "CDK" "0xE34aaF64b29273B7D567FCFc40544c014EEe9970" "1000000000000000000000000" \
| jq --raw-output '.deployedTo')
if [[ -z "$gas_token_address" ]]; then
echo "Unable to deploy gas token"
exit 1
fi
echo "Gas token contract deployed at $gas_token_address on L1"
popd
yq -Y --in-place ".args.gas_token_address = \"$gas_token_address\"" ./.github/tests/gas-token/pre-deployed.yml

- name: Deploy the rest of the stack
run: |
yq -Y --in-place ".deployment_stages.deploy_l1 = false" ./.github/tests/gas-token/pre-deployed.yml
kurtosis run --enclave=${{ env.ENCLAVE_NAME }} --args-file=./.github/tests/gas-token/pre-deployed.yml .

- name: Inspect enclave
run: kurtosis enclave inspect ${{ env.ENCLAVE_NAME }}

- name: Monitor verified batches
working-directory: .github/scripts
run: |
./monitor-verified-batches.sh \
--enclave ${{ env.ENCLAVE_NAME }} \
--rpc-url "$(kurtosis port print ${{ env.ENCLAVE_NAME }} cdk-erigon-rpc-001 rpc)"

- name: Dump enclave
if: ${{ !cancelled() }}
run: kurtosis enclave dump ${{ env.ENCLAVE_NAME }} ./dump

- name: Upload enclave dump
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: dump_pre_deployed_gas_token${{ github.run_id }}
path: ./dump

additional-services:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down Expand Up @@ -386,7 +468,7 @@ jobs:

- name: Deploy to local L1 chain
run: |
kurtosis run --enclave=${{ env.ENCLAVE_NAME }} . '{"deployment_stages": {"deploy_l1": false}}'
kurtosis run --enclave=${{ env.ENCLAVE_NAME }} --args-file=./.github/tests/external-l1/deploy-cdk-to-local-l1.yml .

- name: Inspect enclave
run: kurtosis enclave inspect ${{ env.ENCLAVE_NAME }}
Expand Down
1 change: 0 additions & 1 deletion docs/upgrade-pp/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ args:
consensus_contract_type: pessimistic
sequencer_type: erigon
erigon_strict_mode: false
zkevm_use_gas_token_contract: false
enable_normalcy: true
#+end_src

Expand Down
8 changes: 6 additions & 2 deletions input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ DEFAULT_ROLLUP_ARGS = {
# This flag will enable a stateless executor to verify the execution of the batches.
# Set to true to run erigon as the sequencer.
"erigon_strict_mode": True,
# Set to true to automatically deploy an ERC20 contract on L1 to be used as the gas token on the rollup.
"zkevm_use_gas_token_contract": False,
# Set to true to use an L1 ERC20 contract as the gas token on the rollup.
# The address of the gas token will be determined by the value of `gas_token_address`.
"gas_token_enabled": False,
# The address of the L1 ERC20 contract that will be used as the gas token on the rollup.
# If the address is empty, a contract will be deployed automatically.
"gas_token_address": "",
leovct marked this conversation as resolved.
Show resolved Hide resolved
# Set to true to use Kurtosis dynamic ports (default) and set to false to use static ports.
# You can either use the default static ports defined in this file or specify your custom static
# ports.
Expand Down
28 changes: 20 additions & 8 deletions templates/contract-deploy/run-contract-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ echo_ts "Waiting for the L1 RPC to be available"
wait_for_rpc_to_be_available "{{.l1_rpc_url}}"
echo_ts "L1 RPC is now available"

echo_ts "Funding important accounts on l1"
echo_ts "Funding important accounts on L1"
fund_account_on_l1 "admin" "{{.zkevm_l2_admin_address}}"
fund_account_on_l1 "sequencer" "{{.zkevm_l2_sequencer_address}}"
fund_account_on_l1 "aggregator" "{{.zkevm_l2_aggregator_address}}"
Expand All @@ -107,26 +107,38 @@ fund_account_on_l1 "l1testing" "{{.zkevm_l2_l1testing_address}}"

echo_ts "Setting up local zkevm-contracts repo for deployment"
pushd /opt/zkevm-contracts || exit 1
# setup a foundry toml in case we do a gas token or dac deployment
printf "[profile.default]\nsrc = 'contracts'\nout = 'out'\nlibs = ['node_modules']\n" > foundry.toml

cp /opt/contract-deploy/deploy_parameters.json /opt/zkevm-contracts/deployment/v2/deploy_parameters.json
cp /opt/contract-deploy/create_rollup_parameters.json /opt/zkevm-contracts/deployment/v2/create_rollup_parameters.json
sed -i 's#http://127.0.0.1:8545#{{.l1_rpc_url}}#' hardhat.config.ts

# Deploy gas token
# TODO in the future this should be configurable. I.e. we should be able to specify a token address that has already been deployed
# {{if .zkevm_use_gas_token_contract}}
# {{if .gas_token_enabled}}

# {{if eq .gas_token_address ""}}
echo_ts "Deploying gas token to L1"
printf "[profile.default]\nsrc = 'contracts'\nout = 'out'\nlibs = ['node_modules']\n" > foundry.toml
leovct marked this conversation as resolved.
Show resolved Hide resolved
forge create \
--json \
--rpc-url "{{.l1_rpc_url}}" \
--mnemonic "{{.l1_preallocated_mnemonic}}" \
contracts/mocks/ERC20PermitMock.sol:ERC20PermitMock \
--constructor-args "CDK Gas Token" "CDK" "{{.zkevm_l2_admin_address}}" "1000000000000000000000000" > gasToken-erc20.json
--constructor-args "CDK Gas Token" "CDK" "{{.zkevm_l2_admin_address}}" "1000000000000000000000000" \
> gasToken-erc20.json
jq \
--slurpfile c gasToken-erc20.json \
'.gasTokenAddress = $c[0].deployedTo' \
/opt/contract-deploy/create_rollup_parameters.json \
> /opt/zkevm-contracts/deployment/v2/create_rollup_parameters.json
# {{else}}
echo_ts "Using L1 pre-deployed gas token: {{ .gas_token_address }}"
jq \
--arg c "{{ .gas_token_address }}" \
'.gasTokenAddress = $c' \
/opt/contract-deploy/create_rollup_parameters.json \
> /opt/zkevm-contracts/deployment/v2/create_rollup_parameters.json
# {{end}}

# In this case, we'll configure the create rollup parameters to have a gas token
jq --slurpfile c gasToken-erc20.json '.gasTokenAddress = $c[0].deployedTo' /opt/contract-deploy/create_rollup_parameters.json > /opt/zkevm-contracts/deployment/v2/create_rollup_parameters.json
# {{end}}

is_first_rollup=0 # an indicator if this deployment is doing the first setup of the agglayer etc
Expand Down
Loading