Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Don't merge - zk os integration #3370

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
682 changes: 472 additions & 210 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ members = [
# Test infrastructure
"core/tests/loadnext",
"core/tests/vm-benchmark",
"core/node/zkos_state_keeper",
"core/node/zkos_vm_runner",
]
resolver = "2"

Expand Down Expand Up @@ -159,6 +161,7 @@ regex = "1"
reqwest = "0.12"
rlp = "0.5"
rocksdb = "0.21"
ruint = { version = "1.12", default-features = false }
rustc_version = "0.4.0"
rustls = "0.23"
secp256k1 = { version = "0.27.0", features = ["recovery", "global-context"] }
Expand Down Expand Up @@ -227,20 +230,21 @@ tokio-stream = "0.1.16"
# We *always* pin the latest version of protocol to disallow accidental changes in the execution logic.
# However, for the historical version of protocol crates, we have lax requirements. Otherwise,
# Bumping a crypto dependency like `boojum` would require us to republish all the historical packages.
circuit_sequencer_api_1_3_3 = { package = "circuit_sequencer_api", version = "0.133" }
circuit_sequencer_api_1_4_0 = { package = "circuit_sequencer_api", version = "0.140" }
circuit_sequencer_api_1_4_1 = { package = "circuit_sequencer_api", version = "0.141" }
circuit_sequencer_api_1_4_2 = { package = "circuit_sequencer_api", version = "0.142" }
circuit_sequencer_api_1_5_0 = { package = "circuit_sequencer_api", version = "=0.150.7" }
crypto_codegen = { package = "zksync_solidity_vk_codegen", version = "=0.30.1" }
kzg = { package = "zksync_kzg", version = "=0.150.7" }
circuit_encodings = { package = "circuit_encodings", version = "=0.150.17" }
circuit_sequencer_api = { package = "circuit_sequencer_api", version = "=0.150.17" }
crypto_codegen = { package = "zksync_solidity_vk_codegen", version = "=0.30.10" }
kzg = { package = "zksync_kzg", version = "=0.150.17" }
zk_evm = { version = "=0.133.0" }
zk_evm_1_3_1 = { package = "zk_evm", version = "0.131.0-rc.2" }
zk_evm_1_3_3 = { package = "zk_evm", version = "0.133" }
zk_evm_1_4_0 = { package = "zk_evm", version = "0.140" }
zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" }
zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" }
zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.17" }

zk_os_forward_system = {package = "forward_system", git="https://github.com/matter-labs/zk_ee", branch = "main" }
zk_ee = { package = "zk_ee", git="https://github.com/matter-labs/zk_ee", branch = "main" }
zk_os_basic_system = { package = "basic_system", git="https://github.com/matter-labs/zk_ee", branch = "main" }
zk_os_system_hooks = { package = "system_hooks", git="https://github.com/matter-labs/zk_ee", branch = "main" }
# New VM; pinned to a specific commit because of instability
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "457d8a7eea9093af9440662e33e598c13ba41633" }

Expand Down Expand Up @@ -313,6 +317,8 @@ zksync_vm_runner = { version = "0.1.0", path = "core/node/vm_runner" }
zksync_external_proof_integration_api = { version = "0.1.0", path = "core/node/external_proof_integration_api" }
zksync_node_test_utils = { version = "0.1.0", path = "core/node/test_utils" }
zksync_state_keeper = { version = "0.1.0", path = "core/node/state_keeper" }
zksync_zkos_state_keeper = { version = "0.1.0", path = "core/node/zkos_state_keeper" }
zksync_zkos_vm_runner = { version = "0.1.0", path = "core/node/zkos_vm_runner" }
zksync_reorg_detector = { version = "0.1.0", path = "core/node/reorg_detector" }
zksync_consistency_checker = { version = "0.1.0", path = "core/node/consistency_checker" }
zksync_metadata_calculator = { version = "0.1.0", path = "core/node/metadata_calculator" }
Expand All @@ -323,3 +329,10 @@ zksync_contract_verification_server = { version = "0.1.0", path = "core/node/con
zksync_node_api_server = { version = "0.1.0", path = "core/node/api_server" }
zksync_base_token_adjuster = { version = "0.1.0", path = "core/node/base_token_adjuster" }
zksync_logs_bloom_backfill = { version = "0.1.0", path = "core/node/logs_bloom_backfill" }

[patch.crates-io]
ark-ff = { git = "https://github.com/arkworks-rs/algebra.git" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra.git" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra.git" }
ark-bn254 = { git = "https://github.com/arkworks-rs/algebra.git" }
ark-std = { git = "https://github.com/arkworks-rs/std/" }
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
**This is a modified version of ZKsync ERA node with experimental support of Zk OS.**

To run the node, use the same instructions as for the original ZKsync ERA node:
```
zkstack containers
zkstack ecosystem init
zkstack server
```

On server start, the wallets listed [here](https://github.com/matter-labs/zksync-era/blob/zkos-dev/core/node/zkos_state_keeper/src/keeper.rs#L188) are funded.
This list can be modified - added wallets are funded on server restart (no regenesis is needed)

Note: The chain id is hardcoded as `37`, as this value is hardcoded on the Zk OS side.

**TODOs and missing features:**

**XL**:
* Gas and pubdata price are hardcoded and/or ignored (zksync-era and zk_ee)
* `estimate_gas` returns `u32::MAX` instead of running the transaction
* mempool transactions are not filtered
* Tracing is not implemented (zksync-era and zk_ee)
* Tree is not persisted and is rebuilt on every start. We need a persistent implementation (zksync-era)

**L**:
* Current binary is not compatible with the original ZKsync ERA node - we need to support both systems, passing the target mode as binary parameter (zksync-era)
* L1 Batch and Miniblock header are missing multiple fields. Need to go through them and decide what meaning they have (L, zksync-era and zk_ee)
*
**M**:
* Genesis is commented out - we need to figure out what's expected there (zksync-era)
* `zk_ee` [requires](https://github.com/matter-labs/zk_ee/blob/main/forward_system/src/run/tree.rs#L9) `'static` for storage provide - currently `RefCell` is used to satisfy it (zksync-era and zk_ee)
* Make the error format and conditinos in `eth_call` compatible with Ethereum (zksync-era and zk_ee)
* Transaction replacement is not supported (M, zksync-era)

**S**:
* we clone the whole tree in state keeper - at least use RefCell instead (zksync-era)


# ZKsync Era: A ZK Rollup For Scaling Ethereum

[![Logo](eraLogo.png)](https://zksync.io/)
Expand Down
1 change: 1 addition & 0 deletions ZkStack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: zk
l1_network: Localhost
link_to_code: .
bellman_cuda_dir: null
chains: ./chains
config: ./configs/
default_chain: era
Expand Down
2 changes: 1 addition & 1 deletion chains/era/ZkStack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: 1
name: era
chain_id: 271
chain_id: 37
prover_version: NoProofs
configs: ./chains/era/configs/
rocks_db_path: ./chains/era/db/
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct Cli {
/// Comma-separated list of components to launch.
#[arg(
long,
default_value = "api,tree,eth,state_keeper,housekeeper,commitment_generator,da_dispatcher,vm_runner_protective_reads"
default_value = "api,state_keeper"
)]
components: ComponentsToRun,
/// Path to the yaml config. If set, it will be used instead of env vars.
Expand Down
44 changes: 8 additions & 36 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use zksync_node_framework::{
},
service::{ZkStackService, ZkStackServiceBuilder},
};
use zksync_node_framework::implementations::layers::zkos_state_keeper::ZkOsStateKeeperLayer;
use zksync_types::{
pubdata_da::PubdataSendingMode, settlement::SettlementMode, SHARED_BRIDGE_ETHER_TOKEN_ADDRESS,
};
Expand Down Expand Up @@ -234,46 +235,15 @@ impl MainNodeBuilder {
}

fn add_state_keeper_layer(mut self) -> anyhow::Result<Self> {
// Bytecode compression is currently mandatory for the transactions processed by the sequencer.
const OPTIONAL_BYTECODE_COMPRESSION: bool = false;

let wallets = self.wallets.clone();
//todo: this currently adds zkos state keeper. Consider introducing a separate component for it.
let sk_config = try_load_config!(self.configs.state_keeper_config);
let persistence_layer = OutputHandlerLayer::new(
self.contracts_config.l2_legacy_shared_bridge_addr,
sk_config.l2_block_seal_queue_capacity,
)
.with_protective_reads_persistence_enabled(sk_config.protective_reads_persistence_enabled);
let mempool_io_layer = MempoolIOLayer::new(
self.genesis_config.l2_chain_id,
sk_config.clone(),
let db_config = try_load_config!(self.configs.db_config);

let state_keeper_layer = ZkOsStateKeeperLayer::new(
try_load_config!(self.configs.mempool_config),
try_load_config!(wallets.state_keeper),
self.contracts_config.l2_da_validator_addr,
self.genesis_config.l1_batch_commit_data_generator_mode,
);
let db_config = try_load_config!(self.configs.db_config);
let experimental_vm_config = self
.configs
.experimental_vm_config
.clone()
.unwrap_or_default();
let main_node_batch_executor_builder_layer =
MainBatchExecutorLayer::new(sk_config.save_call_traces, OPTIONAL_BYTECODE_COMPRESSION)
.with_fast_vm_mode(experimental_vm_config.state_keeper_fast_vm_mode);

let rocksdb_options = RocksdbStorageOptions {
block_cache_capacity: db_config
.experimental
.state_keeper_db_block_cache_capacity(),
max_open_files: db_config.experimental.state_keeper_db_max_open_files,
};
let state_keeper_layer =
StateKeeperLayer::new(db_config.state_keeper_db_path, rocksdb_options);

self.node
.add_layer(persistence_layer)
.add_layer(mempool_io_layer)
.add_layer(main_node_batch_executor_builder_layer)
.add_layer(state_keeper_layer);
Ok(self)
}
Expand Down Expand Up @@ -738,10 +708,12 @@ impl MainNodeBuilder {
self = self.add_contract_verification_api_layer()?;
}
Component::Tree => {
anyhow::bail!("Tree component is not supposed for Zk Os");
let with_tree_api = components.contains(&Component::TreeApi);
self = self.add_metadata_calculator_layer(with_tree_api)?;
}
Component::TreeApi => {
unreachable!("Tree component is not supposed for Zk Os");
anyhow::ensure!(
components.contains(&Component::Tree),
"Merkle tree API cannot be started without a tree component"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading