From ffa80f93f4945e2ea002162a86952f44ed65fde6 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 16 Oct 2024 12:45:13 -0400 Subject: [PATCH 01/35] fund l2 accounts --- deploy_l2_contracts.star | 61 +++++++++++++++++++ input_parser.star | 18 +++++- main.star | 8 +++ .../contract-deploy/run-l2-contract-setup.sh | 61 +++++++++++++++++++ 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 deploy_l2_contracts.star create mode 100644 templates/contract-deploy/run-l2-contract-setup.sh diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star new file mode 100644 index 00000000..d471859b --- /dev/null +++ b/deploy_l2_contracts.star @@ -0,0 +1,61 @@ +service_package = import_module("./lib/service.star") + +ARTIFACTS = [ + { + "name": "run-l2-contract-setup.sh", + "file": "./templates/contract-deploy/run-l2-contract-setup.sh", + }, +] + + +def run(plan, args): + artifact_paths = list(ARTIFACTS) + + l2_rpc_service = plan.get_service(name="cdk-erigon-sequencer" + args["deployment_suffix"]) + l2_rpc_url="http://{}:{}".format(l2_rpc_service.ip_address, l2_rpc_service.ports["rpc"].number) + + artifacts = [] + for artifact_cfg in artifact_paths: + template = read_file(src=artifact_cfg["file"]) + artifact = plan.render_templates( + name=artifact_cfg["name"], + config={ + artifact_cfg["name"]: struct( + template=template, + data=args | {"l2_rpc_url": l2_rpc_url}, + ) + }, + ) + artifacts.append(artifact) + + # Create helper service to deploy contracts + contracts_service_name = "contracts-l2" + args["deployment_suffix"] + plan.add_service( + name=contracts_service_name, + config=ServiceConfig( + image=args["zkevm_contracts_image"], + files={ + "/opt/zkevm": Directory(persistent_key="zkevm-l2-artifacts"), + "/opt/contract-deploy/": Directory(artifact_names=artifacts), + }, + # These two lines are only necessary to deploy to any Kubernetes environment (e.g. GKE). + entrypoint=["bash", "-c"], + cmd=["sleep infinity"], + user=User(uid=0, gid=0), # Run the container as root user. + ), + ) + + # Deploy contracts. + plan.exec( + description="Deploying contracts on L2", + service_name=contracts_service_name, + recipe=ExecRecipe( + command=[ + "/bin/sh", + "-c", + "chmod +x {0} && {0}".format( + "/opt/contract-deploy/run-l2-contract-setup.sh" + ), + ] + ), + ) diff --git a/input_parser.star b/input_parser.star index b86671af..d6fd0bf0 100644 --- a/input_parser.star +++ b/input_parser.star @@ -23,6 +23,8 @@ DEFAULT_DEPLOYMENT_STAGES = { # Deploy cdk-erigon node. # TODO: Remove this parameter to incorporate cdk-erigon inside the central environment. "deploy_cdk_erigon_node": True, + # Deploy contracts on L2 (as well as fund accounts). + "deploy_l2_contracts": True, } DEFAULT_IMAGES = { @@ -33,7 +35,7 @@ DEFAULT_IMAGES = { "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags - "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags + "zkevm_contracts_image": "local/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", # https://hub.docker.com/r/0xpolygon/cdk-data-availability/tags "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", # https://hub.docker.com/r/hermeznetwork/zkevm-node/tags "zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.1", # https://hub.docker.com/r/hermeznetwork/zkevm-pool-manager/tags @@ -61,6 +63,7 @@ DEFAULT_PORTS = { # Addresses and private keys of the different components. # They have been generated using the following command: # polycli wallet inspect --mnemonic 'lab code glass agree maid neutral vessel horror deny frequent favorite soft gate galaxy proof vintage once figure diary virtual scissors marble shrug drop' --addresses 9 | tee keys.txt | jq -r '.Addresses[] | [.ETHAddress, .HexPrivateKey] | @tsv' | awk 'BEGIN{split("sequencer,aggregator,claimtxmanager,timelock,admin,loadtest,agglayer,dac,proofsigner",roles,",")} {print "zkevm_l2_" roles[NR] "_address: \"" $1 "\""; print "zkevm_l2_" roles[NR] "_private_key: \"0x" $2 "\"\n"}' +# polycli wallet inspect --mnemonic 'lab code glass agree maid neutral vessel horror deny frequent favorite soft gate galaxy proof vintage once figure diary virtual scissors marble shrug drop' --addresses 11 | tee keys.txt | jq -r '.Addresses[] | [.ETHAddress, .HexPrivateKey] | @tsv' | awk 'BEGIN{split("sequencer,aggregator,claimtxmanager,timelock,admin,loadtest,agglayer,dac,proofsigner,time_to_mine_sender,time_to_mine_receiver",roles,",")} {print "zkevm_l2_" roles[NR] "_address: \"" $1 "\""; print "zkevm_l2_" roles[NR] "_private_key: \"0x" $2 "\"\n"}' DEFAULT_ACCOUNTS = { # Admin "zkevm_l2_admin_address": "0xE34aaF64b29273B7D567FCFc40544c014EEe9970", @@ -142,6 +145,14 @@ DEFAULT_L1_ARGS = { "l1_funding_amount": "100ether", } +DEFAULT_L2_ARGS = { + # The number of accounts to fund on L2. The accounts will be derived from: + # polycli wallet inspect --mnemonic 'code code code code code code code code code code code quality' + "l2_accounts_to_fund": 10, + # The amount of ETH sent to each of the prefunded l2 accounts. + "l2_funding_amount": "100ether", +} + DEFAULT_ROLLUP_ARGS = { # The keystore password. "zkevm_l2_keystore_password": "pSnv6Dh5s9ahuzGzH9RoCDrKAMddaX3m", @@ -195,7 +206,9 @@ DEFAULT_ARGS = ( # - pless_zkevm_node # - prometheus_grafana # - tx_spammer - "additional_services": [], + "additional_services": [ + "prometheus_grafana", + ], # Only relevant when deploying to an external L1. "polygon_zkevm_explorer": "https://explorer.private/", "l1_explorer_url": "https://sepolia.etherscan.io/", @@ -206,6 +219,7 @@ DEFAULT_ARGS = ( | DEFAULT_L1_ARGS | DEFAULT_ROLLUP_ARGS | DEFAULT_PLESS_ZKEVM_NODE_ARGS + | DEFAULT_L2_ARGS ) # A list of fork identifiers currently supported by Kurtosis CDK. diff --git a/main.star b/main.star index a24081fd..aa37f104 100644 --- a/main.star +++ b/main.star @@ -10,6 +10,7 @@ databases_package = "./databases.star" deploy_zkevm_contracts_package = "./deploy_zkevm_contracts.star" ethereum_package = "./ethereum.star" zkevm_pool_manager_package = "./zkevm_pool_manager.star" +deploy_l2_contracts_package = "./deploy_l2_contracts.star" # Additional service packages. arpeggio_package = "./src/additional_services/arpeggio.star" @@ -125,6 +126,13 @@ def run(plan, args={}): else: plan.print("Skipping the deployment of the agglayer") + # Deploy contracts on L2. + if deployment_stages.get("deploy_l2_contracts", False): + plan.print("Deploying contracts on L2") + import_module(deploy_l2_contracts_package).run(plan, args) + else: + plan.print("Skipping the deployment of contracts on L2") + # Launching additional services. additional_services = args["additional_services"] diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh new file mode 100644 index 00000000..16016618 --- /dev/null +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +global_log_level="{{.global_log_level}}" +if [[ $global_log_level == "debug" ]]; then + set -x +fi + +echo_ts() { + local green="\e[32m" + local end_color="\e[0m" + local timestamp=$(date +"[%Y-%m-%d %H:%M:%S]") + + echo -e "$green$timestamp$end_color $1" >&2 +} + +wait_for_rpc_to_be_available() { + local counter=0 + local max_retries=20 + local retry_interval=5 + + until cast send --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + --value 0 "{{.zkevm_l2_sequencer_address}}" &> /dev/null; do + ((counter++)) + echo_ts "Can't send L2 transfers yet... Retrying ($counter)..." + if [[ $counter -ge $max_retries ]]; then + echo_ts "Exceeded maximum retry attempts. Exiting." + exit 1 + fi + sleep $retry_interval + done +} + +if [[ -e "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" ]]; then + echo_ts "This script has already been executed" + exit 1 +fi + +echo_ts "Waiting for the L2 RPC to be available" +wait_for_rpc_to_be_available +echo_ts "L2 RPC is now available" + +echo_ts "Funding accounts on l2" +accounts=$( + polycli wallet inspect \ + --mnemonic 'code code code code code code code code code code code quality' \ + --addresses {{.l2_accounts_to_fund}} +) +echo "$accounts" | jq -r '.Addresses[].ETHAddress' | while read -r address; do + echo_ts "Funding $address" + cast send \ + --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + --value "{{.l2_funding_amount}}" \ + "$address" +done + +# The contract setup is done! +touch "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" From 4c830276cb323f491fff15fd5b96596aa0fac2ab Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 16 Oct 2024 12:46:50 -0400 Subject: [PATCH 02/35] fix lint --- deploy_l2_contracts.star | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index d471859b..00739a8f 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -11,8 +11,12 @@ ARTIFACTS = [ def run(plan, args): artifact_paths = list(ARTIFACTS) - l2_rpc_service = plan.get_service(name="cdk-erigon-sequencer" + args["deployment_suffix"]) - l2_rpc_url="http://{}:{}".format(l2_rpc_service.ip_address, l2_rpc_service.ports["rpc"].number) + l2_rpc_service = plan.get_service( + name="cdk-erigon-sequencer" + args["deployment_suffix"] + ) + l2_rpc_url = "http://{}:{}".format( + l2_rpc_service.ip_address, l2_rpc_service.ports["rpc"].number + ) artifacts = [] for artifact_cfg in artifact_paths: From b18f50967f0e30aef4c093549e90d54c37a25089 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 16 Oct 2024 12:50:24 -0400 Subject: [PATCH 03/35] fix lint --- templates/contract-deploy/run-l2-contract-setup.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 16016618..d415f1f5 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -8,7 +8,8 @@ fi echo_ts() { local green="\e[32m" local end_color="\e[0m" - local timestamp=$(date +"[%Y-%m-%d %H:%M:%S]") + local timestamp + timestamp=$(date + "[%Y-%m-%d %H:%M:%S]") echo -e "$green$timestamp$end_color $1" >&2 } @@ -44,8 +45,8 @@ echo_ts "L2 RPC is now available" echo_ts "Funding accounts on l2" accounts=$( polycli wallet inspect \ - --mnemonic 'code code code code code code code code code code code quality' \ - --addresses {{.l2_accounts_to_fund}} + --mnemonic "code code code code code code code code code code code quality" \ + --addresses "{{.l2_accounts_to_fund}}" ) echo "$accounts" | jq -r '.Addresses[].ETHAddress' | while read -r address; do echo_ts "Funding $address" From 4b1a8104fbf6dfad135a8314ab8a8cc6cdf0065f Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 16 Oct 2024 13:51:38 -0400 Subject: [PATCH 04/35] remove comment --- input_parser.star | 1 - 1 file changed, 1 deletion(-) diff --git a/input_parser.star b/input_parser.star index d6fd0bf0..2fc6fc3d 100644 --- a/input_parser.star +++ b/input_parser.star @@ -63,7 +63,6 @@ DEFAULT_PORTS = { # Addresses and private keys of the different components. # They have been generated using the following command: # polycli wallet inspect --mnemonic 'lab code glass agree maid neutral vessel horror deny frequent favorite soft gate galaxy proof vintage once figure diary virtual scissors marble shrug drop' --addresses 9 | tee keys.txt | jq -r '.Addresses[] | [.ETHAddress, .HexPrivateKey] | @tsv' | awk 'BEGIN{split("sequencer,aggregator,claimtxmanager,timelock,admin,loadtest,agglayer,dac,proofsigner",roles,",")} {print "zkevm_l2_" roles[NR] "_address: \"" $1 "\""; print "zkevm_l2_" roles[NR] "_private_key: \"0x" $2 "\"\n"}' -# polycli wallet inspect --mnemonic 'lab code glass agree maid neutral vessel horror deny frequent favorite soft gate galaxy proof vintage once figure diary virtual scissors marble shrug drop' --addresses 11 | tee keys.txt | jq -r '.Addresses[] | [.ETHAddress, .HexPrivateKey] | @tsv' | awk 'BEGIN{split("sequencer,aggregator,claimtxmanager,timelock,admin,loadtest,agglayer,dac,proofsigner,time_to_mine_sender,time_to_mine_receiver",roles,",")} {print "zkevm_l2_" roles[NR] "_address: \"" $1 "\""; print "zkevm_l2_" roles[NR] "_private_key: \"0x" $2 "\"\n"}' DEFAULT_ACCOUNTS = { # Admin "zkevm_l2_admin_address": "0xE34aaF64b29273B7D567FCFc40544c014EEe9970", From 81e198b7987c0f2679c89152ff669997c65a7077 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 16 Oct 2024 13:52:39 -0400 Subject: [PATCH 05/35] remove additional services --- input_parser.star | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/input_parser.star b/input_parser.star index 2fc6fc3d..a53ec597 100644 --- a/input_parser.star +++ b/input_parser.star @@ -205,9 +205,7 @@ DEFAULT_ARGS = ( # - pless_zkevm_node # - prometheus_grafana # - tx_spammer - "additional_services": [ - "prometheus_grafana", - ], + "additional_services": [], # Only relevant when deploying to an external L1. "polygon_zkevm_explorer": "https://explorer.private/", "l1_explorer_url": "https://sepolia.etherscan.io/", From 112cbef921ddd4154a74f4e3bb0f5c70fb0a189c Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 16 Oct 2024 16:38:08 -0400 Subject: [PATCH 06/35] fix typo --- main.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.star b/main.star index aa37f104..d06c80ea 100644 --- a/main.star +++ b/main.star @@ -80,7 +80,7 @@ def run(plan, args={}): # Deploy cdk central/trusted environment. if deployment_stages.get("deploy_cdk_central_environment", False): # Deploy cdk-erigon sequencer node. - # TODO this is a little weird if the erigon sequencer is deployed before the exector? + # TODO this is a little weird if the erigon sequencer is deployed before the executor? if args["sequencer_type"] == "erigon": plan.print("Deploying cdk-erigon sequencer") import_module(cdk_erigon_package).run_sequencer(plan, args) From 3d234d4c39b7a6d1cb9f5e58dce74f67decafe38 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Thu, 17 Oct 2024 12:15:55 -0400 Subject: [PATCH 07/35] use toolbox for l2 contracts image --- deploy_l2_contracts.star | 2 +- input_parser.star | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 00739a8f..3445d2fa 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -37,7 +37,7 @@ def run(plan, args): plan.add_service( name=contracts_service_name, config=ServiceConfig( - image=args["zkevm_contracts_image"], + image=args["l2_contracts_image"], files={ "/opt/zkevm": Directory(persistent_key="zkevm-l2-artifacts"), "/opt/contract-deploy/": Directory(artifact_names=artifacts), diff --git a/input_parser.star b/input_parser.star index b9897fa3..1da2691f 100644 --- a/input_parser.star +++ b/input_parser.star @@ -32,10 +32,11 @@ DEFAULT_IMAGES = { "cdk_erigon_node_image": "hermeznetwork/cdk-erigon:d930066", # https://hub.docker.com/r/hermeznetwork/cdk-erigon/tags "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.3.0-rc1", # https://github.com/0xpolygon/cdk/pkgs/container/cdk "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", # https://hub.docker.com/r/0xpolygon/cdk-validium-node/tags + "l2_contracts_image": "leovct/toolbox:0.0.5", # https://hub.docker.com/r/leovct/toolbox/tags "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags - "zkevm_contracts_image": "local/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags + "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", # https://hub.docker.com/r/0xpolygon/cdk-data-availability/tags "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", # https://hub.docker.com/r/hermeznetwork/zkevm-node/tags "zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.1", # https://hub.docker.com/r/hermeznetwork/zkevm-pool-manager/tags From 922b3e086d7436849a8c2c0b464a84d78f4c8cbe Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Thu, 17 Oct 2024 13:00:02 -0400 Subject: [PATCH 08/35] update docs --- input_parser.star | 2 +- templates/contract-deploy/run-l2-contract-setup.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/input_parser.star b/input_parser.star index 1da2691f..abc9aee2 100644 --- a/input_parser.star +++ b/input_parser.star @@ -147,7 +147,7 @@ DEFAULT_L1_ARGS = { DEFAULT_L2_ARGS = { # The number of accounts to fund on L2. The accounts will be derived from: - # polycli wallet inspect --mnemonic 'code code code code code code code code code code code quality' + # polycli wallet inspect --mnemonic '{{.l1_preallocated_mnemonic}}' "l2_accounts_to_fund": 10, # The amount of ETH sent to each of the prefunded l2 accounts. "l2_funding_amount": "100ether", diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index d415f1f5..3981ea2a 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -45,7 +45,7 @@ echo_ts "L2 RPC is now available" echo_ts "Funding accounts on l2" accounts=$( polycli wallet inspect \ - --mnemonic "code code code code code code code code code code code quality" \ + --mnemonic "{{.l1_preallocated_mnemonic}}" \ --addresses "{{.l2_accounts_to_fund}}" ) echo "$accounts" | jq -r '.Addresses[].ETHAddress' | while read -r address; do From 12621f7c0bd885d95e08bd2d01f0a1393d59c09d Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Thu, 17 Oct 2024 13:18:22 -0400 Subject: [PATCH 09/35] funded bridge autoclaimer --- .../contract-deploy/run-l2-contract-setup.sh | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 3981ea2a..6db035b1 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -33,6 +33,17 @@ wait_for_rpc_to_be_available() { done } +fund_account_on_l2() { + local address="$1" + echo_ts "Funding $address" + cast send \ + --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + --value "{{.l2_funding_amount}}" \ + "$address" +} + if [[ -e "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" ]]; then echo_ts "This script has already been executed" exit 1 @@ -42,6 +53,9 @@ echo_ts "Waiting for the L2 RPC to be available" wait_for_rpc_to_be_available echo_ts "L2 RPC is now available" +echo_ts "Funding bridge autoclaimer account on l2" +fund_account_on_l2 "{{.zkevm_l2_claimtxmanager_address}}" + echo_ts "Funding accounts on l2" accounts=$( polycli wallet inspect \ @@ -49,13 +63,7 @@ accounts=$( --addresses "{{.l2_accounts_to_fund}}" ) echo "$accounts" | jq -r '.Addresses[].ETHAddress' | while read -r address; do - echo_ts "Funding $address" - cast send \ - --legacy \ - --rpc-url "{{.l2_rpc_url}}" \ - --private-key "{{.zkevm_l2_admin_private_key}}" \ - --value "{{.l2_funding_amount}}" \ - "$address" + fund_account_on_l2 "$address" done # The contract setup is done! From 7a22a0343c1fa13122ef28085e411871957b46a3 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Thu, 17 Oct 2024 13:22:42 -0400 Subject: [PATCH 10/35] fix typo --- input_parser.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input_parser.star b/input_parser.star index abc9aee2..154aa893 100644 --- a/input_parser.star +++ b/input_parser.star @@ -126,7 +126,7 @@ DEFAULT_L1_ARGS = { # - blutgang # - forky # - apache - # - tracoor + # - tracoor # Check the ethereum-package for more details: https://github.com/ethpandaops/ethereum-package "l1_additional_services": [], # Preset for the network. From 1f228c2bc9f524d5ccabb4b5a13e0bae34f90ddd Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 21 Oct 2024 00:24:21 -0400 Subject: [PATCH 11/35] remove extra space --- docker/zkevm-contracts.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/zkevm-contracts.Dockerfile b/docker/zkevm-contracts.Dockerfile index 28b95fbe..e6f51f2c 100644 --- a/docker/zkevm-contracts.Dockerfile +++ b/docker/zkevm-contracts.Dockerfile @@ -12,7 +12,7 @@ LABEL description="Helper image to deploy zkevm contracts" # STEP 1: Download zkevm contracts dependencies and compile contracts. ARG ZKEVM_CONTRACTS_BRANCH WORKDIR /opt/zkevm-contracts -RUN git clone https://github.com/0xPolygonHermez/zkevm-contracts . \ +RUN git clone https://github.com/0xPolygonHermez/zkevm-contracts . \ && git checkout ${ZKEVM_CONTRACTS_BRANCH} \ && npm install --global npm@10.9.0 \ && npm install \ From 6f569b2010c21761a40a512a579a368b84c3a34f Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 21 Oct 2024 11:48:07 -0400 Subject: [PATCH 12/35] update dockerfiles --- docker/toolbox.Dockerfile | 4 ++-- docker/zkevm-contracts.Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/toolbox.Dockerfile b/docker/toolbox.Dockerfile index 26fea5e8..4790ecd8 100644 --- a/docker/toolbox.Dockerfile +++ b/docker/toolbox.Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 AS polycli-builder +FROM golang:1.22 AS polycli-builder ARG POLYCLI_VERSION WORKDIR /opt/polygon-cli RUN git clone --branch ${POLYCLI_VERSION} https://github.com/maticnetwork/polygon-cli.git . \ @@ -17,7 +17,7 @@ COPY --from=polycli-builder /opt/polygon-cli/bindings /opt/bindings # WARNING (SC1091): (Sourced) file not included in mock. # hadolint ignore=DL3008,DL3013,DL4006,SC1091 RUN apt-get update \ - && apt-get install --yes --no-install-recommends curl git jq pipx \ + && apt-get install --yes --no-install-recommends curl git jq pipx nodejs \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && pipx ensurepath \ diff --git a/docker/zkevm-contracts.Dockerfile b/docker/zkevm-contracts.Dockerfile index 47df80dd..e26d1bf3 100644 --- a/docker/zkevm-contracts.Dockerfile +++ b/docker/zkevm-contracts.Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 AS polycli-builder +FROM golang:1.22 AS polycli-builder ARG POLYCLI_VERSION WORKDIR /opt/polygon-cli RUN git clone --branch ${POLYCLI_VERSION} https://github.com/maticnetwork/polygon-cli.git . \ From 6c65c52f3f5f543ff4d5584a7afd6515b1b52a31 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 21 Oct 2024 13:02:57 -0400 Subject: [PATCH 13/35] update network helper --- docs/trigger-a-reorg/network-helper.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/trigger-a-reorg/network-helper.Dockerfile b/docs/trigger-a-reorg/network-helper.Dockerfile index 0a5c3324..8f17df46 100644 --- a/docs/trigger-a-reorg/network-helper.Dockerfile +++ b/docs/trigger-a-reorg/network-helper.Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 AS polycli-builder +FROM golang:1.22 AS polycli-builder WORKDIR /opt/polygon-cli RUN git clone https://github.com/maticnetwork/polygon-cli.git . \ && make build From ae8f5ab04ca99d44e0d4083cad496d78e433e9d0 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 21 Oct 2024 20:05:17 -0400 Subject: [PATCH 14/35] add ddp branch --- deploy_l2_contracts.star | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 3445d2fa..d993fb3d 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -26,7 +26,11 @@ def run(plan, args): config={ artifact_cfg["name"]: struct( template=template, - data=args | {"l2_rpc_url": l2_rpc_url}, + data=args + | { + "l2_rpc_url": l2_rpc_url, + "deterministic_deployment_proxy_branch": "master", + }, ) }, ) From a841ff9b2c6fc1cbca3246923e2d710203b6942d Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 21 Oct 2024 20:05:34 -0400 Subject: [PATCH 15/35] deploy ddp --- .../contract-deploy/run-l2-contract-setup.sh | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 6db035b1..54bfcc3f 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -9,7 +9,7 @@ echo_ts() { local green="\e[32m" local end_color="\e[0m" local timestamp - timestamp=$(date + "[%Y-%m-%d %H:%M:%S]") + timestamp=$(date +"[%Y-%m-%d %H:%M:%S]") echo -e "$green$timestamp$end_color $1" >&2 } @@ -66,5 +66,84 @@ echo "$accounts" | jq -r '.Addresses[].ETHAddress' | while read -r address; do fund_account_on_l2 "$address" done +echo_ts "Building deterministic deployment proxy" +git clone https://github.com/Arachnid/deterministic-deployment-proxy.git \ + /opt/deterministic-deployment-proxy \ + --branch "{{.deterministic_deployment_proxy_branch}}" +cd /opt/deterministic-deployment-proxy +npm ci +npm run build + +signer_address="0x$(cat output/deployment.json | jq --raw-output '.signerAddress')" +gas_price=$(cat output/deployment.json | jq --raw-output '.gasPrice') +gas_limit=$(cat output/deployment.json | jq --raw-output '.gasLimit') +gas_cost=$((gas_price * gas_limit)) +transaction="0x$(cat output/deployment.json | jq --raw-output '.transaction')" +bytecode=$(cat output/bytecode.txt) +deployer_address="0x$(cat output/deployment.json | jq --raw-output '.address')" +contract_method_signature="0xc3cafc6f" +expected="0x000000000000000000000000000000000000000000000000000000000000002a" + +echo_ts "Deploying deterministic deployment proxy on l2" +cast send \ + --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + --value "$gas_cost" \ + "$signer_address" +cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction" + +echo_ts "Deploying deterministic deployment proxy on l1" +cast send \ + --rpc-url "{{.l1_rpc_url}}" \ + --mnemonic "{{.l1_preallocated_mnemonic}}" \ + --value "$gas_cost" \ + "$signer_address" +cast publish --rpc-url "{{.l1_rpc_url}}" "$transaction" + +echo_ts "Testing deterministic deployment proxy on l2" +cast send \ + --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + --create "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" \ + "$deployer_address" +l2_contract_address=$( + cast call \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + "$deployer_address" \ + "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" +) +l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$l2_contract_address" "$contract_method_signature") +if [ "$expected" != "$l2_actual" ]; then + echo "Failed to deploy deterministic deployment proxy on l2" + exit 1 +fi + +echo_ts "Testing deterministic deployment proxy on l1" +cast send \ + --rpc-url "{{.l1_rpc_url}}" \ + --mnemonic "{{.l1_preallocated_mnemonic}}" \ + --create "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" \ + "$deployer_address" +l1_contract_address=$( + cast call \ + --rpc-url "{{.l1_rpc_url}}" \ + --mnemonic "{{.l1_preallocated_mnemonic}}" \ + "$deployer_address" \ + "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" +) +l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$l1_contract_address" "$contract_method_signature") +if [ "$expected" != "$l1_actual" ]; then + echo "Failed to deploy deterministic deployment proxy on l1" + exit 1 +fi + +if [ "$l1_contract_address" != "$l2_contract_address" ]; then + echo "Mismatch contract addresses deployed by deterministic deployment proxy" + exit 1 +fi + # The contract setup is done! touch "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" From bc4ea5874d90dbfcde6d50020170ac7b42b4c8f9 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Mon, 21 Oct 2024 20:05:41 -0400 Subject: [PATCH 16/35] add node to toolbox --- docker/toolbox.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/toolbox.Dockerfile b/docker/toolbox.Dockerfile index 4790ecd8..aeec1e2c 100644 --- a/docker/toolbox.Dockerfile +++ b/docker/toolbox.Dockerfile @@ -17,7 +17,7 @@ COPY --from=polycli-builder /opt/polygon-cli/bindings /opt/bindings # WARNING (SC1091): (Sourced) file not included in mock. # hadolint ignore=DL3008,DL3013,DL4006,SC1091 RUN apt-get update \ - && apt-get install --yes --no-install-recommends curl git jq pipx nodejs \ + && apt-get install --yes --no-install-recommends curl git jq pipx nodejs npm \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && pipx ensurepath \ From 9e1b0ff92e06e5285f0f6fcb472dabba4e8698ff Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:07:21 -0400 Subject: [PATCH 17/35] fix ddp deployment --- .../contract-deploy/run-l2-contract-setup.sh | 82 +++++++++---------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 54bfcc3f..9bbd24a2 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -62,7 +62,7 @@ accounts=$( --mnemonic "{{.l1_preallocated_mnemonic}}" \ --addresses "{{.l2_accounts_to_fund}}" ) -echo "$accounts" | jq -r '.Addresses[].ETHAddress' | while read -r address; do +echo "$accounts" | jq -r ".Addresses[].ETHAddress" | while read -r address; do fund_account_on_l2 "$address" done @@ -79,70 +79,62 @@ gas_price=$(cat output/deployment.json | jq --raw-output '.gasPrice') gas_limit=$(cat output/deployment.json | jq --raw-output '.gasLimit') gas_cost=$((gas_price * gas_limit)) transaction="0x$(cat output/deployment.json | jq --raw-output '.transaction')" -bytecode=$(cat output/bytecode.txt) deployer_address="0x$(cat output/deployment.json | jq --raw-output '.address')" -contract_method_signature="0xc3cafc6f" -expected="0x000000000000000000000000000000000000000000000000000000000000002a" - -echo_ts "Deploying deterministic deployment proxy on l2" -cast send \ - --legacy \ - --rpc-url "{{.l2_rpc_url}}" \ - --private-key "{{.zkevm_l2_admin_private_key}}" \ - --value "$gas_cost" \ - "$signer_address" -cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction" +l1_private_key=$( + polycli wallet inspect \ + --mnemonic "{{.l1_preallocated_mnemonic}}" \ + --addresses 1 \ + | jq -r ".Addresses[].HexPrivateKey" +) echo_ts "Deploying deterministic deployment proxy on l1" cast send \ --rpc-url "{{.l1_rpc_url}}" \ - --mnemonic "{{.l1_preallocated_mnemonic}}" \ + --private-key "$l1_private_key" \ --value "$gas_cost" \ "$signer_address" cast publish --rpc-url "{{.l1_rpc_url}}" "$transaction" -echo_ts "Testing deterministic deployment proxy on l2" +echo_ts "Deploying deterministic deployment proxy on l2" cast send \ --legacy \ --rpc-url "{{.l2_rpc_url}}" \ --private-key "{{.zkevm_l2_admin_private_key}}" \ - --create "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" \ - "$deployer_address" -l2_contract_address=$( - cast call \ - --rpc-url "{{.l2_rpc_url}}" \ - --private-key "{{.zkevm_l2_admin_private_key}}" \ - "$deployer_address" \ - "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" -) -l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$l2_contract_address" "$contract_method_signature") -if [ "$expected" != "$l2_actual" ]; then - echo "Failed to deploy deterministic deployment proxy on l2" - exit 1 -fi + --value "$gas_cost" \ + "$signer_address" +cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction" + +contract_method_signature="banana()(uint8)" +expected="42" +salt="0x0000000000000000000000000000000000000000000000000000000000000000" +# contract: pragma solidity 0.5.8; contract Apple {function banana() external pure returns (uint8) {return 42;}} +bytecode="6080604052348015600f57600080fd5b5060848061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c3cafc6f14602d575b600080fd5b6033604f565b604051808260ff1660ff16815260200191505060405180910390f35b6000602a90509056fea165627a7a72305820ab7651cb86b8c1487590004c2444f26ae30077a6b96c6bc62dda37f1328539250029" +contract_address=$(cast create2 --salt $salt --init-code $bytecode) echo_ts "Testing deterministic deployment proxy on l1" cast send \ + --legacy \ --rpc-url "{{.l1_rpc_url}}" \ - --mnemonic "{{.l1_preallocated_mnemonic}}" \ - --create "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" \ - "$deployer_address" -l1_contract_address=$( - cast call \ - --rpc-url "{{.l1_rpc_url}}" \ - --mnemonic "{{.l1_preallocated_mnemonic}}" \ - "$deployer_address" \ - "0x0000000000000000000000000000000000000000000000000000000000000000$bytecode" -) -l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$l1_contract_address" "$contract_method_signature") + --private-key "$l1_private_key" \ + "$deployer_address" \ + "$salt$bytecode" +l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$contract_address" "$contract_method_signature") if [ "$expected" != "$l1_actual" ]; then - echo "Failed to deploy deterministic deployment proxy on l1" - exit 1 + echo_ts "Failed to deploy deterministic deployment proxy on l1 (expected: $expected, actual $l1_actual)" + exit 1 fi -if [ "$l1_contract_address" != "$l2_contract_address" ]; then - echo "Mismatch contract addresses deployed by deterministic deployment proxy" - exit 1 +echo_ts "Testing deterministic deployment proxy on l2" +cast send \ + --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + "$deployer_address" \ + "$salt$bytecode" +l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$contract_address" "$contract_method_signature") +if [ "$expected" != "$l2_actual" ]; then + echo_ts "Failed to deploy deterministic deployment proxy on l2 (expected: $expected, actual $l2_actual)" + exit 1 fi # The contract setup is done! From 2bd3e668cad7728d6e725c33681ad6e0cb76ae11 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:24:12 -0400 Subject: [PATCH 18/35] try using ci --- deploy_l2_contracts.star | 11 ++--------- input_parser.star | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index d993fb3d..7147f7c6 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -9,17 +9,10 @@ ARTIFACTS = [ def run(plan, args): - artifact_paths = list(ARTIFACTS) - - l2_rpc_service = plan.get_service( - name="cdk-erigon-sequencer" + args["deployment_suffix"] - ) - l2_rpc_url = "http://{}:{}".format( - l2_rpc_service.ip_address, l2_rpc_service.ports["rpc"].number - ) + l2_rpc_url = service_package.get_l2_rpc_url(plan, args) artifacts = [] - for artifact_cfg in artifact_paths: + for artifact_cfg in list(ARTIFACTS): template = read_file(src=artifact_cfg["file"]) artifact = plan.render_templates( name=artifact_cfg["name"], diff --git a/input_parser.star b/input_parser.star index 4b9a027b..ba22bc4f 100644 --- a/input_parser.star +++ b/input_parser.star @@ -32,7 +32,7 @@ DEFAULT_IMAGES = { "cdk_erigon_node_image": "hermeznetwork/cdk-erigon:v2.1.0", # https://hub.docker.com/r/hermeznetwork/cdk-erigon/tags "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.3.0", # https://github.com/0xpolygon/cdk/pkgs/container/cdk "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", # https://hub.docker.com/r/0xpolygon/cdk-validium-node/tags - "l2_contracts_image": "leovct/toolbox:0.0.5", # https://hub.docker.com/r/leovct/toolbox/tags + "l2_contracts_image": "minhdvu/toolbox:0.0.7", # https://hub.docker.com/r/leovct/toolbox/tags "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags From 240bf5a58cdb586e9d2380428c6f7c1fb638f7c3 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:27:00 -0400 Subject: [PATCH 19/35] sort --- docker/toolbox.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/toolbox.Dockerfile b/docker/toolbox.Dockerfile index aeec1e2c..e44a09bb 100644 --- a/docker/toolbox.Dockerfile +++ b/docker/toolbox.Dockerfile @@ -17,7 +17,7 @@ COPY --from=polycli-builder /opt/polygon-cli/bindings /opt/bindings # WARNING (SC1091): (Sourced) file not included in mock. # hadolint ignore=DL3008,DL3013,DL4006,SC1091 RUN apt-get update \ - && apt-get install --yes --no-install-recommends curl git jq pipx nodejs npm \ + && apt-get install --yes --no-install-recommends curl git jq nodejs npm pipx \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && pipx ensurepath \ From cde2d8fda01a9a94b40393352ba21b089f65bf26 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:33:17 -0400 Subject: [PATCH 20/35] fix external l1 ci --- .github/tests/external-l1/deploy-local-l1.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/tests/external-l1/deploy-local-l1.yml b/.github/tests/external-l1/deploy-local-l1.yml index 50be6cd1..b81e14c6 100644 --- a/.github/tests/external-l1/deploy-local-l1.yml +++ b/.github/tests/external-l1/deploy-local-l1.yml @@ -6,3 +6,4 @@ deployment_stages: deploy_cdk_bridge_infra: false deploy_agglayer: false deploy_cdk_erigon_node: false + deploy_l2_contracts: false From b8a9a02e9f54592122639e09ca125acd3040da03 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:41:09 -0400 Subject: [PATCH 21/35] fix: shell lint --- templates/contract-deploy/run-l2-contract-setup.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 9bbd24a2..0338135c 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -74,12 +74,12 @@ cd /opt/deterministic-deployment-proxy npm ci npm run build -signer_address="0x$(cat output/deployment.json | jq --raw-output '.signerAddress')" -gas_price=$(cat output/deployment.json | jq --raw-output '.gasPrice') -gas_limit=$(cat output/deployment.json | jq --raw-output '.gasLimit') +signer_address="0x$(jq -r '.signerAddress' output/deployment.json)" +gas_price=$(jq -r '.gasPrice' output/deployment.json) +gas_limit=$(jq -r '.gasLimit' output/deployment.json) gas_cost=$((gas_price * gas_limit)) -transaction="0x$(cat output/deployment.json | jq --raw-output '.transaction')" -deployer_address="0x$(cat output/deployment.json | jq --raw-output '.address')" +transaction="0x$(jq -r '.transaction' output/deployment.json)" +deployer_address="0x$(jq -r '.address' output/deployment.json)" l1_private_key=$( polycli wallet inspect \ --mnemonic "{{.l1_preallocated_mnemonic}}" \ From e15c2f025011b8acf6904b1d8c18c562a16fa6a0 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:44:43 -0400 Subject: [PATCH 22/35] fix: shell lint --- templates/contract-deploy/run-l2-contract-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 0338135c..06910933 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -70,7 +70,7 @@ echo_ts "Building deterministic deployment proxy" git clone https://github.com/Arachnid/deterministic-deployment-proxy.git \ /opt/deterministic-deployment-proxy \ --branch "{{.deterministic_deployment_proxy_branch}}" -cd /opt/deterministic-deployment-proxy +cd /opt/deterministic-deployment-proxy || exit 1 npm ci npm run build From c7a30a6c8406a58751efd29da0981b898259f37a Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Wed, 23 Oct 2024 03:58:06 -0400 Subject: [PATCH 23/35] maybe fix --- deploy_l2_contracts.star | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 7147f7c6..a36689e1 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -11,8 +11,9 @@ ARTIFACTS = [ def run(plan, args): l2_rpc_url = service_package.get_l2_rpc_url(plan, args) + artifact_paths = list(ARTIFACTS) artifacts = [] - for artifact_cfg in list(ARTIFACTS): + for artifact_cfg in artifact_paths: template = read_file(src=artifact_cfg["file"]) artifact = plan.render_templates( name=artifact_cfg["name"], From cfc82c11c604d0edb49f6c235f7b52eab668e34b Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Thu, 24 Oct 2024 13:45:02 -0400 Subject: [PATCH 24/35] fix: l2_rpc_url --- deploy_l2_contracts.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index a36689e1..40180eb1 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -22,7 +22,7 @@ def run(plan, args): template=template, data=args | { - "l2_rpc_url": l2_rpc_url, + "l2_rpc_url": l2_rpc_url.http, "deterministic_deployment_proxy_branch": "master", }, ) From 7b14837cde0c1943dab00b111b2cb094058df2cc Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Thu, 24 Oct 2024 23:51:47 -0400 Subject: [PATCH 25/35] chore: shell if style --- templates/contract-deploy/run-l2-contract-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 06910933..54c84368 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -119,7 +119,7 @@ cast send \ "$deployer_address" \ "$salt$bytecode" l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$contract_address" "$contract_method_signature") -if [ "$expected" != "$l1_actual" ]; then +if [[ "$expected" != "$l1_actual" ]]; then echo_ts "Failed to deploy deterministic deployment proxy on l1 (expected: $expected, actual $l1_actual)" exit 1 fi From b09f443ef61666aa620db9712d70162c8d2dcd9f Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 03:22:50 -0400 Subject: [PATCH 26/35] address comments --- README.md | 20 ++++++++++--------- docker/toolbox.Dockerfile | 2 +- input_parser.star | 2 +- .../contract-deploy/run-l2-contract-setup.sh | 20 +++++-------------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index e88033b2..5f8b411f 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,14 @@ The package is flexible and supports various configurations for deploying and te > The team is actively working on enabling the use cases that are currently not possible. -| Stack | Sequencer | Sequence Sender / Aggregator | Supported by Kurtosis? | -| ----- | --------- | ---------------------------- | ---------------------- | -| New CDK stack | [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) | [cdk-node](https://github.com/0xPolygon/cdk) | ✅ | -| New sequencer with new zkevm stack | [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) | [zkevm-sequence-sender](https://github.com/0xPolygonHermez/zkevm-sequence-sender) + [zkevm-aggregator](https://github.com/0xPolygonHermez/zkevm-aggregator) | ❌ (WIP) - Check the [kurtosis-cdk-erigon](https://github.com/xavier-romero/kurtosis-cdk-erigon) package | -| New sequencer with legacy zkevm stack | [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | ❌ (WIP) | -| Legacy sequencer with new cdk stack | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | [cdk-node](https://github.com/0xPolygon/cdk) | ❌ (WIP) | -| Legacy sequencer with new zkevm stack | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | [zkevm-sequence-sender](https://github.com/0xPolygonHermez/zkevm-sequence-sender) + [zkevm-aggregator](https://github.com/0xPolygonHermez/zkevm-aggregator) | ❌ (WIP) | -| Legacy zkevm stack | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | ✅ | +| Stack | Sequencer | Sequence Sender / Aggregator | Supported by Kurtosis? | +| ------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| New CDK stack | [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) | [cdk-node](https://github.com/0xPolygon/cdk) | ✅ | +| New sequencer with new zkevm stack | [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) | [zkevm-sequence-sender](https://github.com/0xPolygonHermez/zkevm-sequence-sender) + [zkevm-aggregator](https://github.com/0xPolygonHermez/zkevm-aggregator) | ❌ (WIP) - Check the [kurtosis-cdk-erigon](https://github.com/xavier-romero/kurtosis-cdk-erigon) package | +| New sequencer with legacy zkevm stack | [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | ❌ (WIP) | +| Legacy sequencer with new cdk stack | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | [cdk-node](https://github.com/0xPolygon/cdk) | ❌ (WIP) | +| Legacy sequencer with new zkevm stack | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | [zkevm-sequence-sender](https://github.com/0xPolygonHermez/zkevm-sequence-sender) + [zkevm-aggregator](https://github.com/0xPolygonHermez/zkevm-aggregator) | ❌ (WIP) | +| Legacy zkevm stack | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | [zkevm-node](https://github.com/0xPolygonHermez/zkevm-node) | ✅ | To understand how to configure Kurtosis for these use cases, refer to the [documentation](.github/tests/README.md) and review the test files located in the `.github/tests/` directory. @@ -44,6 +44,8 @@ To understand how to configure Kurtosis for these use cases, refer to the [docum To begin, you will need to install [Docker](https://docs.docker.com/get-docker/) (>= [v4.27.0](https://docs.docker.com/desktop/release-notes/#4270) for Mac users) and [Kurtosis](https://docs.kurtosis.com/install/). +- If you notice some services, such as the `zkevm-stateless-executor` or `zkevm-prover`, consistently having the status of `STOPPED`, try increasing the Docker memory allocation. + If you intend to interact with and debug the stack, you may also want to consider a few additional optional tools such as: - [jq](https://github.com/jqlang/jq) @@ -59,7 +61,7 @@ Once that is good and installed on your system, you can run the following comman kurtosis run --enclave cdk github.com/0xPolygon/kurtosis-cdk ``` -The default deployment includes [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) as the sequencer, and [cdk-node](https://github.com/0xPolygon/cdk) functioning as the sequence sender and aggregator. You can verify the default versions of these components and the default fork ID by reviewing input_parser.star. You can check the default versions of the deployed components and the default fork ID by looking at +The default deployment includes [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) as the sequencer, and [cdk-node](https://github.com/0xPolygon/cdk) functioning as the sequence sender and aggregator. You can verify the default versions of these components and the default fork ID by reviewing input_parser.star. You can check the default versions of the deployed components and the default fork ID by looking at [input_parser.star](./input_parser.star). To make customizations to the CDK environment, clone this repo, make any desired configuration changes, and then run: diff --git a/docker/toolbox.Dockerfile b/docker/toolbox.Dockerfile index e44a09bb..664acdf7 100644 --- a/docker/toolbox.Dockerfile +++ b/docker/toolbox.Dockerfile @@ -17,7 +17,7 @@ COPY --from=polycli-builder /opt/polygon-cli/bindings /opt/bindings # WARNING (SC1091): (Sourced) file not included in mock. # hadolint ignore=DL3008,DL3013,DL4006,SC1091 RUN apt-get update \ - && apt-get install --yes --no-install-recommends curl git jq nodejs npm pipx \ + && apt-get install --yes --no-install-recommends curl git jq pipx \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && pipx ensurepath \ diff --git a/input_parser.star b/input_parser.star index 3ea161f0..20c553c0 100644 --- a/input_parser.star +++ b/input_parser.star @@ -32,7 +32,7 @@ DEFAULT_IMAGES = { "cdk_erigon_node_image": "hermeznetwork/cdk-erigon:v2.1.0", # https://hub.docker.com/r/hermeznetwork/cdk-erigon/tags "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.3.0", # https://github.com/0xpolygon/cdk/pkgs/container/cdk "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", # https://hub.docker.com/r/0xpolygon/cdk-validium-node/tags - "l2_contracts_image": "minhdvu/toolbox:0.0.7", # https://hub.docker.com/r/leovct/toolbox/tags + "l2_contracts_image": "leovct/toolbox:0.0.6", # https://hub.docker.com/r/leovct/toolbox/tags "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 54c84368..64e97be9 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -66,20 +66,10 @@ echo "$accounts" | jq -r ".Addresses[].ETHAddress" | while read -r address; do fund_account_on_l2 "$address" done -echo_ts "Building deterministic deployment proxy" -git clone https://github.com/Arachnid/deterministic-deployment-proxy.git \ - /opt/deterministic-deployment-proxy \ - --branch "{{.deterministic_deployment_proxy_branch}}" -cd /opt/deterministic-deployment-proxy || exit 1 -npm ci -npm run build - -signer_address="0x$(jq -r '.signerAddress' output/deployment.json)" -gas_price=$(jq -r '.gasPrice' output/deployment.json) -gas_limit=$(jq -r '.gasLimit' output/deployment.json) -gas_cost=$((gas_price * gas_limit)) -transaction="0x$(jq -r '.transaction' output/deployment.json)" -deployer_address="0x$(jq -r '.address' output/deployment.json)" +signer_address="0x3fab184622dc19b6109349b94811493bf2a45362" +gas_cost="0.01ether" +transaction="0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222" +deployer_address="0x4e59b44847b379578588920ca78fbf26c0b4956c" l1_private_key=$( polycli wallet inspect \ --mnemonic "{{.l1_preallocated_mnemonic}}" \ @@ -132,7 +122,7 @@ cast send \ "$deployer_address" \ "$salt$bytecode" l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$contract_address" "$contract_method_signature") -if [ "$expected" != "$l2_actual" ]; then +if [[ "$expected" != "$l2_actual" ]]; then echo_ts "Failed to deploy deterministic deployment proxy on l2 (expected: $expected, actual $l2_actual)" exit 1 fi From 089e54a8943e2e376dbc88c12aab90415287e824 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 04:34:11 -0400 Subject: [PATCH 27/35] update docs --- README.md | 1 + docs/deterministic-deployment-proxy.md | 113 ++++++++++++++++++ .../contract-deploy/run-l2-contract-setup.sh | 46 ++----- 3 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 docs/deterministic-deployment-proxy.md diff --git a/README.md b/README.md index 5f8b411f..027eb588 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ This section features documentation specifically designed for advanced users, ou - How to [run a debugger](docs/running-a-debugger/running-a-debugger.org). - How to work with the [timelock](docs/timelock.org). - How to [trigger a reorg](docs/trigger-a-reorg/trigger-a-reorg.md). +- How to [deploy contracts with the deterministic deployment proxy](docs/deterministic-deployment-proxy.md). ## Contact diff --git a/docs/deterministic-deployment-proxy.md b/docs/deterministic-deployment-proxy.md new file mode 100644 index 00000000..203d02a0 --- /dev/null +++ b/docs/deterministic-deployment-proxy.md @@ -0,0 +1,113 @@ +# Deploy Contracts with the Deterministic Deployment Proxy + +A guide to deploy contracts using the [deterministic deployment proxy](https://github.com/Arachnid/deterministic-deployment-proxy). + +## Introduction + +You can deploy contracts to both L1 and L2 using the deterministic deployment +proxy. Deploying the same contract to multiple chains will result in the same +contract address. + +There are two ways to go about deploying contracts: + +1. Manually in your local environment. This requires you to have [`foundry/cast`](https://github.com/foundry-rs/foundry) installed. +2. Using the [`run-l2-contract-setup.sh`](templates/contract-deploy/run-l2-contract-setup.sh) script. This ensures that the contracts will be deployed with every `kurtosis run`. + +## Deploying Contracts Locally + +For this example, we will be deploying this contract: + +```solidity +pragma solidity 0.5.8; +contract Apple { + function banana() external pure returns (uint8) { + return 42; + } +} +``` + +To determine the contract address of the above contract, compile the bytecode +and run: + +```bash +cast create2 --salt $salt --init-code $bytecode +``` + +To deploy a contract, send the salt and bytecode to the deterministic deployment +proxy deployer address which should be `0x4e59b44847b379578588920ca78fbf26c0b4956c`. + +### Deploy Contracts on L1 + +The accounts using the `code code code code code code code code code code code quality` +mnemonic are pre-funded on L1, so you can use those accounts to for the contract +deployments. + +```bash +polycli wallet inspect --mnemonic "code code code code code code code code code code code quality" | jq -r ".Addresses[0].HexPrivateKey" +``` + +```bash +cast send \ + --legacy \ + --rpc-url "http://$(kurtosis port print cdk el-1-geth-lighthouse rpc)" \ + --private-key "0x42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa" \ + "0x4e59b44847b379578588920ca78fbf26c0b4956c" \ + "$salt$bytecode" +``` + +### Deploy Contracts on L2 + +This is similar to L1 the major differences is the pre-funded account on L2 is the +`zkevm_l2_admin_private_key`. + +```bash +cast send \ + --legacy \ + --rpc-url "$(kurtosis port print cdk cdk-erigon-node-001 rpc)" \ + --private-key "0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" \ + "0x4e59b44847b379578588920ca78fbf26c0b4956c" \ + "$salt$bytecode" +``` + +## Deploying Contracts using `run-l2-contract-setup.sh` + +Most of the same concepts from above apply, you just now have access to some +different variables provided through the kurtosis such as `l1_rpc_url` and +`l2_rpc_url`. + +Here's a complete example that could be appended to the `run-l2-contract-setup.sh`: + +```bash +contract_method_signature="banana()(uint8)" +expected="42" +salt="0x0000000000000000000000000000000000000000000000000000000000000000" +# contract: pragma solidity 0.5.8; contract Apple {function banana() external pure returns (uint8) {return 42;}} +bytecode="6080604052348015600f57600080fd5b5060848061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c3cafc6f14602d575b600080fd5b6033604f565b604051808260ff1660ff16815260200191505060405180910390f35b6000602a90509056fea165627a7a72305820ab7651cb86b8c1487590004c2444f26ae30077a6b96c6bc62dda37f1328539250029" +contract_address=$(cast create2 --salt $salt --init-code $bytecode) + +echo_ts "Testing deterministic deployment proxy on l1" +cast send \ + --legacy \ + --rpc-url "{{.l1_rpc_url}}" \ + --private-key "$l1_private_key" \ + "$deployer_address" \ + "$salt$bytecode" +l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$contract_address" "$contract_method_signature") +if [[ "$expected" != "$l1_actual" ]]; then + echo_ts "Failed to deploy deterministic deployment proxy on l1 (expected: $expected, actual $l1_actual)" + exit 1 +fi + +echo_ts "Testing deterministic deployment proxy on l2" +cast send \ + --legacy \ + --rpc-url "{{.l2_rpc_url}}" \ + --private-key "{{.zkevm_l2_admin_private_key}}" \ + "$deployer_address" \ + "$salt$bytecode" +l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$contract_address" "$contract_method_signature") +if [[ "$expected" != "$l2_actual" ]]; then + echo_ts "Failed to deploy deterministic deployment proxy on l2 (expected: $expected, actual $l2_actual)" + exit 1 +fi +``` diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 64e97be9..f8e1d788 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -70,12 +70,7 @@ signer_address="0x3fab184622dc19b6109349b94811493bf2a45362" gas_cost="0.01ether" transaction="0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222" deployer_address="0x4e59b44847b379578588920ca78fbf26c0b4956c" -l1_private_key=$( - polycli wallet inspect \ - --mnemonic "{{.l1_preallocated_mnemonic}}" \ - --addresses 1 \ - | jq -r ".Addresses[].HexPrivateKey" -) +l1_private_key=$(polycli wallet inspect --mnemonic "{{.l1_preallocated_mnemonic}}" | jq -r ".Addresses[0].HexPrivateKey") echo_ts "Deploying deterministic deployment proxy on l1" cast send \ @@ -84,6 +79,10 @@ cast send \ --value "$gas_cost" \ "$signer_address" cast publish --rpc-url "{{.l1_rpc_url}}" "$transaction" +if [[ $(cast code --rpc-url "{{.l1_rpc_url}}" $deployer_address) == "0x" ]]; then + echo_ts "No code at expected l1 address: $deployer_address" + exit 1; +fi echo_ts "Deploying deterministic deployment proxy on l2" cast send \ @@ -93,38 +92,9 @@ cast send \ --value "$gas_cost" \ "$signer_address" cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction" - -contract_method_signature="banana()(uint8)" -expected="42" -salt="0x0000000000000000000000000000000000000000000000000000000000000000" -# contract: pragma solidity 0.5.8; contract Apple {function banana() external pure returns (uint8) {return 42;}} -bytecode="6080604052348015600f57600080fd5b5060848061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c3cafc6f14602d575b600080fd5b6033604f565b604051808260ff1660ff16815260200191505060405180910390f35b6000602a90509056fea165627a7a72305820ab7651cb86b8c1487590004c2444f26ae30077a6b96c6bc62dda37f1328539250029" -contract_address=$(cast create2 --salt $salt --init-code $bytecode) - -echo_ts "Testing deterministic deployment proxy on l1" -cast send \ - --legacy \ - --rpc-url "{{.l1_rpc_url}}" \ - --private-key "$l1_private_key" \ - "$deployer_address" \ - "$salt$bytecode" -l1_actual=$(cast call --rpc-url "{{.l1_rpc_url}}" "$contract_address" "$contract_method_signature") -if [[ "$expected" != "$l1_actual" ]]; then - echo_ts "Failed to deploy deterministic deployment proxy on l1 (expected: $expected, actual $l1_actual)" - exit 1 -fi - -echo_ts "Testing deterministic deployment proxy on l2" -cast send \ - --legacy \ - --rpc-url "{{.l2_rpc_url}}" \ - --private-key "{{.zkevm_l2_admin_private_key}}" \ - "$deployer_address" \ - "$salt$bytecode" -l2_actual=$(cast call --rpc-url "{{.l2_rpc_url}}" "$contract_address" "$contract_method_signature") -if [[ "$expected" != "$l2_actual" ]]; then - echo_ts "Failed to deploy deterministic deployment proxy on l2 (expected: $expected, actual $l2_actual)" - exit 1 +if [[ $(cast code --rpc-url "{{.l2_rpc_url}}" $deployer_address) == "0x" ]]; then + echo_ts "No code at expected l2 address: $deployer_address" + exit 1; fi # The contract setup is done! From 938d2ca9310b3ad742fe0f8633b6db143a5d2a25 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 04:37:04 -0400 Subject: [PATCH 28/35] fix doc --- docs/deterministic-deployment-proxy.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/deterministic-deployment-proxy.md b/docs/deterministic-deployment-proxy.md index 203d02a0..787777b6 100644 --- a/docs/deterministic-deployment-proxy.md +++ b/docs/deterministic-deployment-proxy.md @@ -11,7 +11,7 @@ contract address. There are two ways to go about deploying contracts: 1. Manually in your local environment. This requires you to have [`foundry/cast`](https://github.com/foundry-rs/foundry) installed. -2. Using the [`run-l2-contract-setup.sh`](templates/contract-deploy/run-l2-contract-setup.sh) script. This ensures that the contracts will be deployed with every `kurtosis run`. +2. Using the [`run-l2-contract-setup.sh`](/templates/contract-deploy/run-l2-contract-setup.sh) script. This ensures that the contracts will be deployed with every `kurtosis run`. ## Deploying Contracts Locally @@ -57,8 +57,8 @@ cast send \ ### Deploy Contracts on L2 -This is similar to L1 the major differences is the pre-funded account on L2 is the -`zkevm_l2_admin_private_key`. +This is similar to L1, just that the major difference is the pre-funded account +on L2 is the `zkevm_l2_admin_private_key`. ```bash cast send \ From d376d42e74b93b8b6f9a1276e9108f114b1831fe Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 11:58:00 -0400 Subject: [PATCH 29/35] format readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 027eb588..9deddb97 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,7 @@ Once that is good and installed on your system, you can run the following comman kurtosis run --enclave cdk github.com/0xPolygon/kurtosis-cdk ``` -The default deployment includes [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) as the sequencer, and [cdk-node](https://github.com/0xPolygon/cdk) functioning as the sequence sender and aggregator. You can verify the default versions of these components and the default fork ID by reviewing input_parser.star. You can check the default versions of the deployed components and the default fork ID by looking at -[input_parser.star](./input_parser.star). +The default deployment includes [cdk-erigon](https://github.com/0xPolygonHermez/cdk-erigon) as the sequencer, and [cdk-node](https://github.com/0xPolygon/cdk) functioning as the sequence sender and aggregator. You can verify the default versions of these components and the default fork ID by reviewing input_parser.star. You can check the default versions of the deployed components and the default fork ID by looking at [input_parser.star](./input_parser.star). To make customizations to the CDK environment, clone this repo, make any desired configuration changes, and then run: From cb78ffc0b498042f89bc1a5796091da1c0337a67 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 13:22:06 -0400 Subject: [PATCH 30/35] reuse zkevm-contracts container --- deploy_l2_contracts.star | 52 ++----------------- deploy_zkevm_contracts.star | 4 ++ input_parser.star | 2 +- .../contract-deploy/run-l2-contract-setup.sh | 14 ++--- 4 files changed, 16 insertions(+), 56 deletions(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 40180eb1..9c0d1d6c 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -1,62 +1,18 @@ service_package = import_module("./lib/service.star") -ARTIFACTS = [ - { - "name": "run-l2-contract-setup.sh", - "file": "./templates/contract-deploy/run-l2-contract-setup.sh", - }, -] - - def run(plan, args): l2_rpc_url = service_package.get_l2_rpc_url(plan, args) - artifact_paths = list(ARTIFACTS) - artifacts = [] - for artifact_cfg in artifact_paths: - template = read_file(src=artifact_cfg["file"]) - artifact = plan.render_templates( - name=artifact_cfg["name"], - config={ - artifact_cfg["name"]: struct( - template=template, - data=args - | { - "l2_rpc_url": l2_rpc_url.http, - "deterministic_deployment_proxy_branch": "master", - }, - ) - }, - ) - artifacts.append(artifact) - - # Create helper service to deploy contracts - contracts_service_name = "contracts-l2" + args["deployment_suffix"] - plan.add_service( - name=contracts_service_name, - config=ServiceConfig( - image=args["l2_contracts_image"], - files={ - "/opt/zkevm": Directory(persistent_key="zkevm-l2-artifacts"), - "/opt/contract-deploy/": Directory(artifact_names=artifacts), - }, - # These two lines are only necessary to deploy to any Kubernetes environment (e.g. GKE). - entrypoint=["bash", "-c"], - cmd=["sleep infinity"], - user=User(uid=0, gid=0), # Run the container as root user. - ), - ) - - # Deploy contracts. plan.exec( description="Deploying contracts on L2", - service_name=contracts_service_name, + service_name="contracts" + args["deployment_suffix"], recipe=ExecRecipe( command=[ "/bin/sh", "-c", - "chmod +x {0} && {0}".format( - "/opt/contract-deploy/run-l2-contract-setup.sh" + "export l2_rpc_url={0} && chmod +x {1} && {1}".format( + l2_rpc_url.http, + "/opt/contract-deploy/run-l2-contract-setup.sh", ), ] ), diff --git a/deploy_zkevm_contracts.star b/deploy_zkevm_contracts.star index 21db2a9c..bcdbe974 100644 --- a/deploy_zkevm_contracts.star +++ b/deploy_zkevm_contracts.star @@ -21,6 +21,10 @@ ARTIFACTS = [ "name": "update-ger.sh", "file": "./templates/contract-deploy/update-ger.sh", }, + { + "name": "run-l2-contract-setup.sh", + "file": "./templates/contract-deploy/run-l2-contract-setup.sh", + }, ] diff --git a/input_parser.star b/input_parser.star index d83e69c4..bf0eac93 100644 --- a/input_parser.star +++ b/input_parser.star @@ -36,7 +36,7 @@ DEFAULT_IMAGES = { "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags - "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags + "zkevm_contracts_image": "minhdvu/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", # https://hub.docker.com/r/0xpolygon/cdk-data-availability/tags "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", # https://hub.docker.com/r/hermeznetwork/zkevm-node/tags "zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.1", # https://hub.docker.com/r/hermeznetwork/zkevm-pool-manager/tags diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index f8e1d788..121311d3 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -20,7 +20,7 @@ wait_for_rpc_to_be_available() { local retry_interval=5 until cast send --legacy \ - --rpc-url "{{.l2_rpc_url}}" \ + --rpc-url "$l2_rpc_url" \ --private-key "{{.zkevm_l2_admin_private_key}}" \ --value 0 "{{.zkevm_l2_sequencer_address}}" &> /dev/null; do ((counter++)) @@ -38,13 +38,13 @@ fund_account_on_l2() { echo_ts "Funding $address" cast send \ --legacy \ - --rpc-url "{{.l2_rpc_url}}" \ + --rpc-url "$l2_rpc_url" \ --private-key "{{.zkevm_l2_admin_private_key}}" \ --value "{{.l2_funding_amount}}" \ "$address" } -if [[ -e "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" ]]; then +if [[ -e "/opt/zkevm/.init-l2-complete{{.deployment_suffix}}.lock" ]]; then echo_ts "This script has already been executed" exit 1 fi @@ -87,15 +87,15 @@ fi echo_ts "Deploying deterministic deployment proxy on l2" cast send \ --legacy \ - --rpc-url "{{.l2_rpc_url}}" \ + --rpc-url "$l2_rpc_url" \ --private-key "{{.zkevm_l2_admin_private_key}}" \ --value "$gas_cost" \ "$signer_address" -cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction" -if [[ $(cast code --rpc-url "{{.l2_rpc_url}}" $deployer_address) == "0x" ]]; then +cast publish --rpc-url "$l2_rpc_url" "$transaction" +if [[ $(cast code --rpc-url "$l2_rpc_url" $deployer_address) == "0x" ]]; then echo_ts "No code at expected l2 address: $deployer_address" exit 1; fi # The contract setup is done! -touch "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" +touch "/opt/zkevm/.init-l2-complete{{.deployment_suffix}}.lock" From 4d4a339e4011db92b73b3f94cec5e4fe60297ab1 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 13:36:13 -0400 Subject: [PATCH 31/35] update docs --- deploy_l2_contracts.star | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 9c0d1d6c..6c36e1a6 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -3,6 +3,12 @@ service_package = import_module("./lib/service.star") def run(plan, args): l2_rpc_url = service_package.get_l2_rpc_url(plan, args) + # When funding accounts and deploying the contracts on l2, the + # zkevm-contracts service is reused to reduce startup time. Since the l2 + # doesn't exist at the time the service is added to kurtosis, the l2_rpc_url + # can't be templated. Therefore, we export he l2_rpc_url as an environment + # variable before running the script. + plan.exec( description="Deploying contracts on L2", service_name="contracts" + args["deployment_suffix"], From 4580f6c7ad3f154223411833c3417265c4b64ac2 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 13:37:51 -0400 Subject: [PATCH 32/35] more docs --- deploy_l2_contracts.star | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 6c36e1a6..833ff424 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -5,9 +5,9 @@ def run(plan, args): # When funding accounts and deploying the contracts on l2, the # zkevm-contracts service is reused to reduce startup time. Since the l2 - # doesn't exist at the time the service is added to kurtosis, the l2_rpc_url - # can't be templated. Therefore, we export he l2_rpc_url as an environment - # variable before running the script. + # doesn't exist at the time the service is added to kurtosis, the + # `l2_rpc_url` can't be templated. Therefore, the `l2_rpc_url` is exported + # as an environment variable before running the `run-l2-contract-setup.sh`. plan.exec( description="Deploying contracts on L2", From 380c66f55e8e5921378d5f1670bb75307268b301 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 13:43:32 -0400 Subject: [PATCH 33/35] fix lint --- deploy_l2_contracts.star | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy_l2_contracts.star b/deploy_l2_contracts.star index 833ff424..83b358f1 100644 --- a/deploy_l2_contracts.star +++ b/deploy_l2_contracts.star @@ -1,11 +1,12 @@ service_package = import_module("./lib/service.star") + def run(plan, args): l2_rpc_url = service_package.get_l2_rpc_url(plan, args) # When funding accounts and deploying the contracts on l2, the # zkevm-contracts service is reused to reduce startup time. Since the l2 - # doesn't exist at the time the service is added to kurtosis, the + # doesn't exist at the time the service is added to kurtosis, the # `l2_rpc_url` can't be templated. Therefore, the `l2_rpc_url` is exported # as an environment variable before running the `run-l2-contract-setup.sh`. From 82477eb2c82e06f59db1b53c55773699a35afa49 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 13:44:28 -0400 Subject: [PATCH 34/35] remove l2 contracts image --- input_parser.star | 1 - 1 file changed, 1 deletion(-) diff --git a/input_parser.star b/input_parser.star index bf0eac93..6054710f 100644 --- a/input_parser.star +++ b/input_parser.star @@ -32,7 +32,6 @@ DEFAULT_IMAGES = { "cdk_erigon_node_image": "hermeznetwork/cdk-erigon:v2.1.0", # https://hub.docker.com/r/hermeznetwork/cdk-erigon/tags "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.3.1-rc1", # https://github.com/0xpolygon/cdk/pkgs/container/cdk "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", # https://hub.docker.com/r/0xpolygon/cdk-validium-node/tags - "l2_contracts_image": "leovct/toolbox:0.0.6", # https://hub.docker.com/r/leovct/toolbox/tags "zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags From b9d436b672d205605f7770a190625ab649797e92 Mon Sep 17 00:00:00 2001 From: minhd-vu Date: Fri, 25 Oct 2024 13:52:43 -0400 Subject: [PATCH 35/35] exit if not set --- templates/contract-deploy/run-l2-contract-setup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/contract-deploy/run-l2-contract-setup.sh b/templates/contract-deploy/run-l2-contract-setup.sh index 121311d3..254a9dfa 100644 --- a/templates/contract-deploy/run-l2-contract-setup.sh +++ b/templates/contract-deploy/run-l2-contract-setup.sh @@ -49,6 +49,11 @@ if [[ -e "/opt/zkevm/.init-l2-complete{{.deployment_suffix}}.lock" ]]; then exit 1 fi +if [[ -z "$l2_rpc_url" ]]; then + echo "Error: l2_rpc_url is not set. Exiting." + exit 1 +fi + echo_ts "Waiting for the L2 RPC to be available" wait_for_rpc_to_be_available echo_ts "L2 RPC is now available"