Skip to content

Commit

Permalink
feat: enable support for pre-deployed contracts (#112)
Browse files Browse the repository at this point in the history
* feat: enable support for pre-deployed contracts

* chore: clean up

* feat: add helper service

* chore: deploy helper service in all contexts

* chore: nit

* fix: helper service setup

* ci: add pre-deployed-contracts job

* ci: fix test deployment

* chore: nit

* chore: more logs

* fix: input parser

* chore: nit

* chore: refactor script

* fix: typo

* test

* chore: add debug

* chore: clean up

* ci: rename workload to toolbox
  • Loading branch information
leovct committed May 20, 2024
1 parent d2ac8f9 commit 9381ebb
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 38 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,56 @@ jobs:
- name: Check that batches are being verified
working-directory: ./scripts
run: ./batch_verification_monitor.sh ${{ env.BATCH_VERIFICATION_MONITOR_TARGET }} ${{ env.BATCH_VERIFICATION_MONITOR_TIMEOUT }}

# Deploy the CDK environment against a local l1 chain with pre-deployed zkevm contracts.
pre-deployed-contracts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Install tools.
- name: Install kurtosis
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli=${{ env.KURTOSIS_VERSION }}
kurtosis analytics disable
- name: Install yq
run: pip3 install yq

- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1

# Deploy components.
- name: Deploy L1 and zkEVM contracts
run: |
# Disable all deployment steps.
yq -Y --in-place 'with_entries(if .value | type == "boolean" then .value = false else . end)' params.yml
# Only deploy l1 and zkevm contracts.
yq -Y --in-place '(.deploy_l1 = true) | (.deploy_zkevm_contracts_on_l1 = true)' params.yml
kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always .
- name: Specify the rollup manager contract address and a few other parameters
run: |
zkevm_rollup_manager_address=$(kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq .polygonRollupManagerAddress)
yq -Y --in-place ".args.zkevm_rollup_manager_address = $zkevm_rollup_manager_address" params.yml
zkevm_rollup_manager_block_number=$(kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq .deploymentRollupManagerBlockNumber)
yq -Y --in-place ".args.zkevm_rollup_manager_block_number = $zkevm_rollup_manager_block_number" params.yml
zkevm_global_exit_root_l2_address=$(kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq .polygonZkEVMGlobalExitRootL2Address)
yq -Y --in-place ".args.zkevm_global_exit_root_l2_address = $zkevm_global_exit_root_l2_address" params.yml
polygon_data_committee_address=$(kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq .polygonDataCommitteeAddress)
yq -Y --in-place ".args.polygon_data_committee_address = $polygon_data_committee_address" params.yml
- name: Deploy the rest of the components
run: |
# Enable all deployment steps.
yq -Y --in-place 'with_entries(if .value | type == "boolean" then .value = true else . end)' params.yml
# Do not deploy l1 and zkevm contracts.
yq -Y --in-place '(.deploy_l1 = false) | (.deploy_zkevm_contracts_on_l1 = false)' params.yml
kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always .
6 changes: 3 additions & 3 deletions .github/workflows/docker-image-builder-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true

workload:
toolbox:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -109,9 +109,9 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v5
with:
file: docker/workload.Dockerfile
file: docker/toolbox.Dockerfile
build-args: |
POLYCLI_VERSION=${{ env.POLYCLI_VERSION }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/workload:0.0.1
tags: ${{ secrets.DOCKERHUB_USERNAME }}/toolbox:0.0.1
platforms: linux/amd64,linux/arm64
push: true
12 changes: 6 additions & 6 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ REPOSITORY TAG IMAGE ID CREATED SIZE
local/zkevm-bridge-ui multi-network 040905e1cabe 28 seconds ago 377MB
```

## Workload
## Toolbox

To build the workload image locally, use the following command:
To build the toolbox image locally, use the following command:

```bash
docker build . \
--tag local/workload:0.0.1 \
--tag local/toolbox:0.0.1 \
--build-arg POLYCLI_VERSION=main \
--file workload.Dockerfile
--file toolbox.Dockerfile
```

```bash
$ docker images --filter "reference=local/workload"
$ docker images --filter "reference=local/toolbox"
REPOSITORY TAG IMAGE ID CREATED SIZE
local/workload 0.0.1 3f85f026aaf9 2 seconds ago 490MB
local/toolbox 0.0.1 3f85f026aaf9 2 seconds ago 490MB
```
2 changes: 1 addition & 1 deletion docker/workload.Dockerfile → docker/toolbox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN git clone --branch ${POLYCLI_VERSION} https://github.com/maticnetwork/polygo

FROM ubuntu:22.04
LABEL author="devtools@polygon.technology"
LABEL description="Helper image capable of executing diverse workloads"
LABEL description="Blockchain toolbox"

COPY --from=polycli-builder /opt/polygon-cli/polycli /usr/bin/polycli
# WARNING (DL3008): Pin versions in apt get install.
Expand Down
22 changes: 2 additions & 20 deletions input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DEFAULT_ARGS = {
"blockscout_visualizer_image": "ghcr.io/blockscout/visualizer:main",
"zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network",
"zkevm_bridge_proxy_image": "haproxy:2.9.7",
"workload_image": "leovct/workload:0.0.1",
"toolbox_image": "leovct/toolbox:0.0.1",
"zkevm_hash_db_port": 50061,
"zkevm_executor_port": 50071,
"zkevm_aggregator_port": 50081,
Expand Down Expand Up @@ -114,22 +114,4 @@ DEFAULT_ARGS = {


def parse_args(args):
full_args = fill_dict(args, DEFAULT_ARGS)
# Check whatever on args here.
return full_args


def fill_dict(my_dict, def_values):
# By passing params to main run, args got frozen, so we need to copy
new_dict = {}
for k, v in def_values.items():
if k not in my_dict:
new_dict[k] = v
else:
new_dict[k] = my_dict[k]
if type(v) == "dict":
# No recursion on Star, so only 1 nested level allowed
for _k, _v in v.items():
if _k not in new_dict[k]:
new_dict[k][_k] = _v
return new_dict
return DEFAULT_ARGS | args
2 changes: 1 addition & 1 deletion kurtosis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ description: |-
zkevm_bridge_ui_image: leovct/zkevm-bridge-ui:multi-network
zkevm_bridge_proxy_image: haproxy:2.9.7
workload_image: leovct/workload:0.0.1
toolbox_image: leovct/toolbox:0.0.1
# Port configuration.
Expand Down
12 changes: 9 additions & 3 deletions lib/service.star
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ def get_contract_setup_addresses(plan, args):
"zkevm_bridge_address": "fromjson | .polygonZkEVMBridgeAddress",
"zkevm_rollup_address": "fromjson | .rollupAddress",
"zkevm_rollup_manager_address": "fromjson | .polygonRollupManagerAddress",
"zkevm_rollup_manager_block_number": "fromjson | .deploymentRollupManagerBlockNumber",
"zkevm_global_exit_root_address": "fromjson | .polygonZkEVMGlobalExitRootAddress",
"zkevm_global_exit_root_l2_address": "fromjson | .polygonZkEVMGlobalExitRootL2Address",
"polygon_data_committee_address": "fromjson | .polygonDataCommitteeAddress",
"pol_token_address": "fromjson | .polTokenAddress",
"rollup_manager_block_number": "fromjson | .deploymentRollupManagerBlockNumber",
},
)
service_name = "contracts"
if "zkevm_rollup_manager_address" in args:
service_name = "helper"
service_name += args["deployment_suffix"]
result = plan.exec(
description="Getting contract setup addresses",
service_name="contracts" + args["deployment_suffix"],
description="Getting contract setup addresses from {} service".format(
service_name
),
service_name=service_name,
recipe=exec_recipe,
)
return get_exec_recipe_result(result)
Expand Down
59 changes: 58 additions & 1 deletion main.star
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def run(
else:
plan.print("Skipping the deployment of zkevm contracts on L1")

# Deploy helper service to retrieve rollup data from rollup manager contract.
if (
"zkevm_rollup_manager_address" in args
and "zkevm_rollup_manager_block_number" in args
and "zkevm_global_exit_root_l2_address" in args
and "polygon_data_committee_address" in args
):
plan.print("Deploying helper service to retrieve rollup data")
deploy_helper_service(plan, args)
else:
plan.print("Skipping the deployment of helper service to retrieve rollup data")

# Deploy zkevm node and cdk peripheral databases.
if deploy_databases:
plan.print("Deploying zkevm node and cdk peripheral databases")
Expand Down Expand Up @@ -126,7 +138,7 @@ def run(

# Apply workload
if apply_workload:
plan.print("Apply workload")
plan.print("Applying workload")
import_module(workload_package).run(plan, args)
else:
plan.print("Skipping workload application")
Expand All @@ -138,3 +150,48 @@ def run(
import_module(blutgang_package).run(plan, blutgang_args)
else:
plan.print("Skipping the deployment of blutgang")


def deploy_helper_service(plan, args):
# Create script artifact.
get_rollup_info_template = read_file(src="./templates/get-rollup-info.sh")
get_rollup_info_artifact = plan.render_templates(
name="get-rollup-info-artifact",
config={
"get-rollup-info.sh": struct(
template=get_rollup_info_template,
data=args
| {
"rpc_url": args["l1_rpc_url"],
},
)
},
)

# Deploy helper service.
helper_service_name = "helper" + args["deployment_suffix"]
plan.add_service(
name=helper_service_name,
config=ServiceConfig(
image=args["toolbox_image"],
files={"/opt/zkevm": get_rollup_info_artifact},
# These two lines are only necessary to deploy to any Kubernetes environment (e.g. GKE).
entrypoint=["bash", "-c"],
cmd=["sleep infinity"],
),
)

# Retrieve rollup data.
plan.exec(
description="Retrieving rollup data from the rollup manager contract",
service_name=helper_service_name,
recipe=ExecRecipe(
command=[
"/bin/sh",
"-c",
"chmod +x {0} && {0}".format(
"/opt/zkevm/get-rollup-info.sh",
),
]
),
)
12 changes: 11 additions & 1 deletion params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ args:
blockscout_visualizer_image: ghcr.io/blockscout/visualizer:main
zkevm_bridge_ui_image: leovct/zkevm-bridge-ui:multi-network
zkevm_bridge_proxy_image: haproxy:2.9.7
workload_image: leovct/workload:0.0.1
toolbox_image: leovct/toolbox:0.0.1

# Port configuration.
zkevm_hash_db_port: 50061
Expand Down Expand Up @@ -187,6 +187,16 @@ args:
# The fork id of the new rollup. It indicates the prover (zkROM/executor) version.
zkevm_rollup_fork_id: 9

# The address of the rollup manager contract on L1.
# If specified, the rollup data will be retrieved from this contract instead of using the contracts service.
# zkevm_rollup_manager_address: ""
# # The block number at which the rollup manager contract was deployed.
# zkevm_rollup_manager_block_number: 0
# # The address of the global exit root contract on L2.
# zkevm_global_exit_root_l2_address: ""
# # The address of the Polygon data committee contract on L1.
# polygon_data_committee_address: ""

# The consensus contract name of the new rollup.
zkevm_rollup_consensus: PolygonValidiumEtrog

Expand Down
2 changes: 1 addition & 1 deletion templates/bridge-infra/bridge-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BridgeVersion = "v1"
MaxConns = 20

[NetworkConfig]
GenBlockNumber = "{{.rollup_manager_block_number}}"
GenBlockNumber = "{{.zkevm_rollup_manager_block_number}}"
PolygonBridgeAddress = "{{.zkevm_bridge_address}}"
PolygonZkEVMGlobalExitRootAddress = "{{.zkevm_global_exit_root_address}}"
PolygonRollupManagerAddress = "{{.zkevm_rollup_manager_address}}"
Expand Down
22 changes: 22 additions & 0 deletions templates/get-rollup-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# This script retrieves all the rollup data using the rollup manager address and the chain id.
rpc_url="{{.rpc_url}}"
zkevm_rollup_manager_address="{{.zkevm_rollup_manager_address}}"
zkevm_rollup_chain_id="{{.zkevm_rollup_chain_id}}"

rollup_id="$(cast call --rpc-url "$rpc_url" "$zkevm_rollup_manager_address" "chainIDToRollupID(uint64)(uint32)" "$zkevm_rollup_chain_id")"
zkevm_rollup_address="$(cast call --rpc-url "$rpc_url" "$zkevm_rollup_manager_address" "rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)" "$rollup_id" | sed -n "1p")"
zkevm_bridge_address="$(cast call --rpc-url "$rpc_url" "$zkevm_rollup_manager_address" "bridgeAddress()(address)")"
zkevm_global_exit_root_address="$(cast call --rpc-url "$rpc_url" "$zkevm_rollup_manager_address" "globalExitRootManager()(address)")"
pol_token_address="$(cast call --rpc-url "$rpc_url" "$zkevm_rollup_manager_address" "pol()(address)")"
echo '{' \
\"polygonZkEVMBridgeAddress\":\""$zkevm_bridge_address"\", \
\"rollupAddress\":\""$zkevm_rollup_address"\", \
\"polygonRollupManagerAddress\":\""$zkevm_rollup_manager_address"\", \
\"deploymentRollupManagerBlockNumber\":\""{{.zkevm_rollup_manager_block_number}}"\", \
\"polygonZkEVMGlobalExitRootAddress\":\""$zkevm_global_exit_root_address"\", \
\"polygonZkEVMGlobalExitRootL2Address\":\""{{.zkevm_global_exit_root_l2_address}}"\", \
\"polygonDataCommitteeAddress\":\""{{.polygon_data_committee_address}}"\", \
\"polTokenAddress\":\""$pol_token_address"\" \
'}' | jq > /opt/zkevm/combined.json
2 changes: 1 addition & 1 deletion workload.star
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run(plan, args):
plan.add_service(
name="workload" + args["deployment_suffix"],
config=ServiceConfig(
image=args["workload_image"],
image=args["toolbox_image"],
files={
"/usr/local/bin": Directory(artifact_names=[workload_script_artifact]),
},
Expand Down

0 comments on commit 9381ebb

Please sign in to comment.