Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/runner-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,10 @@ runs:
uses: foundry-rs/foundry-toolchain@82dee4ba654bd2146511f85f0d013af94670c4de # v1.4.0
with:
version: ${{ inputs.foundry_version }}

# Temporary measure - install prebuilt version of anvil based off of https://github.com/foundry-rs/foundry/pull/13244
- name: Install custom anvil
shell: 'bash -ex {0}'
run: |
wget https://github.com/itegulov/foundry/releases/download/v1.6.0-compressed-state/anvil -O $(which anvil)
chmod +x $(which anvil)
14 changes: 6 additions & 8 deletions .github/scripts/test-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ chmod a+x ./zksync-os-server

# name|state|config
CONFIGS=(
"v30 default|local-chains/v30.2/default/zkos-l1-state.json|local-chains/v30.2/default/config.yaml"
"v30 multi-chain 1|local-chains/v30.2/multi_chain/zkos-l1-state.json|local-chains/v30.2/multi_chain/chain_6565.yaml"
"v30 multi-chain 2|local-chains/v30.2/multi_chain/zkos-l1-state.json|local-chains/v30.2/multi_chain/chain_6566.yaml"
# TODO: Temporary disable v31 config tests due to wrong state files without balance
# to be re-enabled soon after fixing the issue with state files size and re-generation
# "v31 default|local-chains/v31.0/default/zkos-l1-state.json|local-chains/v31.0/default/config.yaml"
# "v31 multi-chain 1|local-chains/v31.0/multi_chain/zkos-l1-state.json|local-chains/v31.0/multi_chain/chain_6565.yaml"
# "v31 multi-chain 2|local-chains/v31.0/multi_chain/zkos-l1-state.json|local-chains/v31.0/multi_chain/chain_6566.yaml"
"v30 default|local-chains/v30.2/l1-state.json.gz|local-chains/v30.2/default/config.yaml"
"v30 multi-chain 1|local-chains/v30.2/l1-state.json.gz|local-chains/v30.2/multi_chain/chain_6565.yaml"
"v30 multi-chain 2|local-chains/v30.2/l1-state.json.gz|local-chains/v30.2/multi_chain/chain_6566.yaml"
"v31 default|local-chains/v31.0/l1-state.json.gz|local-chains/v31.0/default/config.yaml"
"v31 multi-chain 1|local-chains/v31.0/l1-state.json.gz|local-chains/v31.0/multi_chain/chain_6565.yaml"
"v31 multi-chain 2|local-chains/v31.0/l1-state.json.gz|local-chains/v31.0/multi_chain/chain_6566.yaml"
)

cleanup() {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ jobs:
# This is a special mandatory hack to transfer test binary from one machine to another.
# We must use a dummy `./` path addition in the workspace path /home/runner/_work
# to prevent GitHub Actions to replace it to the mapped `/__w` folder in the docker container.
# This is required to make sure that the paths to workspace artifacts like zkos-l1-state.json
# This is required to make sure that the paths to workspace artifacts like l1-state.json.gz
# are correct inside prebuilt binary.
# This variable overwrites the default relative `./` in the .cargo/config.toml.
WORKSPACE_DIR: "/opt/./actions-runner/_work/zksync-os-server/zksync-os-server"
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/release-bins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ env:
RELEASE_PROFILE: 'maxperf'
SERVER_LOGFILE: zksync-os-server.log.txt
FOUNDRY_VERSION: 'v1.5.1'
L1_STATE_JSON: 'local-chains/v30.2/default/zkos-l1-state.json'
GENESIS_JSON: 'local-chains/v30.2/default/genesis.json'
L1_STATE_JSON: 'local-chains/v30.2/l1-state.json.gz'
GENESIS_JSON: 'local-chains/v30.2/genesis.json'

defaults:
run:
Expand Down Expand Up @@ -140,6 +140,13 @@ jobs:
with:
version: '${{ env.FOUNDRY_VERSION }}'

# Temporary measure - install prebuilt version of anvil based off of https://github.com/foundry-rs/foundry/pull/13244
- name: Install custom anvil
shell: 'bash -ex {0}'
run: |
wget https://github.com/itegulov/foundry/releases/download/v1.6.0-compressed-state/anvil -O $(which anvil)
chmod +x $(which anvil)

- name: Check executable
env:
TIMEOUT: 60
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spec-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
uses: ./.github/actions/runner-setup

- name: Run anvil L1
run: anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545 &
run: anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545 &

- name: Build server
run: cargo build --release --bin zksync-os-server
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

### Basic Commands
- **Build**: `cargo build` or `cargo build --release`
- **Run locally**: `cargo run` (requires `anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545` running first)
- **Run locally**: `cargo run` (requires `anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545` running first)
- **Format**: `cargo fmt --all -- --check`
- **Lint**: `cargo clippy --all-targets --all-features --workspace --exclude zksync_os_integration_tests -- -D warnings`
- **Unit tests**: `cargo nextest run --workspace --exclude zksync_os_integration_tests`
- **Integration tests**: `cargo nextest run --profile ci -p zksync_os_integration_tests`

### Local Development Setup
1. Start anvil: `anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545`
1. Start anvil: `anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545`
2. Run server: `cargo run`
3. To restart chain: `rm -rf db/*` then restart anvil

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The ZKsync OS Server design optimizes for throughput, low latency, and a seamles
To run server locally with in-memory L1 node and dummy proofs, run the following commands:
```bash
# Start in-memory L1 node
anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545
anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545
# Launch zksync-os-server on the default port 3050
# By default, fake (dummy) proofs are used both for FRI and SNARK proofs.
cargo run --release --bin zksync-os-server
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guides/generate_l1_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ THIS GUIDE IS A DRAFT VERSION FOR THE NEW TOOLING AND WILL BE SIGNIFICANTLY UPDA
## Prerequisites

Make sure you have the following tools installed:
* `anvil` v1.5.1 -> incredibly important to have exactly this `anvil` version, otherwise the state file won't load
* `anvil` v1.6.0-5bcdddc06a -> incredibly important to have exactly this `anvil` version, otherwise the state file won't load
* `forge` and `cast` v0.0.4 -> incredibly important to have exactly these versions, otherwise contracts won't deploy correctly
* `git`
* `cargo`
Expand Down
14 changes: 7 additions & 7 deletions docs/src/guides/running_with_l1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ USE THIS GUIDE ONLY AS A GENERAL REFERENCE, BRANCHES AND VERSIONS MIGHT ARE OUTD
## Simplest (no contract changes etc)
If you're not doing any contract changes, and simply want to hook up to L1, start anvil with pre-created state.

This repo includes a pre-setup L1 state `zkos-l1-state.json` that can be loaded into `anvil`. The state was generated by `zkstack init` and essentially consists of all L1 contracts deployed and initialized with L2 genesis.
This repo includes a pre-setup L1 state `l1-state.json.gz` that can be loaded into `anvil`. The state was generated by `zkstack init` and essentially consists of all L1 contracts deployed and initialized with L2 genesis.
The state comes with some L1 priority transactions that were generated by the old genesis logic and are hence failing in the new implementation.
It also comes with a deposit transaction that makes `0x36615cf349d7f6344891b1e7ca7c72883f5dc049` into a rich account (>10k ETH) (to regenerate it, see "Regenerate zkos-l1-state.json` below)
It also comes with a deposit transaction that makes `0x36615cf349d7f6344891b1e7ca7c72883f5dc049` into a rich account (>10k ETH) (to regenerate it, see "Regenerate l1-state.json.gz` below)

Before you run an L1 node, make sure you have a `1.5.1` version of `anvil` installed (see [foundry guide](https://getfoundry.sh/)). Then:
Before you run an L1 node, make sure you have a `v1.6.0-5bcdddc06a` version of `anvil` installed (see [foundry guide](https://getfoundry.sh/)). Then:

```
anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545
anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545
...
Listening on 127.0.0.1:8545
...
Expand Down Expand Up @@ -119,9 +119,9 @@ If you restart anvil, you have to repeat a subset of steps from above, to re-cre

Note: There is an [experimental tool](https://github.com/mm-zk/zksync_tools/tree/main/zkos/update_state_json) that can run these commands for you. If it turns out to be useful, we might make it more permanent.

L1 state is checked in into this repo under `zkos-l1-state.json`. To regenerate it from scratch, run the following commands:
L1 state is checked in into this repo under `l1-state.json.gz`. To regenerate it from scratch, run the following commands:
```
anvil -m "stuff slice staff easily soup parent arm payment cotton trade scatter struggle" --state ./local-chains/v30.2/default/zkos-l1-state.json
anvil -m "stuff slice staff easily soup parent arm payment cotton trade scatter struggle" --state ./local-chains/v30.2/l1-state.json.gz
```
Note that we pass this mnemonic to have `0x36615cf349d7f6344891b1e7ca7c72883f5dc049` rich wallet - legacy from era.

Expand All @@ -136,7 +136,7 @@ Successfully submitted L1->L2 deposit tx with hash '0xb8544a2a9bc55713f1f94acf37
Process finished with exit code 0

```
Now stop anvil (ctrl+c) - the state will be saved to the file. Rerun it with `--load-state ./local-chains/v30.2/default/zkos-l1-state.json` (`--load-state` - not `--state`, otherwise it will be overwritten). Commit the new file in git.
Now stop anvil (ctrl+c) - the state will be saved to the file. Rerun it with `--load-state ./local-chains/v30.2/l1-state.json.gz` (`--load-state` - not `--state`, otherwise it will be overwritten). Commit the new file in git.

Update values in `L1SenderConfig`:
* `bridgehub_address` -> `bridgehub_proxy_addr` in `contracts.yaml` of `zkstack` tool output
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guides/updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Then follow instructions below for era-contracts updates.

## Updating era contracts

If you do any change to era-contracts, we should update zkos-l1-state.json (especially if this is a breaking change -- be careful with those when we're in production).
If you do any change to era-contracts, we should update l1-state.json.gz (especially if this is a breaking change -- be careful with those when we're in production).

* commit your change to era-contracts, and generate a new release/tag (we name them as zkos-v0.29.3 for example)
* go to zksync-era, checkout zksync-os-integration, and update the contracts dependency there (this step will hopefully disappear soon)
Expand All @@ -36,6 +36,6 @@ Currently it is a little bit of a frustrating process, but we plan to improve it
* Step 2: compute "genesis hash" - when you start the server **with new genesis.json** created in the step above - add a print here: https://github.com/matter-labs/zksync-os-server/blob/main/node/bin/src/batcher/util.rs#L36 to get the hash value.
* Step 3: Put the new hash value into: https://github.com/matter-labs/zksync-era/blob/zksync-os-integration/etc/env/file_based/genesis.yaml
* Step 4: Re-run the Step 1. Make sure to use zksync-era with the Step3, as new genesis is used inside CTM registration, so it will impact the state.json contents.
* Step 5: check that everything works -- you should be able to run anvil with the new state (`anvil --load_state ./local-chains/v30.2/default/zkos-l1-state.json`) and zksync-os-server **with new genesis.json** (it normally loads it from local directory).
* Step 5: check that everything works -- you should be able to run anvil with the new state (`anvil --load_state ./local-chains/v30.2/l1-state.json.gz`) and zksync-os-server **with new genesis.json** (it normally loads it from local directory).

https://github.com/matter-labs/zksync-os-server/blob/main/node/bin/src/batcher/util.rs#L36
2 changes: 1 addition & 1 deletion docs/src/setup/local_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The `run_local.sh` script automates starting Anvil and chain node(s):
To run node locally, first launch `anvil`:

```
anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545
anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545
```

then launch the server:
Expand Down
19 changes: 11 additions & 8 deletions docs/src/setup/prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@ This project requires:
* The **Foundry nightly toolchain**
* The **Rust toolchain**

### Install Foundry (v1.5.1)
### Install Foundry (v1.6.0-5bcdddc06a)

Install [Foundry](https://getfoundry.sh/) v1.5.1:
To install [Foundry](https://getfoundry.sh/):

```bash
# Download the Foundry installer
curl -L https://foundry.paradigm.xyz | bash

# Install forge, cast, anvil, chisel
# Ensure you are using the 1.5.1 stable release
foundryup -i 1.5.1
# Temporarily we require custom version of anvil that supports compressed state.
# Hopefully https://github.com/foundry-rs/foundry/pull/13244 will get accepted, then we will
# be able to switch to nightly.
foundryup -r itegulov/foundry -C 5bcdddc06abe5b0cd8e9bc1de8ddfb7202a95ed1
```

Verify your installation:
Verify your installation reports correct version:

```bash
anvil --version
$ anvil --version
anvil Version: 1.6.0-dev
Commit SHA: 5bcdddc06abe5b0cd8e9bc1de8ddfb7202a95ed1
...
```

The output should include a `anvil Version: 1.5.1`.

### Install Rust

Install [Rust](https://www.rust-lang.org/tools/install) using `rustup`:
Expand Down
9 changes: 6 additions & 3 deletions integration-tests/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ impl<'a> ChainLayout<'a> {
}
}

fn base_dir(self) -> PathBuf {
fn protocol_dir(self) -> PathBuf {
workspace_dir()
.join("local-chains")
.join(self.protocol_version())
.join(self.dir())
}

fn base_dir(self) -> PathBuf {
self.protocol_dir().join(self.dir())
}

fn config_path(self) -> PathBuf {
Expand All @@ -59,7 +62,7 @@ impl<'a> ChainLayout<'a> {
}

fn l1_state_path(self) -> PathBuf {
self.base_dir().join("zkos-l1-state.json")
self.protocol_dir().join("l1-state.json.gz")
}

/// Genesis input is always taken from `<version>/default/genesis.json`
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod provider;
pub mod upgrade;
mod utils;

/// L1 chain id as expected by contracts deployed in `zkos-l1-state.json`
/// L1 chain id as expected by contracts deployed in `l1-state.json.gz`
const L1_CHAIN_ID: u64 = 31337;

/// Set of private keys for batch verification participants.
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/upgrade/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl UpgradeTester {

// Bytecode supplier is a bit special: right now it's not discoverable
// The value is hardcoded, keep it aligned with `node/bin/src/config.rs`, it must correspond
// to the value stored in `zkos-l1-state.json`.
// to the value stored in `l1-state.json.gz`.
let bytecode_supplier_address = default_config
.genesis_config
.bridgehub_address
Expand All @@ -197,7 +197,7 @@ impl UpgradeTester {
.get_code_at(bytecode_supplier_address)
.await?
.is_empty(),
"Bytecode supplier contract is not deployed at expected address {bytecode_supplier_address:?}; if zkos-l1-state.json was updated, update the address in the test code"
"Bytecode supplier contract is not deployed at expected address {bytecode_supplier_address:?}; if l1-state.json.gz was updated, update the address in the test code"
);
let bytecode_supplier = interfaces::BytecodesSupplier::new(
bytecode_supplier_address,
Expand Down
30 changes: 14 additions & 16 deletions local-chains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,45 @@ local-chains/
│ ├── default/ # Default (single-chain) setup
│ │ ├── README.md # Scenario-specific documentation
│ │ ├── config.yaml # Sequencer configuration
│ │ ├── genesis.json # Genesis configuration
│ │ ├── wallets.yaml # Wallets configuration
│ │ ├── contracts.yaml # Contracts configuration
│ │ └── zkos-l1-state.json # L1 state for this scenario
│ │ └── contracts.yaml # Contracts configuration
│ ├── multi_chain/ # Multi-chain scenario
│ │ ├── README.md # Scenario-specific documentation
│ │ ├── chain_6565.yaml # Configuration for chain with ID 6565
│ │ ├── chain_6566.yaml # Configuration for chain with ID 6566
│ │ ├── wallets_6565.yaml # Wallets for chain 6565
│ │ ├── wallets_6566.yaml # Wallets for chain 6566
│ │ ├── contracts_6565.yaml # Contracts for chain 6565
│ │ ├── contracts_6566.yaml # Contracts for chain 6566
│ │ └── zkos-l1-state.json # Shared L1 state for the multi-chain scenario
│ │ └── contracts_6566.yaml # Contracts for chain 6566
│ ├── l1-state.json.gz # Shared L1 state for protocol v30.2
│ ├── genesis.json # Genesis configuration for protocol v30.2
│ └── versions.yaml # Version metadata for protocol v30.2
└── v31.0/ # Protocol version v31.0
├── default/ # Default (single-chain) setup
│ ├── README.md # Scenario-specific documentation
│ ├── config.yaml # Sequencer configuration
│ ├── genesis.json # Genesis configuration
│ ├── wallets.yaml # Wallets configuration
│ └── zkos-l1-state.json # L1 state for this scenario
│ └── wallets.yaml # Wallets configuration
├── multi_chain/ # Multi-chain scenario
│ ├── README.md # Scenario-specific documentation
│ ├── chain_6565.yaml # Configuration for chain with ID 6565
│ ├── chain_6566.yaml # Configuration for chain with ID 6566
│ ├── wallets_6565.yaml # Wallets for chain 6565
│ ├── wallets_6566.yaml # Wallets for chain 6566
│ ├── contracts_6565.yaml # Contracts for chain 6565
│ ├── contracts_6566.yaml # Contracts for chain 6566
│ └── zkos-l1-state.json # Shared L1 state for the multi-chain scenario
└── versions.yaml # Version metadata for protocol v31.0
│ └── contracts_6566.yaml # Contracts for chain 6566
│ ├── l1-state.json.gz # Shared L1 state for protocol v31.0
│ ├── genesis.json # Genesis configuration for protocol v31.0
│ └── versions.yaml # Version metadata for protocol v31.0
```

## Configuration Files

### `zkos-l1-state.json`
### `l1-state.json.gz`

L1 state snapshot for Anvil. Contains the deployed L1 contracts state that can be loaded with:

```bash
anvil --load-state ./local-chains/v30.2/default/zkos-l1-state.json --port 8545
anvil --load-state ./local-chains/v30.2/l1-state.json.gz --port 8545
```

### `config.yaml`
Expand Down Expand Up @@ -100,7 +98,7 @@ The `run_local.sh` script automates starting Anvil and chain node(s):

#### How the Script Works

1. **Validates configuration directory** - Checks that the directory exists and contains `zkos-l1-state.json`
1. **Validates configuration directory** - Checks that the directory exists and `l1-state.json.gz` is in parent directory
2. **Builds ZKsync OS**
3. **Starts Anvil** - Loads the L1 state snapshot on port 8545
4. **Waits for Anvil readiness** - Polls the JSON-RPC endpoint until Anvil responds (up to 30 seconds)
Expand Down Expand Up @@ -144,7 +142,7 @@ Follow the instructions in the [v30.2/multi_chain/README.md](./v30.2/multi_chain
### Anvil failed to start

- Check if port 8545 is already in use: `lsof -i :8545`
- Verify `zkos-l1-state.json` exists and is valid JSON
- Verify `l1-state.json.gz` exists and is valid gzipped JSON

### Chain fails to start

Expand All @@ -155,4 +153,4 @@ Follow the instructions in the [v30.2/multi_chain/README.md](./v30.2/multi_chain
### Multiple chains: port conflicts

- Each chain config must specify unique ports. `rpc.address` - JSON-RPC port (e.g., 3050, 3051, 3052)
- Chains should be run in ephemeral mode or use unique directory paths for RocksDB and file storage to avoid interfering with one another.
- Chains should be run in ephemeral mode or use unique directory paths for RocksDB and file storage to avoid interfering with one another.
Loading
Loading