Update server: generate genesis and L1 state

Updates zksync-os-server and its local-chains setup repository with the new genesis and L1 state.

Usually, the script is used by the protocol upgrade operator or automation to perform the protocol upgrade.

It can be used to create or update local test setups for a given protocol version or with a custom version of era-contracts.

Script performs the following steps:

  • Build zkstack CLI: Compiles the zkstack command used to create/init ecosystems and chains.
  • Build L1 contracts.
  • Generate genesis.json.
  • Fund necessary rich wallets.
  • Deploy required L1 contracts.
  • Update local-chains configurations, copies required chains and wallets files.
  • Generate L1 -> L2 deposit tx for rich wallets.
  • Updates verification key hash.
  • Regenerate contracts.json used by the L1 watcher.

The script updates the following files in the zksync-os-server repository:

  • local-chains/<protocol_version>/**/* - local chain configuration for chosen protocol version
  • lib/l1_watcher/src/factory_deps/contracts.json - L1 contracts configuration used by the L1 watcher
  • lib/types/src/protocol/proving_version.rs - new verification key hash (if it changed, otherwise it is not updated)

Local use

Example usage

REPO_DIR="/path/to/zksync-os-server" \
ERA_CONTRACTS_PATH="/path/to/era-contracts" \
ZKSYNC_ERA_PATH="/path/to/zksync-era" \
PROTOCOL_VERSION=<protocol_version> \
    uv run -m scripts.update_server

Careful

Before running this script, ensure that anvil is not running on 8545 port.

To run the script, you will need:

Protocol version and branches

In addition, the script requires access to the following repositories, which should be specified via corresponding path environment variables:

RepositoryEnv VariableProtocol version → Branch Mapping
zksync-os-serverREPO_DIRall versionsmain
era-contractsERA_CONTRACTS_PATHv30.2zksync-os-stable
v31.0draft-v31-with-zksync-os
zksync-eraZKSYNC_ERA_PATHv30.2zkstack-for-zksync-os
v31.0draft-v31

Also, make sure you have the right tooling versions:

protocolfoundry-zksyncanvil version
v30.2nightly-ae913af65381734ad46c044a9495b67310bc77c41.5.1
v31.01.3.5-foundry-zksync-v0.1.51.5.1

Detailed instructions on how to install the required tooling can be found in the prerequisites guide.

Please, additionally check protocol compatibility to ensure the correct versions are used.


GitHub Actions

The script supports execution via GitHub Actions update-server.yaml workflow that can be triggered manually via GitHub Actions UI interface.

Input parameters

NameRequiredDescription
protocol_versionProtocol version to update. Determines default dependency mappings.
zksync_server_branchBase branch of zksync-os-server used for the update.
zksync_era_versionExplicit zksync-era version. If empty, derived from protocol_version.
era_contracts_versionExplicit era-contracts version. If empty, derived from protocol_version.
commit_changesWhether to commit changes back to the repository. Defaults to true.
open_prWhether to open a PR for the committed changes. Defaults to true.

Workflow inputs

Configuring the workflow

Follow more detailed tutorial in the GitHub Actions guide.

Outputs

On successful runs, the workflow uploads server_<protocol_version>.patch Git patch file with the changes made to the zksync-os-server repository.

If commit_changes and open_pr are set to true, a PR is opened automatically with the changes.

On failed runs, the workflow saves logs from the workspace .logs directory as an artifact.

Tip

Artifacts can be downloaded directly from the workflow run page in GitHub Actions.

Script dependencies

The script relies on the following external resources:

Script failure

If the script fails, it means that one of the dependencies is changed or unavailable. In this case, the script needs to be updated accordingly.

  • Wrong tooling versions → incompatible with the contracts and scripts
    • To fix: check the required versions in the protocol version and branches table above and in the protocol compatibility guide, and install the correct versions
  • Unable to start anvil → anvil is already running on 8545 port
    • To fix: stop another anvil instances you already have or change the port it runs on

Any other issue in the operations performed by the script is likely caused by changes in the dependencies, and requires checking the steps of the script and updating it accordingly.

If you notice any such changes are required, please, reach out to the owners or create a PR with the required updates.