From 39ea23f22a3440ff036e4a7f7d193d42828bb311 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 15 Jan 2025 11:54:20 +0100 Subject: [PATCH 1/6] re-added zkos --- Cargo.lock | 394 +++++++++++++++++++++++++++- Cargo.toml | 1 + crates/cli/src/cli.rs | 5 + crates/config/src/config.rs | 9 + crates/core/Cargo.toml | 10 + crates/core/src/lib.rs | 1 + crates/core/src/node/zkos.rs | 479 ++++++++++++++++++++++++++++++++++- rust-toolchain.toml | 2 +- 8 files changed, 887 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f1e8f29..03035ffb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,12 @@ dependencies = [ "gimli", ] +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "adler2" version = "2.0.0" @@ -38,6 +44,18 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -47,6 +65,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "alloy-consensus" version = "0.5.4" @@ -471,12 +495,14 @@ dependencies = [ "anyhow", "async-trait", "backon", + "basic_system", "chrono", "colored", "ethabi 16.0.0", "ethers", "eyre", "flate2", + "forward_system", "futures 0.3.31", "hex", "httptest", @@ -486,9 +512,11 @@ dependencies = [ "maplit", "once_cell", "reqwest 0.11.27", + "ruint", "rustc-hash 1.1.0", "serde", "serde_json", + "system_hooks", "tempdir", "test-case", "thiserror", @@ -496,7 +524,9 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "zk_ee", "zksync-web3-rs", + "zksync_basic_types", "zksync_contracts", "zksync_multivm", "zksync_types", @@ -520,6 +550,38 @@ version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +[[package]] +name = "ark-bn254" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d69eab57e8d2663efa5c63135b2af4f396d66424f88954c21104125ab6b3e6bc" +dependencies = [ + "ark-ec", + "ark-ff 0.5.0", + "ark-std 0.5.0", +] + +[[package]] +name = "ark-ec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d68f2d516162846c1238e755a7c4d131b892b70cc70c471a8e3ca3ed818fce" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-poly", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.2", + "itertools 0.13.0", + "num-bigint", + "num-integer", + "num-traits", + "zeroize", +] + [[package]] name = "ark-ff" version = "0.3.0" @@ -558,6 +620,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ark-ff" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a177aba0ed1e0fbb62aa9f6d0502e9b46dad8c2eab04c14258a1212d2557ea70" +dependencies = [ + "ark-ff-asm 0.5.0", + "ark-ff-macros 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "arrayvec 0.7.6", + "digest 0.10.7", + "educe", + "itertools 0.13.0", + "num-bigint", + "num-traits", + "paste", + "zeroize", +] + [[package]] name = "ark-ff-asm" version = "0.3.0" @@ -578,6 +660,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-asm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" +dependencies = [ + "quote", + "syn 2.0.89", +] + [[package]] name = "ark-ff-macros" version = "0.3.0" @@ -603,6 +695,34 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09be120733ee33f7693ceaa202ca41accd5653b779563608f1234f78ae07c4b3" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "ark-poly" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579305839da207f02b89cd1679e50e67b4331e2f9294a57693e5051b7703fe27" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.2", +] + [[package]] name = "ark-serialize" version = "0.3.0" @@ -624,6 +744,30 @@ dependencies = [ "num-bigint", ] +[[package]] +name = "ark-serialize" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f4d068aaf107ebcd7dfb52bc748f8030e0fc930ac8e360146ca54c1203088f7" +dependencies = [ + "ark-serialize-derive", + "ark-std 0.5.0", + "arrayvec 0.7.6", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "ark-std" version = "0.3.0" @@ -644,6 +788,16 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "ark-std" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246a225cc6131e9ee4f24619af0f19d67761fff15d7ccc22e42b80846e69449a" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -873,6 +1027,51 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "basic_bootloader" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", + "crypto", + "either", + "evm_interpreter", + "hex", + "iwasm_ee", + "iwasm_interpreter", + "ruint", + "seq-macro", + "system_hooks", + "zk_ee", +] + +[[package]] +name = "basic_system" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "arrayvec 0.7.6", + "cfg-if", + "const_for", + "crypto", + "either", + "evm_interpreter", + "hex", + "iwasm_ee", + "iwasm_interpreter", + "miniz_nostd_compression", + "ruint", + "secp256k1 0.1.0", + "serde", + "storage_models", + "system_hooks", + "zk_ee", +] + [[package]] name = "bech32" version = "0.9.1" @@ -901,6 +1100,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bindgen" version = "0.69.5" @@ -1453,6 +1661,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const_for" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c50fcfdf972929aff202c16b80086aa3cfc6a3a820af714096c58c7c1d0582" + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -1555,6 +1769,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "blake2", + "k256 0.13.4", + "p256", + "sha2 0.10.8", + "sha3 0.10.8", +] + [[package]] name = "crypto-bigint" version = "0.4.9" @@ -1839,6 +2065,18 @@ dependencies = [ "spki 0.7.3", ] +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "either" version = "1.13.0" @@ -1930,6 +2168,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "enum_dispatch" version = "0.3.13" @@ -2340,6 +2598,19 @@ dependencies = [ "yansi 0.5.1", ] +[[package]] +name = "evm_interpreter" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", + "crypto", + "either", + "hex", + "ruint", + "zk_ee", +] + [[package]] name = "eyre" version = "0.6.12" @@ -2475,6 +2746,26 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "forward_system" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", + "basic_bootloader", + "basic_system", + "bincode", + "crypto", + "either", + "evm_interpreter", + "hex", + "ruint", + "seq-macro", + "serde", + "system_hooks", + "zk_ee", +] + [[package]] name = "fs2" version = "0.4.3" @@ -2805,6 +3096,7 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ + "allocator-api2", "foldhash", "serde", ] @@ -3448,6 +3740,36 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "iwasm_ee" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", + "crypto", + "iwasm_interpreter", + "iwasm_specification", + "ruint", + "zk_ee", +] + +[[package]] +name = "iwasm_interpreter" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", +] + +[[package]] +name = "iwasm_specification" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "num-derive", + "num-traits", +] + [[package]] name = "jni" version = "0.19.0" @@ -3932,6 +4254,14 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_nostd_compression" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "adler", +] + [[package]] name = "miniz_oxide" version = "0.8.0" @@ -4043,6 +4373,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -5664,6 +6005,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "secp256k1" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "cfg-if", + "const_for", + "crypto", +] + [[package]] name = "secp256k1" version = "0.27.0" @@ -5862,6 +6213,12 @@ dependencies = [ "uuid 1.11.0", ] +[[package]] +name = "seq-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" + [[package]] name = "serde" version = "1.0.215" @@ -6210,6 +6567,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "storage_models" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", + "either", + "ruint", + "zk_ee", +] + [[package]] name = "string_cache" version = "0.8.7" @@ -6385,6 +6753,16 @@ dependencies = [ "libc", ] +[[package]] +name = "system_hooks" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "crypto", + "ruint", + "zk_ee", +] + [[package]] name = "tap" version = "1.0.1" @@ -7728,6 +8106,20 @@ dependencies = [ "zstd", ] +[[package]] +name = "zk_ee" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +dependencies = [ + "arrayvec 0.7.6", + "bitflags 2.6.0", + "cfg-if", + "crypto", + "derivative", + "ruint", + "serde", +] + [[package]] name = "zk_evm" version = "0.131.0-rc.2" @@ -8042,7 +8434,7 @@ dependencies = [ "blake2", "hex", "rand 0.8.5", - "secp256k1", + "secp256k1 0.27.0", "serde", "serde_json", "sha2 0.10.8", diff --git a/Cargo.toml b/Cargo.toml index ca9c3040..0d59a25d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ categories = ["cryptography"] ######################### zksync_multivm = { git = "https://github.com/matter-labs/zksync-era.git", rev = "core-v25.4.0" } zksync_contracts = { git = "https://github.com/matter-labs/zksync-era.git", rev = "core-v25.4.0" } +zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "core-v25.4.0" } zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "core-v25.4.0" } zksync_vm_interface = { git = "https://github.com/matter-labs/zksync-era.git", rev = "core-v25.4.0" } zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev = "core-v25.4.0", features = [ diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 9fb70feb..a4a11549 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -166,6 +166,10 @@ pub struct Cli { /// Enables EVM emulation. Requires local system contracts. pub emulate_evm: bool, + #[arg(long, help_heading = "System Configuration")] + /// Enables zkos (experimental). + pub use_zkos: bool, + // Logging Configuration #[arg(long, help_heading = "Logging Configuration")] /// Log level (default: info). @@ -444,6 +448,7 @@ impl Cli { .set_config_out(self.config_out) .with_host(self.host) .with_evm_emulator(if self.emulate_evm { Some(true) } else { None }) + .with_zkos(if self.use_zkos { Some(true) } else { None }) .with_health_check_endpoint(if self.health_check_endpoint { Some(true) } else { diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index e7ceafdb..879d4116 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -515,6 +515,15 @@ impl TestNodeConfig { self } + /// Enable or disable zkos + #[must_use] + pub fn with_zkos(mut self, enable: Option) -> Self { + if let Some(enable) = enable { + self.use_zkos = enable; + } + self + } + /// Get the EVM emulation status pub fn is_evm_emulator_enabled(&self) -> bool { self.use_evm_emulator diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 75bbb313..da155815 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -17,6 +17,7 @@ zksync_multivm.workspace = true zksync_contracts.workspace = true zksync_types.workspace = true zksync_web3_decl.workspace = true +zksync_basic_types.workspace = true anyhow.workspace = true tokio.workspace = true @@ -42,6 +43,15 @@ flate2.workspace = true thiserror.workspace = true async-trait.workspace = true + +# ZK os dependencies + +forward_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} +basic_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} +zk_ee = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} +system_hooks = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} +ruint = { version = "1.12.3", default-features = false, features = ["alloc"]} + [dev-dependencies] maplit.workspace = true ethers.workspace = true diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 674fdf15..a8f95a5a 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(allocator_api)] //! anvil-zksync //! //! The `anvil-zksync` crate provides an in-memory node designed primarily for local testing. diff --git a/crates/core/src/node/zkos.rs b/crates/core/src/node/zkos.rs index 6f53ce98..f2058300 100644 --- a/crates/core/src/node/zkos.rs +++ b/crates/core/src/node/zkos.rs @@ -1,31 +1,438 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - //! Interfaces that use zkos for VM execution. //! This is still experimental code. +use std::{alloc::Global, collections::HashMap, vec}; + +use basic_system::basic_system::simple_growable_storage::TestingTree; +use forward_system::run::{ + test_impl::{InMemoryPreimageSource, InMemoryTree, TxListSource}, + PreimageType, StorageCommitment, +}; +use ruint::aliases::B160; +use system_hooks::addresses_constants::{ + NOMINAL_TOKEN_BALANCE_STORAGE_ADDRESS, NONCE_HOLDER_HOOK_ADDRESS, +}; +use zk_ee::{common_structs::derive_flat_storage_key, utils::Bytes32}; use zksync_multivm::{ interface::{ storage::{StoragePtr, WriteStorage}, - L1BatchEnv, SystemEnv, VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, + ExecutionResult, InspectExecutionMode, L1BatchEnv, PushTransactionResult, SystemEnv, + TxExecutionMode, VmExecutionLogs, VmExecutionResultAndLogs, VmInterface, + VmInterfaceHistoryEnabled, VmRevertReason, }, vm_latest::TracerPointer, HistoryMode, }; -use zksync_types::{Address, StorageKey, Transaction}; +use zksync_types::{ + address_to_h256, web3::keccak256, AccountTreeId, Address, StorageKey, StorageLog, + StorageLogWithPreviousValue, Transaction, H160, H256, +}; use crate::deps::InMemoryStorage; +// Helper methods for different convertions. +pub fn bytes32_to_h256(data: Bytes32) -> H256 { + H256::from(data.as_u8_array_ref()) +} + +pub fn h256_to_bytes32(data: &H256) -> Bytes32 { + Bytes32::from(data.as_fixed_bytes().clone()) +} + +pub fn b160_to_h160(data: B160) -> H160 { + H160::from_slice(&data.to_be_bytes_vec()) +} + +pub fn pad_to_word(input: &Vec) -> Vec { + let mut data = input.clone(); + let remainder = input.len().div_ceil(32) * 32 - input.len(); + for _ in 0..remainder { + data.push(0u8); + } + data +} + +pub fn h160_to_b160(data: &H160) -> B160 { + B160::from_be_bytes(data.as_fixed_bytes().clone()) +} + +// Helper methods to add data to the Vec in the format expected by ZKOS. +pub fn append_address(data: &mut Vec, address: &H160) { + let mut pp = vec![0u8; 32]; + let ap1 = address.as_fixed_bytes(); + for i in 0..20 { + pp[i + 12] = ap1[i]; + } + data.append(&mut pp); +} + +pub fn append_u256(data: &mut Vec, payload: &zksync_types::U256) { + let mut pp = [0u8; 32]; + payload.to_big_endian(&mut pp); + + data.append(&mut pp.to_vec()); +} +pub fn append_u64(data: &mut Vec, payload: u64) { + let mut pp = [0u8; 32]; + let pp1 = payload.to_be_bytes(); + for i in 0..8 { + pp[24 + i] = pp1[i]; + } + data.append(&mut pp.to_vec()); +} + +pub fn append_usize(data: &mut Vec, payload: usize) { + let mut pp = [0u8; 32]; + let pp1 = payload.to_be_bytes(); + for i in 0..8 { + pp[24 + i] = pp1[i]; + } + data.append(&mut pp.to_vec()); +} + +/// Iterates over raw storage and creates a tree from it. +pub fn create_tree_from_full_state( + raw_storage: &InMemoryStorage, +) -> (InMemoryTree, InMemoryPreimageSource) { + let original_state = &raw_storage.state; + let mut tree = InMemoryTree { + storage_tree: TestingTree::new_in(Global), + cold_storage: HashMap::new(), + }; + let mut preimage_source = InMemoryPreimageSource { + inner: HashMap::new(), + }; + + for entry in original_state { + let kk = derive_flat_storage_key( + &h160_to_b160(entry.0.address()), + &h256_to_bytes32(entry.0.key()), + ); + let vv = h256_to_bytes32(entry.1); + + tree.storage_tree.insert(&kk, &vv); + tree.cold_storage.insert(kk, vv); + } + + for entry in &raw_storage.factory_deps { + preimage_source.inner.insert( + ( + PreimageType::Bytecode(zk_ee::system::ExecutionEnvironmentType::EVM), + h256_to_bytes32(entry.0), + ), + entry.1.clone(), + ); + } + (tree, preimage_source) +} + +pub fn add_elem_to_tree(tree: &mut InMemoryTree, k: &StorageKey, v: &H256) { + let kk = derive_flat_storage_key(&h160_to_b160(k.address()), &h256_to_bytes32(k.key())); + let vv = h256_to_bytes32(v); + + tree.storage_tree.insert(&kk, &vv); + tree.cold_storage.insert(kk, vv); +} + +// Serialize Transaction to ZKOS format. +// Should match the code in basic_bootloader/src/bootloader/transaction/mod.rs +pub fn transaction_to_zkos_vec(tx: &Transaction) -> Vec { + let mut tx_raw: Vec = vec![]; + let tx_type_id = match tx.tx_format() { + zksync_types::l2::TransactionType::LegacyTransaction => 0u8, + zksync_types::l2::TransactionType::EIP2930Transaction => 1u8, + zksync_types::l2::TransactionType::EIP1559Transaction => 2u8, + zksync_types::l2::TransactionType::EIP712Transaction => todo!(), + zksync_types::l2::TransactionType::PriorityOpTransaction => todo!(), + zksync_types::l2::TransactionType::ProtocolUpgradeTransaction => todo!(), + }; + let common_data = match &tx.common_data { + zksync_types::ExecuteTransactionCommon::L1(_) => todo!(), + zksync_types::ExecuteTransactionCommon::L2(l2_tx_common_data) => l2_tx_common_data, + zksync_types::ExecuteTransactionCommon::ProtocolUpgrade(_) => todo!(), + }; + // tx_type + tx_raw.append(&mut vec![0u8; 31]); + tx_raw.append(&mut vec![tx_type_id; 1]); + + // from + append_address(&mut tx_raw, &common_data.initiator_address); + // to + append_address( + &mut tx_raw, + &tx.execute.contract_address.unwrap_or(H160::zero()), + ); + + let gas_limit = common_data.fee.gas_limit; + // gas limit + append_u256(&mut tx_raw, &gas_limit); + // gas per pubdata limit + append_u256(&mut tx_raw, &common_data.fee.gas_per_pubdata_limit); + + let fee_per_gas = common_data.fee.max_fee_per_gas; + + // max fee per gas + append_u256(&mut tx_raw, &fee_per_gas); + // max priority fee per gas. + // hack for legacy tx (verify!!) + append_u256(&mut tx_raw, &common_data.fee.max_priority_fee_per_gas); + + // paymaster + append_u64(&mut tx_raw, 0); + + // nonce + append_u64(&mut tx_raw, common_data.nonce.0.into()); + + append_u256(&mut tx_raw, &tx.execute.value); + + let mut reserved = [0u64; 4]; + + // Should check chain_id + if tx_type_id == 0 { + reserved[0] = 1; + } + + if tx.execute.contract_address.is_none() { + reserved[1] = 1; + } + + for i in 0..4 { + // reserved + append_u64(&mut tx_raw, reserved[i]); + } + + let signature_u256 = common_data.signature.len().div_ceil(32) as u64; + + let execute_calldata_words = tx.execute.calldata.len().div_ceil(32) as u64; + + let mut current_offset = 19; + + // data offset + append_u64(&mut tx_raw, current_offset * 32); + // lent + current_offset += 1 + execute_calldata_words; + // signature offset (stupid -- this doesn't include the padding!!) + append_u64(&mut tx_raw, current_offset * 32); + current_offset += 1 + signature_u256; + + // factory deps + append_u64(&mut tx_raw, current_offset * 32); + current_offset += 1; + // paymater + append_u64(&mut tx_raw, current_offset * 32); + current_offset += 1; + // reserved + append_u64(&mut tx_raw, current_offset * 32); + + // len - data. + append_usize(&mut tx_raw, tx.execute.calldata.len()); + tx_raw.append(&mut pad_to_word(&tx.execute.calldata)); + + // len - signature. + append_usize(&mut tx_raw, common_data.signature.len()); + tx_raw.append(&mut pad_to_word(&common_data.signature)); + + // factory deps + append_u64(&mut tx_raw, 0); + // paymater + append_u64(&mut tx_raw, 0); + // reserved + append_u64(&mut tx_raw, 0); + tx_raw +} + +pub fn execute_tx_in_zkos( + tx: &Transaction, + tree: &InMemoryTree, + preimage_source: &InMemoryPreimageSource, + storage: &mut StoragePtr, + simulate_only: bool, + batch_env: &L1BatchEnv, +) -> VmExecutionResultAndLogs { + let batch_context = basic_system::basic_system::BasicBlockMetadataFromOracle { + // TODO: get fee from batch_env. + eip1559_basefee: ruint::aliases::U256::from(if simulate_only { 0u64 } else { 1000u64 }), + ergs_price: ruint::aliases::U256::from(1u64), + block_number: batch_env.number.0 as u64, + timestamp: batch_env.timestamp, + gas_per_pubdata: ruint::aliases::U256::from(1u64), + }; + + let storage_commitment = StorageCommitment { + root: *tree.storage_tree.root(), + next_free_slot: tree.storage_tree.next_free_slot, + }; + + let tx_raw = transaction_to_zkos_vec(tx); + + let (output, dynamic_factory_deps, storage_logs) = if simulate_only { + ( + forward_system::run::simulate_tx( + tx_raw, + storage_commitment, + batch_context, + tree.clone(), + preimage_source.clone(), + ) + .unwrap(), + Default::default(), // dynamic factory deps + vec![], // storage logs + ) + } else { + let tx_source = TxListSource { + transactions: vec![tx_raw].into(), + }; + let batch_output = forward_system::run::run_batch( + batch_context, + storage_commitment, + // FIXME + tree.clone(), + preimage_source.clone(), + tx_source, + ) + .unwrap(); + + let mut storage_ptr = storage.borrow_mut(); + + let mut storage_logs = vec![]; + + // apply storage writes.. + for write in batch_output.storage_writes { + let storage_key = StorageKey::new( + AccountTreeId::new(Address::from_slice(&write.account.to_be_bytes_vec())), + H256::from(write.account_key.as_u8_array_ref()), + ); + let storage_value = H256::from(write.value.as_u8_array_ref()); + let prev_value = storage_ptr.set_value(storage_key, storage_value); + + let storage_log = StorageLog { + // FIXME - should distinguish between initial write and repeated write. + kind: zksync_types::StorageLogKind::InitialWrite, + key: storage_key, + value: storage_value, + }; + storage_logs.push(StorageLogWithPreviousValue { + log: storage_log, + previous_value: prev_value, + }); + } + let mut f_deps = HashMap::new(); + + for factory_dep in batch_output.published_preimages { + f_deps.insert(bytes32_to_h256(factory_dep.0), factory_dep.1); + } + + (batch_output.tx_results[0].clone(), f_deps, storage_logs) + }; + + let tx_output = match output.as_ref() { + Ok(tx_output) => match &tx_output.execution_result { + forward_system::run::ExecutionResult::Success(output) => match &output { + forward_system::run::ExecutionOutput::Call(data) => data, + forward_system::run::ExecutionOutput::Create(data, _) => data, + }, + forward_system::run::ExecutionResult::Revert(data) => { + return VmExecutionResultAndLogs { + result: ExecutionResult::Revert { + output: VmRevertReason::General { + msg: "Transaction reverted".to_string(), + data: data.clone(), + }, + }, + logs: Default::default(), + statistics: Default::default(), + refunds: Default::default(), + dynamic_factory_deps: Default::default(), + } + } + }, + Err(invalid_tx) => { + return VmExecutionResultAndLogs { + result: ExecutionResult::Revert { + output: VmRevertReason::General { + msg: format!("{:?}", invalid_tx), + data: vec![], + }, + }, + logs: Default::default(), + statistics: Default::default(), + refunds: Default::default(), + dynamic_factory_deps: Default::default(), + } + } + }; + + VmExecutionResultAndLogs { + result: ExecutionResult::Success { + output: tx_output.clone(), + }, + logs: VmExecutionLogs { + storage_logs, + events: Default::default(), + user_l2_to_l1_logs: Default::default(), + system_l2_to_l1_logs: Default::default(), + total_log_queries_count: Default::default(), + }, + statistics: Default::default(), + refunds: Default::default(), + dynamic_factory_deps, + } +} + pub fn zkos_get_nonce_key(account: &Address) -> StorageKey { - todo!() + let nonce_manager = AccountTreeId::new(b160_to_h160(NONCE_HOLDER_HOOK_ADDRESS)); + + // The `minNonce` (used as nonce for EOAs) is stored in a mapping inside the `NONCE_HOLDER` system contract + let key = address_to_h256(account); + + StorageKey::new(nonce_manager, key) +} + +pub fn zkos_key_for_eth_balance(address: &Address) -> H256 { + address_to_h256(address) +} + +/// Create a `key` part of `StorageKey` to access the balance from ERC20 contract balances +fn zkos_key_for_erc20_balance(address: &Address) -> H256 { + let address_h256 = address_to_h256(address); + + // 20 bytes address first gets aligned to 32 bytes with index of `balanceOf` storage slot + // of default ERC20 contract and to then to 64 bytes. + let slot_index = H256::from_low_u64_be(51); + let mut bytes = [0_u8; 64]; + bytes[..32].copy_from_slice(address_h256.as_bytes()); + bytes[32..].copy_from_slice(slot_index.as_bytes()); + H256(keccak256(&bytes)) +} + +pub fn zkos_storage_key_for_standard_token_balance( + token_contract: AccountTreeId, + address: &Address, +) -> StorageKey { + // We have different implementation of the standard ERC20 contract and native + // eth contract. The key for the balance is different for each. + let key = if token_contract.address() == &b160_to_h160(NOMINAL_TOKEN_BALANCE_STORAGE_ADDRESS) { + zkos_key_for_eth_balance(address) + } else { + zkos_key_for_erc20_balance(address) + }; + + StorageKey::new(token_contract, key) } pub fn zkos_storage_key_for_eth_balance(address: &Address) -> StorageKey { - todo!(); + zkos_storage_key_for_standard_token_balance( + AccountTreeId::new(b160_to_h160(NOMINAL_TOKEN_BALANCE_STORAGE_ADDRESS)), + address, + ) } pub struct ZKOsVM { pub storage: StoragePtr, - + pub tree: InMemoryTree, + preimage: InMemoryPreimageSource, + transactions: Vec, + execution_mode: TxExecutionMode, + batch_env: L1BatchEnv, _phantom: std::marker::PhantomData, } @@ -36,12 +443,26 @@ impl ZKOsVM { storage: StoragePtr, raw_storage: &InMemoryStorage, ) -> Self { - todo!() + let execution_mode = system_env.execution_mode; + let (tree, preimage) = { create_tree_from_full_state(raw_storage) }; + // TODO: get chain_id from system_env and pass to ZKOS. + ZKOsVM { + storage, + tree, + preimage, + transactions: vec![], + execution_mode, + batch_env, + _phantom: Default::default(), + } } /// If any keys are updated in storage externally, but not reflected in internal tree. pub fn update_inconsistent_keys(&mut self, inconsistent_nodes: &[&StorageKey]) { - todo!() + for key in inconsistent_nodes { + let value = self.storage.borrow_mut().read_value(key); + add_elem_to_tree(&mut self.tree, key, &value); + } } } @@ -77,7 +498,10 @@ impl VmInterface for ZKOsVM { &mut self, tx: Transaction, ) -> zksync_multivm::interface::PushTransactionResult<'_> { - todo!() + self.transactions.push(tx); + PushTransactionResult { + compressed_bytecodes: Default::default(), + } } fn inspect( @@ -85,7 +509,38 @@ impl VmInterface for ZKOsVM { _dispatcher: &mut Self::TracerDispatcher, execution_mode: zksync_multivm::interface::InspectExecutionMode, ) -> VmExecutionResultAndLogs { - todo!() + if let InspectExecutionMode::Bootloader = execution_mode { + return VmExecutionResultAndLogs { + result: ExecutionResult::Success { output: vec![] }, + logs: Default::default(), + statistics: Default::default(), + refunds: Default::default(), + dynamic_factory_deps: Default::default(), + }; + } + let simulate_only = match self.execution_mode { + TxExecutionMode::VerifyExecute => false, + TxExecutionMode::EstimateFee => true, + TxExecutionMode::EthCall => true, + }; + + // For now we only support one transaction. + assert_eq!( + 1, + self.transactions.len(), + "only one tx per batch supported for now" + ); + + // TODO: add support for multiple transactions. + let tx = self.transactions[0].clone(); + execute_tx_in_zkos( + &tx, + &self.tree, + &self.preimage, + &mut self.storage, + simulate_only, + &self.batch_env, + ) } fn start_new_l2_block(&mut self, _l2_block_env: zksync_multivm::interface::L2BlockEnv) { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 73cb934d..d456bdf6 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "stable" +channel = "nightly-2024-11-12" components = ["rustfmt", "clippy"] From b0370e457714e89e14de45169a8261fa127d0f78 Mon Sep 17 00:00:00 2001 From: Marcin M <128217157+mm-zk@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:45:59 +0100 Subject: [PATCH 2/6] added chain id, and proper gas refund (#540) --- Cargo.lock | 35 +++++++++++++---------- crates/core/Cargo.toml | 14 +++++++--- crates/core/src/node/zkos.rs | 54 ++++++++++++++++++++++++++---------- 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03035ffb..0b7651ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1030,7 +1030,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basic_bootloader" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", "crypto", @@ -1048,7 +1048,7 @@ dependencies = [ [[package]] name = "basic_system" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "ark-bn254", "ark-ec", @@ -1772,11 +1772,13 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "blake2", "k256 0.13.4", + "modexp", "p256", + "ripemd", "sha2 0.10.8", "sha3 0.10.8", ] @@ -2601,12 +2603,11 @@ dependencies = [ [[package]] name = "evm_interpreter" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", "crypto", "either", - "hex", "ruint", "zk_ee", ] @@ -2749,7 +2750,7 @@ dependencies = [ [[package]] name = "forward_system" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", "basic_bootloader", @@ -3743,7 +3744,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "iwasm_ee" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", "crypto", @@ -3756,7 +3757,7 @@ dependencies = [ [[package]] name = "iwasm_interpreter" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", ] @@ -3764,7 +3765,7 @@ dependencies = [ [[package]] name = "iwasm_specification" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "num-derive", "num-traits", @@ -4257,7 +4258,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_nostd_compression" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "adler", ] @@ -4283,6 +4284,11 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "modexp" +version = "1.0.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" + [[package]] name = "multimap" version = "0.10.0" @@ -6008,7 +6014,7 @@ dependencies = [ [[package]] name = "secp256k1" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "cfg-if", "const_for", @@ -6570,7 +6576,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "storage_models" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", "either", @@ -6756,9 +6762,10 @@ dependencies = [ [[package]] name = "system_hooks" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "crypto", + "evm_interpreter", "ruint", "zk_ee", ] @@ -8109,7 +8116,7 @@ dependencies = [ [[package]] name = "zk_ee" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=zkos_anvil_v241217#5aa07d27ab201ee6bbcfbfc39991737acc2dbd8b" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" dependencies = [ "arrayvec 0.7.6", "bitflags 2.6.0", diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index da155815..82233575 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -46,10 +46,16 @@ async-trait.workspace = true # ZK os dependencies -forward_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} -basic_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} -zk_ee = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} -system_hooks = { git = "https://github.com/matter-labs/zk_ee.git", branch = "zkos_anvil_v241217"} +forward_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} +basic_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} +zk_ee = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} +system_hooks = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} + +#forward_system = { path = "../../../zk_ee/forward_system" } +#basic_system = { path = "../../../zk_ee/basic_system" } +#zk_ee = { path = "../../../zk_ee/zk_ee" } +#system_hooks = { path = "../../../zk_ee/system_hooks" } + ruint = { version = "1.12.3", default-features = false, features = ["alloc"]} [dev-dependencies] diff --git a/crates/core/src/node/zkos.rs b/crates/core/src/node/zkos.rs index f2058300..c28560b9 100644 --- a/crates/core/src/node/zkos.rs +++ b/crates/core/src/node/zkos.rs @@ -15,16 +15,16 @@ use zk_ee::{common_structs::derive_flat_storage_key, utils::Bytes32}; use zksync_multivm::{ interface::{ storage::{StoragePtr, WriteStorage}, - ExecutionResult, InspectExecutionMode, L1BatchEnv, PushTransactionResult, SystemEnv, - TxExecutionMode, VmExecutionLogs, VmExecutionResultAndLogs, VmInterface, + ExecutionResult, InspectExecutionMode, L1BatchEnv, PushTransactionResult, Refunds, + SystemEnv, TxExecutionMode, VmExecutionLogs, VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmRevertReason, }, vm_latest::TracerPointer, HistoryMode, }; use zksync_types::{ - address_to_h256, web3::keccak256, AccountTreeId, Address, StorageKey, StorageLog, - StorageLogWithPreviousValue, Transaction, H160, H256, + address_to_h256, web3::keccak256, AccountTreeId, Address, ExecuteTransactionCommon, StorageKey, + StorageLog, StorageLogWithPreviousValue, Transaction, H160, H256, U256, }; use crate::deps::InMemoryStorage; @@ -247,6 +247,7 @@ pub fn execute_tx_in_zkos( storage: &mut StoragePtr, simulate_only: bool, batch_env: &L1BatchEnv, + chain_id: u64, ) -> VmExecutionResultAndLogs { let batch_context = basic_system::basic_system::BasicBlockMetadataFromOracle { // TODO: get fee from batch_env. @@ -255,6 +256,7 @@ pub fn execute_tx_in_zkos( block_number: batch_env.number.0 as u64, timestamp: batch_env.timestamp, gas_per_pubdata: ruint::aliases::U256::from(1u64), + chain_id, }; let storage_commitment = StorageCommitment { @@ -262,7 +264,22 @@ pub fn execute_tx_in_zkos( next_free_slot: tree.storage_tree.next_free_slot, }; - let tx_raw = transaction_to_zkos_vec(tx); + let mut tx = tx.clone(); + if simulate_only { + // Currently zkos doesn't do validation when running a simulated transaction. + // This results in lower gas estimation - which might cause issues for the user. + const ZKOS_EXPECTED_VALIDATION_COST: u64 = 6_000; + let new_gas_limit = tx + .gas_limit() + .saturating_sub(U256::from(ZKOS_EXPECTED_VALIDATION_COST)); + match &mut tx.common_data { + ExecuteTransactionCommon::L1(data) => data.gas_limit = new_gas_limit, + ExecuteTransactionCommon::L2(data) => data.fee.gas_limit = new_gas_limit, + ExecuteTransactionCommon::ProtocolUpgrade(data) => data.gas_limit = new_gas_limit, + }; + } + + let tx_raw = transaction_to_zkos_vec(&tx); let (output, dynamic_factory_deps, storage_logs) = if simulate_only { ( @@ -324,11 +341,13 @@ pub fn execute_tx_in_zkos( (batch_output.tx_results[0].clone(), f_deps, storage_logs) }; - let tx_output = match output.as_ref() { + let (tx_output, gas_refunded) = match output.as_ref() { Ok(tx_output) => match &tx_output.execution_result { forward_system::run::ExecutionResult::Success(output) => match &output { - forward_system::run::ExecutionOutput::Call(data) => data, - forward_system::run::ExecutionOutput::Create(data, _) => data, + forward_system::run::ExecutionOutput::Call(data) => (data, tx_output.gas_refunded), + forward_system::run::ExecutionOutput::Create(data, _) => { + (data, tx_output.gas_refunded) + } }, forward_system::run::ExecutionResult::Revert(data) => { return VmExecutionResultAndLogs { @@ -340,7 +359,10 @@ pub fn execute_tx_in_zkos( }, logs: Default::default(), statistics: Default::default(), - refunds: Default::default(), + refunds: Refunds { + gas_refunded: tx_output.gas_refunded, + operator_suggested_refund: tx_output.gas_refunded, + }, dynamic_factory_deps: Default::default(), } } @@ -373,7 +395,10 @@ pub fn execute_tx_in_zkos( total_log_queries_count: Default::default(), }, statistics: Default::default(), - refunds: Default::default(), + refunds: Refunds { + gas_refunded, + operator_suggested_refund: gas_refunded, + }, dynamic_factory_deps, } } @@ -431,7 +456,7 @@ pub struct ZKOsVM { pub tree: InMemoryTree, preimage: InMemoryPreimageSource, transactions: Vec, - execution_mode: TxExecutionMode, + system_env: SystemEnv, batch_env: L1BatchEnv, _phantom: std::marker::PhantomData, } @@ -443,15 +468,13 @@ impl ZKOsVM { storage: StoragePtr, raw_storage: &InMemoryStorage, ) -> Self { - let execution_mode = system_env.execution_mode; let (tree, preimage) = { create_tree_from_full_state(raw_storage) }; - // TODO: get chain_id from system_env and pass to ZKOS. ZKOsVM { storage, tree, preimage, transactions: vec![], - execution_mode, + system_env, batch_env, _phantom: Default::default(), } @@ -518,7 +541,7 @@ impl VmInterface for ZKOsVM { dynamic_factory_deps: Default::default(), }; } - let simulate_only = match self.execution_mode { + let simulate_only = match self.system_env.execution_mode { TxExecutionMode::VerifyExecute => false, TxExecutionMode::EstimateFee => true, TxExecutionMode::EthCall => true, @@ -540,6 +563,7 @@ impl VmInterface for ZKOsVM { &mut self.storage, simulate_only, &self.batch_env, + self.system_env.chain_id.as_u64(), ) } From 92dad63a0671b12f1a4bad7268f8c9a45fb7a93f Mon Sep 17 00:00:00 2001 From: Marcin M <128217157+mm-zk@users.noreply.github.com> Date: Fri, 17 Jan 2025 08:11:29 +0100 Subject: [PATCH 3/6] feat: [zkos] compute and return the witness (#545) * ugly hacks to return the witness * compute witness correctly * passing zkconfig along * moved zkos into zkos_config * moved zkos namespace to proper place * added docs * put dependency back on main branch --- Cargo.lock | 1226 +++++++++++------ crates/api_decl/src/lib.rs | 1 + crates/api_decl/src/namespaces/mod.rs | 3 +- crates/api_decl/src/namespaces/zkos.rs | 13 + crates/api_server/src/impls/mod.rs | 3 +- crates/api_server/src/impls/zkos.rs | 19 + crates/api_server/src/server.rs | 4 +- crates/cli/src/cli.rs | 10 +- crates/cli/src/main.rs | 2 +- crates/config/src/config.rs | 26 +- crates/config/src/types/mod.rs | 2 + crates/config/src/types/zkos.rs | 14 + crates/core/Cargo.toml | 3 + crates/core/src/node/eth.rs | 4 +- crates/core/src/node/in_memory.rs | 5 +- crates/core/src/node/in_memory_ext.rs | 4 +- crates/core/src/node/inner/in_memory_inner.rs | 25 +- crates/core/src/node/mod.rs | 1 + crates/core/src/node/zkos.rs | 149 +- crates/core/src/system_contracts.rs | 16 +- docs/rustbook/src/usage/experimental-zkos.md | 30 +- 21 files changed, 1030 insertions(+), 530 deletions(-) create mode 100644 crates/api_decl/src/namespaces/zkos.rs create mode 100644 crates/api_server/src/impls/zkos.rs create mode 100644 crates/config/src/types/zkos.rs diff --git a/Cargo.lock b/Cargo.lock index 0b7651ba..c361c7b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,13 +12,28 @@ dependencies = [ "regex", ] +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "cpp_demangle", + "fallible-iterator", + "gimli 0.29.0", + "memmap2", + "object 0.35.0", + "rustc-demangle", + "smallvec", +] + [[package]] name = "addr2line" version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "gimli", + "gimli 0.31.1", ] [[package]] @@ -51,6 +66,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -83,7 +99,7 @@ dependencies = [ "alloy-serde", "auto_impl", "c-kzg", - "derive_more", + "derive_more 1.0.0", "serde", ] @@ -106,7 +122,7 @@ checksum = "64ffc577390ce50234e02d841214b3dc0bea6aaaae8e04bbf3cb82e9a45da9eb" dependencies = [ "alloy-primitives", "alloy-rlp", - "derive_more", + "derive_more 1.0.0", "serde", ] @@ -122,7 +138,7 @@ dependencies = [ "alloy-rlp", "alloy-serde", "c-kzg", - "derive_more", + "derive_more 1.0.0", "once_cell", "serde", "sha2 0.10.8", @@ -138,7 +154,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tracing", ] @@ -160,7 +176,7 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -178,19 +194,18 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6259a506ab13e1d658796c31e6e39d2e2ee89243bcc505ddc613b35732e0a430" +checksum = "ec878088ec6283ce1e90d280316aadd3d6ce3de06ff63d68953c855e7e447e92" dependencies = [ "alloy-rlp", "bytes", "cfg-if", "const-hex", - "derive_more", + "derive_more 1.0.0", "foldhash", "hashbrown 0.15.2", - "hex-literal", - "indexmap 2.6.0", + "indexmap 2.7.0", "itoa", "k256 0.13.4", "keccak-asm", @@ -198,7 +213,7 @@ dependencies = [ "proptest", "rand 0.8.5", "ruint", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "sha3 0.10.8", "tiny-keccak 2.0.2", @@ -206,9 +221,9 @@ dependencies = [ [[package]] name = "alloy-rlp" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0822426598f95e45dd1ea32a738dac057529a709ee645fcc516ffa4cbde08f" +checksum = "3d6c1d995bff8d011f7cd6c81820d51825e6e06d6db73914c1630ecf544d83d6" dependencies = [ "alloy-rlp-derive", "arrayvec 0.7.6", @@ -217,13 +232,13 @@ dependencies = [ [[package]] name = "alloy-rlp-derive" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b09cae092c27b6f1bde952653a22708691802e57bfef4a2973b80bea21efd3f" +checksum = "a40e1ef334153322fd878d07e86af7a529bcb86b2439525920a88eba87bcf943" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -239,7 +254,7 @@ dependencies = [ "alloy-rlp", "alloy-serde", "alloy-sol-types", - "derive_more", + "derive_more 1.0.0", "itertools 0.13.0", "serde", "serde_json", @@ -267,7 +282,7 @@ dependencies = [ "auto_impl", "elliptic-curve 0.13.8", "k256 0.13.4", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -285,61 +300,61 @@ dependencies = [ "coins-bip39 0.12.0", "k256 0.13.4", "rand 0.8.5", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "alloy-sol-macro" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9d64f851d95619233f74b310f12bcf16e0cbc27ee3762b6115c14a84809280a" +checksum = "8d039d267aa5cbb7732fa6ce1fd9b5e9e29368f580f80ba9d7a8450c794de4b2" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] name = "alloy-sol-macro-expander" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bf7ed1574b699f48bf17caab4e6e54c6d12bc3c006ab33d58b1e227c1c3559f" +checksum = "620ae5eee30ee7216a38027dec34e0585c55099f827f92f50d11e3d2d3a4a954" dependencies = [ "alloy-sol-macro-input", "const-hex", "heck", - "indexmap 2.6.0", + "indexmap 2.7.0", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "syn-solidity", "tiny-keccak 2.0.2", ] [[package]] name = "alloy-sol-macro-input" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c02997ccef5f34f9c099277d4145f183b422938ed5322dc57a089fe9b9ad9ee" +checksum = "ad9f7d057e00f8c5994e4ff4492b76532c51ead39353aa2ed63f8c50c0f4d52e" dependencies = [ "const-hex", "dunce", "heck", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "syn-solidity", ] [[package]] name = "alloy-sol-types" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1174cafd6c6d810711b4e00383037bdb458efc4fe3dbafafa16567e0320c54d8" +checksum = "c1382302752cd751efd275f4d6ef65877ddf61e0e6f5ac84ef4302b79a33a31a" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -402,11 +417,12 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "3.0.6" +version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" dependencies = [ "anstyle", + "once_cell", "windows-sys 0.59.0", ] @@ -457,9 +473,9 @@ dependencies = [ "anvil_zksync_types", "anyhow", "hex", - "http 1.1.0", + "http 1.2.0", "jsonrpsee", - "thiserror", + "thiserror 1.0.69", "tokio", "tower 0.4.13", "tower-http", @@ -506,7 +522,7 @@ dependencies = [ "futures 0.3.31", "hex", "httptest", - "indexmap 2.6.0", + "indexmap 2.7.0", "itertools 0.13.0", "lazy_static", "maplit", @@ -519,12 +535,13 @@ dependencies = [ "system_hooks", "tempdir", "test-case", - "thiserror", + "thiserror 1.0.69", "time", "tokio", "tracing", "tracing-subscriber", "zk_ee", + "zkos_api", "zksync-web3-rs", "zksync_basic_types", "zksync_contracts", @@ -546,9 +563,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.93" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" [[package]] name = "ark-bn254" @@ -667,7 +684,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" dependencies = [ "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -705,7 +722,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -765,7 +782,7 @@ checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -844,7 +861,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -855,7 +872,7 @@ checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -877,13 +894,13 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "auto_impl" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +checksum = "e12882f59de5360c748c4cbf569a042d5fb0eb515f7bea9c1f470b47f6ffbd73" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -894,9 +911,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "aws-lc-rs" -version = "1.11.1" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f47bb8cc16b669d267eeccf585aea077d0882f4777b1c1f740217885d6e6e5a3" +checksum = "1ea835662a0af02443aa1396d39be523bbf8f11ee6fad20329607c480bea48c3" dependencies = [ "aws-lc-sys", "paste", @@ -905,16 +922,15 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.23.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2101df3813227bbaaaa0b04cd61c534c7954b22bd68d399b440be937dc63ff7" +checksum = "71b2ddd3ada61a305e1d8bb6c005d1eaa7d14d903681edfc400406d523a9b491" dependencies = [ "bindgen", "cc", "cmake", "dunce", "fs_extra", - "libc", "paste", ] @@ -928,7 +944,7 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "itoa", @@ -940,7 +956,7 @@ dependencies = [ "rustversion", "serde", "sync_wrapper 1.0.2", - "tower 0.5.1", + "tower 0.5.2", "tower-layer", "tower-service", ] @@ -954,7 +970,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "mime", @@ -982,11 +998,11 @@ version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ - "addr2line", + "addr2line 0.24.2", "cfg-if", "libc", "miniz_oxide", - "object", + "object 0.36.7", "rustc-demangle", "windows-targets 0.52.6", ] @@ -1030,7 +1046,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basic_bootloader" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", "crypto", @@ -1048,7 +1064,7 @@ dependencies = [ [[package]] name = "basic_system" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "ark-bn254", "ark-ec", @@ -1089,9 +1105,9 @@ dependencies = [ [[package]] name = "bigdecimal" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f850665a0385e070b64c38d2354e6c104c8479c59868d1e48a0c13ee2c7a1c1" +checksum = "7f31f3af01c5c65a07985c804d3366560e6fa7883d640a122819b14ec327482c" dependencies = [ "autocfg", "libm", @@ -1115,7 +1131,7 @@ version = "0.69.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "cexpr", "clang-sys", "itertools 0.12.1", @@ -1128,7 +1144,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.89", + "syn 2.0.96", "which", ] @@ -1158,9 +1174,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "bitvec" @@ -1215,6 +1231,14 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "blake2s_u32" +version = "0.1.0" +source = "git+https://github.com/matter-labs/air_compiler#5aee5740532670f7ccbbb7a8418ad0c2eae171a7" +dependencies = [ + "unroll", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -1285,6 +1309,12 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +[[package]] +name = "bytemuck" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" + [[package]] name = "byteorder" version = "1.5.0" @@ -1293,9 +1323,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" dependencies = [ "serde", ] @@ -1362,17 +1392,17 @@ checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" dependencies = [ "camino", "cargo-platform", - "semver 1.0.23", + "semver 1.0.24", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "cc" -version = "1.2.1" +version = "1.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" dependencies = [ "jobserver", "libc", @@ -1402,9 +1432,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1451,9 +1481,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.21" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" dependencies = [ "clap_builder", "clap_derive", @@ -1461,9 +1491,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.21" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" dependencies = [ "anstream", "anstyle", @@ -1473,21 +1503,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "cmake" @@ -1511,7 +1541,7 @@ dependencies = [ "k256 0.13.4", "serde", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1527,7 +1557,7 @@ dependencies = [ "k256 0.13.4", "serde", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1543,7 +1573,7 @@ dependencies = [ "pbkdf2 0.12.2", "rand 0.8.5", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1559,7 +1589,7 @@ dependencies = [ "pbkdf2 0.12.2", "rand 0.8.5", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1579,7 +1609,7 @@ dependencies = [ "serde_derive", "sha2 0.10.8", "sha3 0.10.8", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1598,7 +1628,7 @@ dependencies = [ "serde", "sha2 0.10.8", "sha3 0.10.8", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1609,12 +1639,12 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -1689,6 +1719,15 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpp_demangle" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96e58d342ad113c2b878f16d5d034c03be492ae460cdbc02b7f0f2284d310c7d" +dependencies = [ + "cfg-if", +] + [[package]] name = "cpufeatures" version = "0.2.16" @@ -1722,18 +1761,18 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.13" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -1750,18 +1789,18 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" @@ -1772,7 +1811,7 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "blake2", "k256 0.13.4", @@ -1824,7 +1863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501" dependencies = [ "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -1871,11 +1910,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "data-encoding" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +checksum = "0e60eed09d8c01d3cee5b7d30acb059b76614c918fa0f992e0dd6eeb10daad6f" [[package]] name = "debugid" @@ -1884,7 +1937,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" dependencies = [ "serde", - "uuid 1.11.0", + "uuid 1.12.0", ] [[package]] @@ -1928,6 +1981,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "derive_more" version = "1.0.0" @@ -1945,7 +2009,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "unicode-xid", ] @@ -2026,7 +2090,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -2076,7 +2140,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -2187,7 +2251,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -2199,7 +2263,16 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", +] + +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", ] [[package]] @@ -2215,6 +2288,16 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" +dependencies = [ + "env_filter", + "log", +] + [[package]] name = "envy" version = "0.4.2" @@ -2232,12 +2315,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2258,7 +2341,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "sha3 0.10.8", - "thiserror", + "thiserror 1.0.69", "uuid 0.8.2", ] @@ -2273,7 +2356,7 @@ dependencies = [ "serde", "serde_json", "sha3 0.9.1", - "thiserror", + "thiserror 1.0.69", "uint", ] @@ -2290,7 +2373,7 @@ dependencies = [ "serde", "serde_json", "sha3 0.10.8", - "thiserror", + "thiserror 1.0.69", "uint", ] @@ -2396,7 +2479,7 @@ dependencies = [ "pin-project", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -2418,7 +2501,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "syn 2.0.89", + "syn 2.0.96", "toml", "walkdir", ] @@ -2436,7 +2519,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -2462,9 +2545,9 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.89", + "syn 2.0.96", "tempfile", - "thiserror", + "thiserror 1.0.69", "tiny-keccak 2.0.2", "unicode-xid", ] @@ -2478,10 +2561,10 @@ dependencies = [ "chrono", "ethers-core", "reqwest 0.11.27", - "semver 1.0.23", + "semver 1.0.24", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tracing", ] @@ -2505,7 +2588,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tracing", "tracing-futures", @@ -2537,7 +2620,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tokio-tungstenite", "tracing", @@ -2564,7 +2647,7 @@ dependencies = [ "ethers-core", "rand 0.8.5", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", "tracing", ] @@ -2587,12 +2670,12 @@ dependencies = [ "path-slash", "rayon", "regex", - "semver 1.0.23", + "semver 1.0.24", "serde", "serde_json", "solang-parser", "svm-rs", - "thiserror", + "thiserror 1.0.69", "tiny-keccak 2.0.2", "tokio", "tracing", @@ -2603,7 +2686,7 @@ dependencies = [ [[package]] name = "evm_interpreter" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", "crypto", @@ -2622,11 +2705,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fastrlp" @@ -2639,6 +2728,17 @@ dependencies = [ "bytes", ] +[[package]] +name = "fastrlp" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce8dba4714ef14b8274c371879b175aa55b16b30f269663f19d576f380018dc4" +dependencies = [ + "arrayvec 0.7.6", + "auto_impl", + "bytes", +] + [[package]] name = "ff" version = "0.12.1" @@ -2659,6 +2759,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "field" +version = "0.1.0" +source = "git+https://github.com/matter-labs/air_compiler#5aee5740532670f7ccbbb7a8418ad0c2eae171a7" +dependencies = [ + "rand 0.8.5", + "seq-macro", + "serde", +] + [[package]] name = "findshlibs" version = "0.10.2" @@ -2719,9 +2829,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foldhash" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" [[package]] name = "foreign-types" @@ -2750,7 +2860,7 @@ dependencies = [ [[package]] name = "forward_system" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", "basic_bootloader", @@ -2874,7 +2984,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -2955,6 +3065,16 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +dependencies = [ + "fallible-iterator", + "stable_deref_trait", +] + [[package]] name = "gimli" version = "0.31.1" @@ -2963,9 +3083,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "gloo-net" @@ -2982,7 +3102,7 @@ dependencies = [ "pin-project", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -3059,7 +3179,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.6.0", + "indexmap 2.7.0", "slab", "tokio", "tokio-util", @@ -3077,8 +3197,8 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.1.0", - "indexmap 2.6.0", + "http 1.2.0", + "indexmap 2.7.0", "slab", "tokio", "tokio-util", @@ -3091,6 +3211,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "hashbrown" version = "0.15.2" @@ -3138,12 +3264,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hex-literal" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" - [[package]] name = "hmac" version = "0.12.1" @@ -3155,11 +3275,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3186,9 +3306,9 @@ dependencies = [ [[package]] name = "http" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" dependencies = [ "bytes", "fnv", @@ -3213,7 +3333,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http 1.2.0", ] [[package]] @@ -3224,7 +3344,7 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "pin-project-lite", ] @@ -3253,7 +3373,7 @@ dependencies = [ "form_urlencoded", "futures 0.3.31", "http 0.2.12", - "hyper 0.14.31", + "hyper 0.14.32", "log", "once_cell", "regex", @@ -3271,9 +3391,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.31" +version = "0.14.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" dependencies = [ "bytes", "futures-channel", @@ -3295,15 +3415,15 @@ dependencies = [ [[package]] name = "hyper" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" +checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0" dependencies = [ "bytes", "futures-channel", "futures-util", "h2 0.4.7", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "httparse", "httpdate", @@ -3322,7 +3442,7 @@ checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http 0.2.12", - "hyper 0.14.31", + "hyper 0.14.32", "rustls 0.21.12", "tokio", "tokio-rustls 0.24.1", @@ -3330,19 +3450,19 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.3" +version = "0.27.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" dependencies = [ "futures-util", - "http 1.1.0", - "hyper 1.5.1", + "http 1.2.0", + "hyper 1.5.2", "hyper-util", "log", - "rustls 0.23.19", + "rustls 0.23.21", "rustls-pki-types", "tokio", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "tower-service", ] @@ -3352,7 +3472,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" dependencies = [ - "hyper 1.5.1", + "hyper 1.5.2", "hyper-util", "pin-project-lite", "tokio", @@ -3366,7 +3486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.31", + "hyper 0.14.32", "native-tls", "tokio", "tokio-native-tls", @@ -3380,7 +3500,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.5.1", + "hyper 1.5.2", "hyper-util", "native-tls", "tokio", @@ -3397,9 +3517,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", - "hyper 1.5.1", + "hyper 1.5.2", "pin-project-lite", "socket2", "tokio", @@ -3545,7 +3665,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -3590,7 +3710,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" dependencies = [ - "parity-scale-codec 3.7.0", + "parity-scale-codec 3.6.12", ] [[package]] @@ -3628,7 +3748,7 @@ checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -3649,15 +3769,37 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown 0.15.2", "serde", ] +[[package]] +name = "inferno" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692eda1cc790750b9f5a5e3921ef9c117fd5498b97cfacbc910693e5b29002dc" +dependencies = [ + "ahash", + "clap", + "crossbeam-channel", + "crossbeam-utils", + "dashmap", + "env_logger 0.11.6", + "indexmap 2.7.0", + "itoa", + "log", + "num-format", + "once_cell", + "quick-xml", + "rgb", + "str_stack", +] + [[package]] name = "inout" version = "0.1.3" @@ -3744,7 +3886,7 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "iwasm_ee" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", "crypto", @@ -3757,7 +3899,7 @@ dependencies = [ [[package]] name = "iwasm_interpreter" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", ] @@ -3765,7 +3907,7 @@ dependencies = [ [[package]] name = "iwasm_specification" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "num-derive", "num-traits", @@ -3781,7 +3923,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.69", "walkdir", ] @@ -3802,10 +3944,11 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.72" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -3837,16 +3980,16 @@ dependencies = [ "futures-channel", "futures-util", "gloo-net", - "http 1.1.0", + "http 1.2.0", "jsonrpsee-core", "pin-project", - "rustls 0.23.19", + "rustls 0.23.21", "rustls-pki-types", "rustls-platform-verifier", "soketto", - "thiserror", + "thiserror 1.0.69", "tokio", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "tokio-util", "tracing", "url", @@ -3864,7 +4007,7 @@ dependencies = [ "bytes", "futures-timer", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "jsonrpsee-types", @@ -3874,7 +4017,7 @@ dependencies = [ "rustc-hash 1.1.0", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tokio-stream", "tracing", @@ -3890,16 +4033,16 @@ dependencies = [ "async-trait", "base64 0.22.1", "http-body 1.0.1", - "hyper 1.5.1", - "hyper-rustls 0.27.3", + "hyper 1.5.2", + "hyper-rustls 0.27.5", "hyper-util", "jsonrpsee-core", "jsonrpsee-types", - "rustls 0.23.19", + "rustls 0.23.21", "rustls-platform-verifier", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tower 0.4.13", "tracing", @@ -3916,7 +4059,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -3927,10 +4070,10 @@ checksum = "654afab2e92e5d88ebd8a39d6074483f3f2bfdf91c5ac57fe285e7127cdd4f51" dependencies = [ "anyhow", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.1", + "hyper 1.5.2", "hyper-util", "jsonrpsee-core", "jsonrpsee-types", @@ -3939,7 +4082,7 @@ dependencies = [ "serde", "serde_json", "soketto", - "thiserror", + "thiserror 1.0.69", "tokio", "tokio-stream", "tokio-util", @@ -3954,10 +4097,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c465fbe385238e861fdc4d1c85e04ada6c1fd246161d26385c1b311724d2af" dependencies = [ "beef", - "http 1.1.0", + "http 1.2.0", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -3977,7 +4120,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c28759775f5cb2f1ea9667672d3fe2b0e701d1f4b7b67954e60afe7fd058b5e" dependencies = [ - "http 1.1.0", + "http 1.2.0", "jsonrpsee-client-transport", "jsonrpsee-core", "jsonrpsee-types", @@ -4087,15 +4230,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.166" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -4113,15 +4256,15 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "libc", ] [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "litemap" @@ -4141,9 +4284,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" [[package]] name = "logos" @@ -4165,7 +4308,7 @@ dependencies = [ "proc-macro2", "quote", "regex-syntax 0.6.29", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -4220,6 +4363,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" +dependencies = [ + "libc", +] + [[package]] name = "miette" version = "5.10.0" @@ -4228,7 +4380,7 @@ checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" dependencies = [ "miette-derive", "once_cell", - "thiserror", + "thiserror 1.0.69", "unicode-width", ] @@ -4240,7 +4392,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -4258,27 +4410,26 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_nostd_compression" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "adler", ] [[package]] name = "miniz_oxide" -version = "0.8.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924" dependencies = [ "adler2", ] [[package]] name = "mio" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ - "hermit-abi 0.3.9", "libc", "wasi", "windows-sys 0.52.0", @@ -4287,7 +4438,7 @@ dependencies = [ [[package]] name = "modexp" version = "1.0.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" [[package]] name = "multimap" @@ -4328,6 +4479,11 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "non_determinism_source" +version = "0.1.0" +source = "git+https://github.com/matter-labs/air_compiler#5aee5740532670f7ccbbb7a8418ad0c2eae171a7" + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4387,7 +4543,17 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", +] + +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec 0.7.6", + "itoa", ] [[package]] @@ -4469,7 +4635,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -4481,7 +4647,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -4495,11 +4661,24 @@ dependencies = [ [[package]] name = "object" -version = "0.36.5" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" +dependencies = [ + "flate2", + "memchr", + "ruzstd 0.6.0", +] + +[[package]] +name = "object" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" dependencies = [ + "flate2", "memchr", + "ruzstd 0.7.3", ] [[package]] @@ -4545,7 +4724,7 @@ version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "cfg-if", "foreign-types", "libc", @@ -4562,7 +4741,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -4594,7 +4773,7 @@ dependencies = [ "js-sys", "once_cell", "pin-project-lite", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -4617,9 +4796,9 @@ checksum = "ad31e9de44ee3538fb9d64fe3376c1362f406162434609e79aea2a41a0af78ab" dependencies = [ "async-trait", "bytes", - "http 1.1.0", + "http 1.2.0", "opentelemetry", - "reqwest 0.12.9", + "reqwest 0.12.12", ] [[package]] @@ -4630,14 +4809,14 @@ checksum = "6b925a602ffb916fb7421276b86756027b37ee708f9dce2dbdcc51739f07e727" dependencies = [ "async-trait", "futures-core", - "http 1.1.0", + "http 1.2.0", "opentelemetry", "opentelemetry-http", "opentelemetry-proto", "opentelemetry_sdk", "prost 0.13.4", - "reqwest 0.12.9", - "thiserror", + "reqwest 0.12.12", + "thiserror 1.0.69", "tokio", "tonic", ] @@ -4676,7 +4855,7 @@ dependencies = [ "percent-encoding", "rand 0.8.5", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tokio-stream", ] @@ -4687,6 +4866,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "oracle_provider" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" +dependencies = [ + "ringbuffer", + "risc_v_simulator", + "zk_ee", +] + [[package]] name = "ordered-float" version = "2.10.1" @@ -4698,9 +4887,9 @@ dependencies = [ [[package]] name = "os_info" -version = "3.8.2" +version = "3.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" +checksum = "6e6520c8cc998c5741ee68ec1dc369fc47e5f0ea5320018ecf2a1ccd6328f48b" dependencies = [ "log", "serde", @@ -4741,16 +4930,15 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.7.0" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be4817d39f3272f69c59fe05d0535ae6456c2dc2fa1ba02910296c7e0a5c590" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" dependencies = [ "arrayvec 0.7.6", "bitvec 1.0.1", "byte-slice-cast", "impl-trait-for-tuples", - "parity-scale-codec-derive 3.7.0", - "rustversion", + "parity-scale-codec-derive 3.6.12", "serde", ] @@ -4768,14 +4956,14 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.7.0" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8781a75c6205af67215f382092b6e0a4ff3734798523e69073d4bcd294ec767b" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.89", + "syn 1.0.109", ] [[package]] @@ -4872,12 +5060,12 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" +checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror", + "thiserror 2.0.11", "ucd-trie", ] @@ -4888,7 +5076,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.6.0", + "indexmap 2.7.0", ] [[package]] @@ -4903,35 +5091,35 @@ dependencies = [ [[package]] name = "phf" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ "phf_macros", - "phf_shared 0.11.2", + "phf_shared 0.11.3", ] [[package]] name = "phf_generator" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" dependencies = [ - "phf_shared 0.11.2", + "phf_shared 0.11.3", "rand 0.8.5", ] [[package]] name = "phf_macros" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" dependencies = [ "phf_generator", - "phf_shared 0.11.2", + "phf_shared 0.11.3", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -4940,43 +5128,43 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" dependencies = [ - "siphasher", + "siphasher 0.3.11", ] [[package]] name = "phf_shared" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ - "siphasher", + "siphasher 1.0.1", ] [[package]] name = "pin-project" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" +checksum = "1e2ec53ad785f4d35dac0adea7f7dc6f1bb277ad84a680c7afefeae05d1f5916" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" +checksum = "d56a66c0c55993aa927429d0f8a0abfd74f084e4d9c192cffed01e418d83eefb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" @@ -5010,6 +5198,17 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "poseidon2" +version = "0.1.0" +source = "git+https://github.com/matter-labs/air_compiler#5aee5740532670f7ccbbb7a8418ad0c2eae171a7" +dependencies = [ + "field", + "non_determinism_source", + "rand 0.8.5", + "unroll", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -5043,12 +5242,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.25" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac" dependencies = [ "proc-macro2", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -5125,14 +5324,14 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -5157,7 +5356,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -5168,7 +5367,7 @@ checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.6.0", + "bitflags 2.8.0", "lazy_static", "num-traits", "rand 0.8.5", @@ -5217,7 +5416,7 @@ dependencies = [ "prost 0.12.6", "prost-types", "regex", - "syn 2.0.89", + "syn 2.0.96", "tempfile", ] @@ -5231,7 +5430,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -5244,7 +5443,7 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -5284,7 +5483,7 @@ dependencies = [ "prost-reflect", "prost-types", "protox-parse", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -5296,7 +5495,7 @@ dependencies = [ "logos", "miette", "prost-types", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -5314,11 +5513,20 @@ dependencies = [ "byteorder", ] +[[package]] +name = "quick-xml" +version = "0.37.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "165859e9e55f79d67b96c5d96f4e88b6f2695a1972849c15a6a3f5c59fc2c003" +dependencies = [ + "memchr", +] + [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -5434,11 +5642,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", ] [[package]] @@ -5449,7 +5657,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -5519,7 +5727,7 @@ dependencies = [ "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", - "hyper 0.14.31", + "hyper 0.14.32", "hyper-rustls 0.24.2", "hyper-tls 0.5.0", "ipnet", @@ -5551,9 +5759,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.9" +version = "0.12.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" +checksum = "43e734407157c3c2034e0258f5e4473ddb361b1e85f95a66690d67264d7cd1da" dependencies = [ "base64 0.22.1", "bytes", @@ -5562,11 +5770,11 @@ dependencies = [ "futures-core", "futures-util", "h2 0.4.7", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.1", - "hyper-rustls 0.27.3", + "hyper 1.5.2", + "hyper-rustls 0.27.5", "hyper-tls 0.6.0", "hyper-util", "ipnet", @@ -5585,6 +5793,7 @@ dependencies = [ "system-configuration 0.6.1", "tokio", "tokio-native-tls", + "tower 0.5.2", "tower-service", "url", "wasm-bindgen", @@ -5614,6 +5823,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "rgb" +version = "0.8.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.16.20" @@ -5644,6 +5862,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ringbuffer" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df6368f71f205ff9c33c076d170dd56ebf68e8161c733c0caa07a7a5509ed53" + [[package]] name = "ripemd" version = "0.1.3" @@ -5653,6 +5877,22 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "risc_v_simulator" +version = "0.1.0" +source = "git+https://github.com/matter-labs/air_compiler#5aee5740532670f7ccbbb7a8418ad0c2eae171a7" +dependencies = [ + "addr2line 0.22.0", + "blake2s_u32", + "field", + "inferno", + "memmap2", + "object 0.36.7", + "poseidon2", + "rand 0.8.5", + "ringbuffer", +] + [[package]] name = "rlp" version = "0.5.2" @@ -5683,18 +5923,20 @@ checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" [[package]] name = "ruint" -version = "1.12.3" +version = "1.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c3cc4c2511671f327125da14133d0c5c5d137f006a1017a16f557bc85b16286" +checksum = "f5ef8fb1dd8de3870cb8400d51b4c2023854bbafd5431a3ac7e7317243e22d2f" dependencies = [ "alloy-rlp", "ark-ff 0.3.0", "ark-ff 0.4.2", "bytes", - "fastrlp", + "fastrlp 0.3.1", + "fastrlp 0.4.0", "num-bigint", + "num-integer", "num-traits", - "parity-scale-codec 3.7.0", + "parity-scale-codec 3.6.12", "primitive-types 0.12.2", "proptest", "rand 0.8.5", @@ -5725,9 +5967,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc-hash" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" [[package]] name = "rustc-hex" @@ -5750,20 +5992,20 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.23", + "semver 1.0.24", ] [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5780,9 +6022,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.19" +version = "0.23.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" +checksum = "8f287924602bf649d949c63dc8ac8b235fa5387d394020705b80c4eb597ce5b8" dependencies = [ "aws-lc-rs", "log", @@ -5827,9 +6069,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37" [[package]] name = "rustls-platform-verifier" @@ -5842,7 +6084,7 @@ dependencies = [ "jni", "log", "once_cell", - "rustls 0.23.19", + "rustls 0.23.21", "rustls-native-certs", "rustls-platform-verifier-android", "rustls-webpki 0.102.8", @@ -5882,9 +6124,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" [[package]] name = "rusty-fork" @@ -5898,6 +6140,26 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "ruzstd" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5174a470eeb535a721ae9fdd6e291c2411a906b96592182d05217591d5c5cf7b" +dependencies = [ + "byteorder", + "derive_more 0.99.18", + "twox-hash", +] + +[[package]] +name = "ruzstd" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad02996bfc73da3e301efe90b1837be9ed8f4a462b6ed410aa35d00381de89f" +dependencies = [ + "twox-hash", +] + [[package]] name = "ryu" version = "1.0.18" @@ -5929,8 +6191,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "346a3b32eba2640d17a9cb5927056b08f3de90f65b72fe09402c2ad07d684d0b" dependencies = [ "cfg-if", - "derive_more", - "parity-scale-codec 3.7.0", + "derive_more 1.0.0", + "parity-scale-codec 3.6.12", "scale-info-derive", ] @@ -5943,7 +6205,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -6014,7 +6276,7 @@ dependencies = [ [[package]] name = "secp256k1" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "cfg-if", "const_for", @@ -6054,7 +6316,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "core-foundation", "core-foundation-sys", "libc", @@ -6064,9 +6326,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.1" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" dependencies = [ "core-foundation-sys", "libc", @@ -6083,9 +6345,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" dependencies = [ "serde", ] @@ -6213,10 +6475,10 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "time", "url", - "uuid 1.11.0", + "uuid 1.12.0", ] [[package]] @@ -6227,9 +6489,9 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -6246,20 +6508,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] name = "serde_json" -version = "1.0.133" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" dependencies = [ "itoa", "memchr", @@ -6317,7 +6579,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.0", "itoa", "ryu", "serde", @@ -6458,13 +6720,13 @@ dependencies = [ [[package]] name = "simple_asn1" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb" dependencies = [ "num-bigint", "num-traits", - "thiserror", + "thiserror 2.0.11", "time", ] @@ -6474,6 +6736,12 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "slab" version = "0.4.9" @@ -6491,9 +6759,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" dependencies = [ "libc", "windows-sys 0.52.0", @@ -6501,14 +6769,14 @@ dependencies = [ [[package]] name = "soketto" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37468c595637c10857701c990f93a40ce0e357cedb0953d1c26c8d8027f9bb53" +checksum = "2e859df029d160cb88608f5d7df7fb4753fd20fdfb4de5644f3d8b8440841721" dependencies = [ "base64 0.22.1", "bytes", "futures 0.3.31", - "http 1.1.0", + "http 1.2.0", "httparse", "log", "rand 0.8.5", @@ -6525,7 +6793,7 @@ dependencies = [ "lalrpop", "lalrpop-util", "phf", - "thiserror", + "thiserror 1.0.69", "unicode-xid", ] @@ -6576,7 +6844,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "storage_models" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", "either", @@ -6584,6 +6852,12 @@ dependencies = [ "zk_ee", ] +[[package]] +name = "str_stack" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" + [[package]] name = "string_cache" version = "0.8.7" @@ -6628,7 +6902,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -6648,11 +6922,11 @@ dependencies = [ "hex", "once_cell", "reqwest 0.11.27", - "semver 1.0.23", + "semver 1.0.24", "serde", "serde_json", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", "url", "zip", ] @@ -6670,9 +6944,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.89" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -6681,14 +6955,14 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219389c1ebe89f8333df8bdfb871f6631c552ff399c23cac02480b6088aad8f0" +checksum = "b84e4d83a0a6704561302b917a932484e1cae2d8c6354c64be8b7bac1c1fe057" dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -6714,7 +6988,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -6734,7 +7008,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "core-foundation", "system-configuration-sys 0.6.0", ] @@ -6762,7 +7036,7 @@ dependencies = [ [[package]] name = "system_hooks" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "crypto", "evm_interpreter", @@ -6788,12 +7062,13 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.14.0" +version = "3.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" dependencies = [ "cfg-if", "fastrand", + "getrandom", "once_cell", "rustix", "windows-sys 0.59.0", @@ -6837,7 +7112,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -6848,7 +7123,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "test-case-core", ] @@ -6858,7 +7133,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +dependencies = [ + "thiserror-impl 2.0.11", ] [[package]] @@ -6869,7 +7153,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", ] [[package]] @@ -6893,9 +7188,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.36" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa", @@ -6916,9 +7211,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" dependencies = [ "num-conv", "time-core", @@ -6954,9 +7249,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +checksum = "022db8904dfa342efe721985167e9fcd16c29b226db4397ed752a761cfce81e8" dependencies = [ "tinyvec_macros", ] @@ -6969,9 +7264,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.1" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" dependencies = [ "backtrace", "bytes", @@ -6988,13 +7283,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -7019,20 +7314,19 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ - "rustls 0.23.19", - "rustls-pki-types", + "rustls 0.23.21", "tokio", ] [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -7057,9 +7351,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" dependencies = [ "bytes", "futures-core", @@ -7096,7 +7390,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.0", "toml_datetime", "winnow 0.5.40", ] @@ -7107,11 +7401,11 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.0", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.20", + "winnow 0.6.24", ] [[package]] @@ -7126,10 +7420,10 @@ dependencies = [ "base64 0.22.1", "bytes", "h2 0.4.7", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.1", + "hyper 1.5.2", "hyper-timeout", "hyper-util", "percent-encoding", @@ -7166,14 +7460,15 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", "pin-project-lite", - "sync_wrapper 0.1.2", + "sync_wrapper 1.0.2", + "tokio", "tower-layer", "tower-service", ] @@ -7184,9 +7479,9 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "bytes", - "http 1.1.0", + "http 1.2.0", "pin-project-lite", "tower-layer", "tower-service", @@ -7224,7 +7519,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -7278,9 +7573,9 @@ dependencies = [ [[package]] name = "tracing-serde" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" dependencies = [ "serde", "tracing-core", @@ -7288,9 +7583,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ "matchers", "nu-ansi-term", @@ -7329,11 +7624,21 @@ dependencies = [ "rand 0.8.5", "rustls 0.21.12", "sha1", - "thiserror", + "thiserror 1.0.69", "url", "utf-8", ] +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "static_assertions", +] + [[package]] name = "typenum" version = "1.17.0" @@ -7391,6 +7696,16 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "unroll" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ad948c1cb799b1a70f836077721a92a35ac177d4daddf4c20a633786d4cf618" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "unsafe-libyaml" version = "0.2.11" @@ -7411,9 +7726,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.10.1" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" dependencies = [ "base64 0.22.1", "log", @@ -7470,18 +7785,18 @@ dependencies = [ [[package]] name = "uuid" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" +checksum = "744018581f9a3454a9e15beb8a33b017183f1e7c0cd170232a2d1453b23a51c4" dependencies = [ "serde", ] [[package]] name = "valuable" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vcpkg" @@ -7515,7 +7830,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "671d3b894d5d0849f0a597f56bf071f42d4f2a1cbcf2f78ca21f870ab7c0cc2b" dependencies = [ - "hyper 0.14.31", + "hyper 0.14.32", "once_cell", "tokio", "tracing", @@ -7530,7 +7845,7 @@ checksum = "6a511871dc5de990a3b2a0e715facfbc5da848c0c0395597a1415029fb7c250a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -7569,47 +7884,48 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.45" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", + "once_cell", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7617,28 +7933,31 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.72" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -7910,9 +8229,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.20" +version = "0.6.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" dependencies = [ "memchr", ] @@ -7952,7 +8271,7 @@ dependencies = [ "pharos", "rustc_version 0.4.1", "send_wrapper 0.6.0", - "thiserror", + "thiserror 1.0.69", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -8005,7 +8324,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "synstructure", ] @@ -8027,7 +8346,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -8047,7 +8366,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", "synstructure", ] @@ -8068,7 +8387,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -8090,7 +8409,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -8116,10 +8435,10 @@ dependencies = [ [[package]] name = "zk_ee" version = "0.1.0" -source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#a2d29abcebd48e9b07407bdb4d856e32bc463efe" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" dependencies = [ "arrayvec 0.7.6", - "bitflags 2.6.0", + "bitflags 2.8.0", "cfg-if", "crypto", "derivative", @@ -8247,6 +8566,14 @@ dependencies = [ "zkevm_opcode_defs 0.150.18", ] +[[package]] +name = "zk_os_runner" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" +dependencies = [ + "risc_v_simulator", +] + [[package]] name = "zkevm_opcode_defs" version = "0.131.0" @@ -8265,7 +8592,7 @@ version = "0.132.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0769f7b27d8fb06e715da3290c575cac5d04d10a557faef180e847afce50ac4" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "blake2", "ethereum-types 0.14.1", "k256 0.11.6", @@ -8280,7 +8607,7 @@ version = "0.141.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6be7bd5f0e0b61211f544147289640b4712715589d7f2fe5229d92a7a3ac64c0" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "blake2", "ethereum-types 0.14.1", "k256 0.13.4", @@ -8295,7 +8622,7 @@ version = "0.150.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bad437d4891536fdcc0054a3f04562c408817ff19d83b6c27569217692e6e74" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.8.0", "blake2", "ethereum-types 0.14.1", "k256 0.13.4", @@ -8306,6 +8633,17 @@ dependencies = [ "sha3 0.10.8", ] +[[package]] +name = "zkos_api" +version = "0.1.0" +source = "git+https://github.com/matter-labs/zk_ee.git?branch=main#487662eb1df150aaf4878624a8c04ffed8501969" +dependencies = [ + "forward_system", + "oracle_provider", + "risc_v_simulator", + "zk_os_runner", +] + [[package]] name = "zksync-web3-rs" version = "0.1.1" @@ -8314,7 +8652,7 @@ checksum = "15bc9b106393359ac013c2527db318ced4ca838d26ef03488233af557ebe5da8" dependencies = [ "async-trait", "clap", - "env_logger", + "env_logger 0.10.2", "ethers", "ethers-contract", "hex", @@ -8323,7 +8661,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.9.9", - "thiserror", + "thiserror 1.0.69", "tokio", ] @@ -8344,7 +8682,7 @@ dependencies = [ "serde_with", "sha2 0.10.8", "strum", - "thiserror", + "thiserror 1.0.69", "tiny-keccak 2.0.2", "url", ] @@ -8383,7 +8721,7 @@ dependencies = [ "pin-project", "rand 0.8.5", "sha3 0.10.8", - "thiserror", + "thiserror 1.0.69", "time", "tokio", "tracing", @@ -8414,7 +8752,7 @@ checksum = "723e2a4b056cc5af192a83163c89a6951ee75c098cc5c4a4cdc435f4232d88bd" dependencies = [ "anyhow", "rand 0.8.5", - "thiserror", + "thiserror 1.0.69", "zksync_concurrency", ] @@ -8445,7 +8783,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.69", "zksync_basic_types", ] @@ -8498,7 +8836,7 @@ dependencies = [ "hex", "itertools 0.10.5", "once_cell", - "thiserror", + "thiserror 1.0.69", "tracing", "vise", "zk_evm 0.131.0-rc.2", @@ -8562,7 +8900,7 @@ dependencies = [ "prost-reflect", "protox", "quote", - "syn 2.0.89", + "syn 2.0.96", ] [[package]] @@ -8583,7 +8921,7 @@ dependencies = [ "bigdecimal", "blake2", "chrono", - "derive_more", + "derive_more 1.0.0", "hex", "itertools 0.10.5", "num", @@ -8595,7 +8933,7 @@ dependencies = [ "serde_json", "serde_with", "strum", - "thiserror", + "thiserror 1.0.69", "tracing", "zksync_basic_types", "zksync_contracts", @@ -8614,7 +8952,7 @@ dependencies = [ "anyhow", "futures 0.3.31", "once_cell", - "reqwest 0.12.9", + "reqwest 0.12.12", "serde_json", "sha2 0.10.8", "tokio", @@ -8637,7 +8975,7 @@ dependencies = [ "sentry", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "time", "tokio", "tracing", @@ -8678,7 +9016,7 @@ dependencies = [ "hex", "pretty_assertions", "serde", - "thiserror", + "thiserror 1.0.69", "tracing", "zksync_contracts", "zksync_system_constants", @@ -8696,10 +9034,10 @@ dependencies = [ "jsonrpsee", "pin-project-lite", "rlp", - "rustls 0.23.19", + "rustls 0.23.21", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tracing", "vise", diff --git a/crates/api_decl/src/lib.rs b/crates/api_decl/src/lib.rs index a9e7a295..aa019c02 100644 --- a/crates/api_decl/src/lib.rs +++ b/crates/api_decl/src/lib.rs @@ -2,6 +2,7 @@ mod namespaces; pub use namespaces::{ AnvilNamespaceServer, ConfigNamespaceServer, EthTestNamespaceServer, EvmNamespaceServer, + ZKOSNamespaceServer, }; // Re-export available namespaces from zksync-era diff --git a/crates/api_decl/src/namespaces/mod.rs b/crates/api_decl/src/namespaces/mod.rs index 6e5636d5..680f3df5 100644 --- a/crates/api_decl/src/namespaces/mod.rs +++ b/crates/api_decl/src/namespaces/mod.rs @@ -2,8 +2,9 @@ mod anvil; mod config; mod eth_test; mod evm; +mod zkos; pub use self::{ anvil::AnvilNamespaceServer, config::ConfigNamespaceServer, eth_test::EthTestNamespaceServer, - evm::EvmNamespaceServer, + evm::EvmNamespaceServer, zkos::ZKOSNamespaceServer, }; diff --git a/crates/api_decl/src/namespaces/zkos.rs b/crates/api_decl/src/namespaces/zkos.rs new file mode 100644 index 00000000..dce42e06 --- /dev/null +++ b/crates/api_decl/src/namespaces/zkos.rs @@ -0,0 +1,13 @@ +use jsonrpsee::core::RpcResult; +use jsonrpsee::proc_macros::rpc; + +/// API bindings for the `zkos` experimental namespace. +#[rpc(server, namespace = "zkos")] +pub trait ZKOSNamespace { + /// Returns the witness for a given batch. + /// + /// # Returns + /// Bytes with the witness that can be passed to proving system. + #[method(name = "getWitness")] + async fn get_witness(&self, batch: u32) -> RpcResult>>; +} diff --git a/crates/api_server/src/impls/mod.rs b/crates/api_server/src/impls/mod.rs index 520d0863..317fa30f 100644 --- a/crates/api_server/src/impls/mod.rs +++ b/crates/api_server/src/impls/mod.rs @@ -6,10 +6,11 @@ mod eth_test; mod evm; mod net; mod web3; +mod zkos; mod zks; pub use self::{ anvil::AnvilNamespace, config::ConfigNamespace, debug::DebugNamespace, eth::EthNamespace, eth_test::EthTestNamespace, evm::EvmNamespace, net::NetNamespace, web3::Web3Namespace, - zks::ZksNamespace, + zkos::ZKOSNamespace, zks::ZksNamespace, }; diff --git a/crates/api_server/src/impls/zkos.rs b/crates/api_server/src/impls/zkos.rs new file mode 100644 index 00000000..c0ed659c --- /dev/null +++ b/crates/api_server/src/impls/zkos.rs @@ -0,0 +1,19 @@ +use anvil_zksync_core::node::zkos_get_batch_witness; +use jsonrpsee::core::{async_trait, RpcResult}; + +use anvil_zksync_api_decl::ZKOSNamespaceServer; + +pub struct ZKOSNamespace {} + +impl ZKOSNamespace { + pub fn new() -> Self { + Self {} + } +} + +#[async_trait] +impl ZKOSNamespaceServer for ZKOSNamespace { + async fn get_witness(&self, batch: u32) -> RpcResult>> { + Ok(zkos_get_batch_witness(&batch)) + } +} diff --git a/crates/api_server/src/server.rs b/crates/api_server/src/server.rs index 39488a5d..5fe1577b 100644 --- a/crates/api_server/src/server.rs +++ b/crates/api_server/src/server.rs @@ -1,3 +1,4 @@ +use crate::impls::ZKOSNamespace; use crate::{ AnvilNamespace, ConfigNamespace, DebugNamespace, EthNamespace, EthTestNamespace, EvmNamespace, NetNamespace, Web3Namespace, ZksNamespace, @@ -5,7 +6,7 @@ use crate::{ use anvil_zksync_api_decl::{ AnvilNamespaceServer, ConfigNamespaceServer, DebugNamespaceServer, EthNamespaceServer, EthTestNamespaceServer, EvmNamespaceServer, NetNamespaceServer, Web3NamespaceServer, - ZksNamespaceServer, + ZKOSNamespaceServer, ZksNamespaceServer, }; use anvil_zksync_core::node::InMemoryNode; use http::Method; @@ -58,6 +59,7 @@ impl NodeServerBuilder { rpc.merge(ConfigNamespace::new(node.clone()).into_rpc()) .unwrap(); rpc.merge(ZksNamespace::new(node).into_rpc()).unwrap(); + rpc.merge(ZKOSNamespace::new().into_rpc()).unwrap(); rpc.merge(Web3Namespace.into_rpc()).unwrap(); rpc } diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index a4a11549..d558803a 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -4,7 +4,7 @@ use anvil_zksync_config::constants::{ DEFAULT_DISK_CACHE_DIR, DEFAULT_MNEMONIC, TEST_NODE_NETWORK_ID, }; use anvil_zksync_config::types::{ - AccountGenerator, CacheConfig, CacheType, Genesis, SystemContractsOptions, + AccountGenerator, CacheConfig, CacheType, Genesis, SystemContractsOptions, ZKOSConfig, }; use anvil_zksync_config::TestNodeConfig; use anvil_zksync_core::{ @@ -166,9 +166,9 @@ pub struct Cli { /// Enables EVM emulation. Requires local system contracts. pub emulate_evm: bool, - #[arg(long, help_heading = "System Configuration")] - /// Enables zkos (experimental). - pub use_zkos: bool, + #[clap(flatten)] + /// ZKOS detailed config. + pub zkos_config: ZKOSConfig, // Logging Configuration #[arg(long, help_heading = "Logging Configuration")] @@ -448,7 +448,7 @@ impl Cli { .set_config_out(self.config_out) .with_host(self.host) .with_evm_emulator(if self.emulate_evm { Some(true) } else { None }) - .with_zkos(if self.use_zkos { Some(true) } else { None }) + .with_zkos_config(self.zkos_config) .with_health_check_endpoint(if self.health_check_endpoint { Some(true) } else { diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 94ff9847..156d45e7 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -221,7 +221,7 @@ async fn main() -> anyhow::Result<()> { let system_contracts = SystemContracts::from_options( &config.system_contracts_options, config.use_evm_emulator, - config.use_zkos, + config.zkos_config.clone(), ); let (node_inner, _fork_storage, blockchain, time) = InMemoryNodeInner::init( diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 879d4116..ced30140 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -70,8 +70,8 @@ pub struct TestNodeConfig { pub override_bytecodes_dir: Option, /// Enables EVM emulation mode pub use_evm_emulator: bool, - /// Enables ZKOS mode (experimental) - pub use_zkos: bool, + /// ZKOS configuration + pub zkos_config: ZKOSConfig, /// Optional chain ID for the node pub chain_id: Option, /// L1 gas price (optional override) @@ -157,7 +157,7 @@ impl Default for TestNodeConfig { system_contracts_options: Default::default(), override_bytecodes_dir: None, use_evm_emulator: false, - use_zkos: false, + zkos_config: Default::default(), chain_id: None, // Gas configuration defaults @@ -367,12 +367,22 @@ impl TestNodeConfig { ); tracing::info!( "ZK OS: {}", - if self.use_zkos { + if self.zkos_config.use_zkos { "Enabled".green() } else { "Disabled".red() } ); + if self.zkos_config.use_zkos { + tracing::info!( + "ZK bin: {}", + if let Some(path) = self.zkos_config.zkos_bin_path.as_ref() { + path.green() + } else { + "Not set".red() + } + ); + } println!("\n"); tracing::info!("========================================"); @@ -515,12 +525,10 @@ impl TestNodeConfig { self } - /// Enable or disable zkos + /// ZKOS configuration #[must_use] - pub fn with_zkos(mut self, enable: Option) -> Self { - if let Some(enable) = enable { - self.use_zkos = enable; - } + pub fn with_zkos_config(mut self, config: ZKOSConfig) -> Self { + self.zkos_config = config; self } diff --git a/crates/config/src/types/mod.rs b/crates/config/src/types/mod.rs index 8a44da14..98dacd7a 100644 --- a/crates/config/src/types/mod.rs +++ b/crates/config/src/types/mod.rs @@ -1,12 +1,14 @@ mod account_generator; mod cache; mod genesis; +mod zkos; pub use account_generator::AccountGenerator; pub use cache::{CacheConfig, CacheType}; use clap::ValueEnum; pub use genesis::Genesis; use serde::Deserialize; +pub use zkos::ZKOSConfig; #[derive(Deserialize, Default, Debug, Copy, Clone, PartialEq, ValueEnum)] pub enum SystemContractsOptions { diff --git a/crates/config/src/types/zkos.rs b/crates/config/src/types/zkos.rs new file mode 100644 index 00000000..7d7e41a4 --- /dev/null +++ b/crates/config/src/types/zkos.rs @@ -0,0 +1,14 @@ +use clap::Parser; +use serde::Deserialize; + +/// Genesis +#[derive(Deserialize, Clone, Debug, Parser, Default)] +pub struct ZKOSConfig { + #[arg(long, help_heading = "Experimental Configuration")] + /// Enables zkos (experimental). + pub use_zkos: bool, + + #[arg(long, help_heading = "Experimental Configuration")] + /// Path to zkos binary (if you need to compute witnesses). + pub zkos_bin_path: Option, +} diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 82233575..9414755e 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -50,11 +50,14 @@ forward_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "m basic_system = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} zk_ee = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} system_hooks = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main"} +zkos_api = { git = "https://github.com/matter-labs/zk_ee.git", branch = "main" } #forward_system = { path = "../../../zk_ee/forward_system" } #basic_system = { path = "../../../zk_ee/basic_system" } #zk_ee = { path = "../../../zk_ee/zk_ee" } #system_hooks = { path = "../../../zk_ee/system_hooks" } +#zkos_api = { path = "../../../zk_ee/api" } + ruint = { version = "1.12.3", default-features = false, features = ["alloc"]} diff --git a/crates/core/src/node/eth.rs b/crates/core/src/node/eth.rs index 9de40a91..cbc9fd82 100644 --- a/crates/core/src/node/eth.rs +++ b/crates/core/src/node/eth.rs @@ -177,7 +177,7 @@ impl InMemoryNode { _block: Option, ) -> anyhow::Result { let balance_key = StorageKeyLayout::get_storage_key_for_base_token( - self.system_contracts.use_zkos, + self.system_contracts.use_zkos(), &address, ); @@ -274,7 +274,7 @@ impl InMemoryNode { _block: Option, ) -> anyhow::Result { let inner = self.inner.read().await; - let nonce_key = StorageKeyLayout::get_nonce_key(self.system_contracts.use_zkos, &address); + let nonce_key = StorageKeyLayout::get_nonce_key(self.system_contracts.use_zkos(), &address); match inner.fork_storage.read_value_internal(&nonce_key) { Ok(result) => Ok(h256_to_u64(result).into()), diff --git a/crates/core/src/node/in_memory.rs b/crates/core/src/node/in_memory.rs index 30ced093..f8317246 100644 --- a/crates/core/src/node/in_memory.rs +++ b/crates/core/src/node/in_memory.rs @@ -385,13 +385,14 @@ impl InMemoryNode { let storage = StorageView::new(&inner.fork_storage).into_rc_ptr(); - let mut vm = if self.system_contracts.use_zkos { + let mut vm = if self.system_contracts.use_zkos() { AnvilVM::ZKOs(super::zkos::ZKOsVM::<_, HistoryDisabled>::new( batch_env, system_env, storage, // TODO: this might be causing a deadlock.. check.. &inner.fork_storage.inner.read().unwrap().raw_storage, + &self.system_contracts.zkos_config, )) } else { AnvilVM::ZKSync(Vm::new(batch_env, system_env, storage)) @@ -652,7 +653,7 @@ impl InMemoryNode { let system_contracts = SystemContracts::from_options( &config.system_contracts_options, config.use_evm_emulator, - config.use_zkos, + config.zkos_config.clone(), ); let (inner, _, blockchain, time) = InMemoryNodeInner::init( fork, diff --git a/crates/core/src/node/in_memory_ext.rs b/crates/core/src/node/in_memory_ext.rs index d1193ccc..55bb548b 100644 --- a/crates/core/src/node/in_memory_ext.rs +++ b/crates/core/src/node/in_memory_ext.rs @@ -168,7 +168,7 @@ impl InMemoryNode { pub async fn set_balance(&self, address: Address, balance: U256) -> bool { let writer = self.inner.write().await; let balance_key = StorageKeyLayout::get_storage_key_for_base_token( - self.system_contracts.use_zkos, + self.system_contracts.use_zkos(), &address, ); writer @@ -184,7 +184,7 @@ impl InMemoryNode { pub async fn set_nonce(&self, address: Address, nonce: U256) -> bool { let writer = self.inner.write().await; - let nonce_key = StorageKeyLayout::get_nonce_key(self.system_contracts.use_zkos, &address); + let nonce_key = StorageKeyLayout::get_nonce_key(self.system_contracts.use_zkos(), &address); let enforced_full_nonce = nonces_to_full_nonce(nonce, nonce); tracing::info!( "👷 Nonces for address {:?} have been set to {}", diff --git a/crates/core/src/node/inner/in_memory_inner.rs b/crates/core/src/node/inner/in_memory_inner.rs index 73d947e4..3ff3d534 100644 --- a/crates/core/src/node/inner/in_memory_inner.rs +++ b/crates/core/src/node/inner/in_memory_inner.rs @@ -22,6 +22,7 @@ use crate::system_contracts::SystemContracts; use crate::utils::{bytecode_to_factory_dep, create_debug_output}; use crate::{delegate_vm, formatter, utils}; use anvil_zksync_config::constants::NON_FORK_FIRST_BLOCK_TIMESTAMP; +use anvil_zksync_config::types::ZKOSConfig; use anvil_zksync_config::TestNodeConfig; use anvil_zksync_types::{ShowCalls, ShowGasDetails, ShowStorageLogs, ShowVMDetails}; use colored::Colorize; @@ -555,13 +556,14 @@ impl InMemoryNodeInner { ) -> Vec { let storage = StorageView::new(self.fork_storage.clone()).into_rc_ptr(); - let mut vm = if self.system_contracts.use_zkos { + let mut vm = if self.system_contracts.use_zkos() { AnvilVM::ZKOs(ZKOsVM::<_, HistoryEnabled>::new( batch_env.clone(), system_env, storage.clone(), // TODO: this might be causing a deadlock.. check.. &self.fork_storage.inner.read().unwrap().raw_storage, + &self.system_contracts.zkos_config, )) } else { AnvilVM::ZKSync(Vm::new(batch_env.clone(), system_env, storage.clone())) @@ -827,7 +829,7 @@ impl InMemoryNodeInner { batch_env.clone(), system_env.clone(), &self.fork_storage, - self.system_contracts.use_zkos, + &self.system_contracts.zkos_config, ); if result.statistics.pubdata_published > MAX_VM_PUBDATA_PER_BATCH.try_into().unwrap() { @@ -865,7 +867,7 @@ impl InMemoryNodeInner { batch_env.clone(), system_env.clone(), &self.fork_storage, - self.system_contracts.use_zkos, + &self.system_contracts.zkos_config, ); if estimate_gas_result.result.is_failed() { @@ -897,7 +899,7 @@ impl InMemoryNodeInner { batch_env, system_env, &self.fork_storage, - self.system_contracts.use_zkos, + &self.system_contracts.zkos_config, ); let overhead = derive_overhead( @@ -1012,7 +1014,7 @@ impl InMemoryNodeInner { batch_env: L1BatchEnv, system_env: SystemEnv, fork_storage: &ForkStorage, - is_zkos: bool, + zkos_config: &ZKOSConfig, ) -> VmExecutionResultAndLogs { let tx: Transaction = l2_tx.clone().into(); @@ -1031,7 +1033,8 @@ impl InMemoryNodeInner { // The nonce needs to be updated let nonce = l2_tx.nonce(); - let nonce_key = StorageKeyLayout::get_nonce_key(is_zkos, &l2_tx.initiator_account()); + let nonce_key = + StorageKeyLayout::get_nonce_key(zkos_config.use_zkos, &l2_tx.initiator_account()); let full_nonce = storage.borrow_mut().read_value(&nonce_key); let (_, deployment_nonce) = decompose_full_nonce(h256_to_u256(full_nonce)); let enforced_full_nonce = nonces_to_full_nonce(U256::from(nonce.0), deployment_nonce); @@ -1041,7 +1044,8 @@ impl InMemoryNodeInner { // We need to explicitly put enough balance into the account of the users let payer = l2_tx.payer(); - let balance_key = StorageKeyLayout::get_storage_key_for_base_token(is_zkos, &payer); + let balance_key = + StorageKeyLayout::get_storage_key_for_base_token(zkos_config.use_zkos, &payer); let mut current_balance = h256_to_u256(storage.borrow_mut().read_value(&balance_key)); let added_balance = l2_tx.common_data.fee.gas_limit * l2_tx.common_data.fee.max_fee_per_gas; current_balance += added_balance; @@ -1049,13 +1053,14 @@ impl InMemoryNodeInner { .borrow_mut() .set_value(balance_key, u256_to_h256(current_balance)); - let mut vm = if is_zkos { + let mut vm = if zkos_config.use_zkos { let mut vm = ZKOsVM::<_, HistoryDisabled>::new( batch_env, system_env, storage, // TODO: this might be causing a deadlock.. check.. &fork_storage.inner.read().unwrap().raw_storage, + zkos_config, ); // Temporary hack - as we update the 'storage' just above, but zkos loads its full // state from fork_storage (that is not updated). @@ -1317,7 +1322,7 @@ impl InMemoryNodeInner { /// Adds a lot of tokens to a given account with a specified balance. pub fn set_rich_account(&mut self, address: H160, balance: U256) { let key = StorageKeyLayout::get_storage_key_for_base_token( - self.system_contracts.use_zkos, + self.system_contracts.use_zkos(), &address, ); @@ -1382,7 +1387,7 @@ impl InMemoryNodeInner { let system_contracts = SystemContracts::from_options( &config.system_contracts_options, config.use_evm_emulator, - config.use_zkos, + config.zkos_config.clone(), ); let (inner, _, _, _) = InMemoryNodeInner::init( None, diff --git a/crates/core/src/node/mod.rs b/crates/core/src/node/mod.rs index d435e438..32717844 100644 --- a/crates/core/src/node/mod.rs +++ b/crates/core/src/node/mod.rs @@ -26,3 +26,4 @@ pub use self::{ pub use in_memory::*; pub use inner::{blockchain, fork, node_executor, time}; pub use inner::{InMemoryNodeInner, TxExecutionOutput}; +pub use zkos::zkos_get_batch_witness; diff --git a/crates/core/src/node/zkos.rs b/crates/core/src/node/zkos.rs index c28560b9..f3244f84 100644 --- a/crates/core/src/node/zkos.rs +++ b/crates/core/src/node/zkos.rs @@ -2,6 +2,7 @@ //! This is still experimental code. use std::{alloc::Global, collections::HashMap, vec}; +use anvil_zksync_config::types::ZKOSConfig; use basic_system::basic_system::simple_growable_storage::TestingTree; use forward_system::run::{ test_impl::{InMemoryPreimageSource, InMemoryTree, TxListSource}, @@ -28,6 +29,23 @@ use zksync_types::{ }; use crate::deps::InMemoryStorage; +use once_cell::sync::Lazy; +use std::sync::Mutex; + +static BATCH_WITNESS: Lazy>>> = Lazy::new(|| { + let m = HashMap::new(); + Mutex::new(m) +}); + +pub fn set_batch_witness(key: u32, value: Vec) { + let mut map = BATCH_WITNESS.lock().unwrap(); + map.insert(key, value); +} + +pub fn zkos_get_batch_witness(key: &u32) -> Option> { + let map = BATCH_WITNESS.lock().unwrap(); + map.get(key).cloned() +} // Helper methods for different convertions. pub fn bytes32_to_h256(data: Bytes32) -> H256 { @@ -248,7 +266,9 @@ pub fn execute_tx_in_zkos( simulate_only: bool, batch_env: &L1BatchEnv, chain_id: u64, -) -> VmExecutionResultAndLogs { + // if zkos_path is passed, it will also compute witness. + zkos_path: Option, +) -> (VmExecutionResultAndLogs, Option>) { let batch_context = basic_system::basic_system::BasicBlockMetadataFromOracle { // TODO: get fee from batch_env. eip1559_basefee: ruint::aliases::U256::from(if simulate_only { 0u64 } else { 1000u64 }), @@ -281,6 +301,8 @@ pub fn execute_tx_in_zkos( let tx_raw = transaction_to_zkos_vec(&tx); + let mut witness = None; + let (output, dynamic_factory_deps, storage_logs) = if simulate_only { ( forward_system::run::simulate_tx( @@ -304,10 +326,24 @@ pub fn execute_tx_in_zkos( // FIXME tree.clone(), preimage_source.clone(), - tx_source, + tx_source.clone(), ) .unwrap(); + if let Some(zkos_path) = zkos_path { + let result = zkos_api::run_batch_generate_witness( + batch_context, + tree.clone(), + preimage_source.clone(), + tx_source, + storage_commitment, + &zkos_path, + ); + + witness = Some(result.iter().map(|x| x.to_be_bytes()).flatten().collect()); + //set_batch_witness(batch_env.number.0, witness); + } + let mut storage_ptr = storage.borrow_mut(); let mut storage_logs = vec![]; @@ -350,57 +386,66 @@ pub fn execute_tx_in_zkos( } }, forward_system::run::ExecutionResult::Revert(data) => { - return VmExecutionResultAndLogs { + return ( + VmExecutionResultAndLogs { + result: ExecutionResult::Revert { + output: VmRevertReason::General { + msg: "Transaction reverted".to_string(), + data: data.clone(), + }, + }, + logs: Default::default(), + statistics: Default::default(), + refunds: Refunds { + gas_refunded: tx_output.gas_refunded, + operator_suggested_refund: tx_output.gas_refunded, + }, + dynamic_factory_deps: Default::default(), + }, + witness, + ) + } + }, + Err(invalid_tx) => { + return ( + VmExecutionResultAndLogs { result: ExecutionResult::Revert { output: VmRevertReason::General { - msg: "Transaction reverted".to_string(), - data: data.clone(), + msg: format!("{:?}", invalid_tx), + data: vec![], }, }, logs: Default::default(), statistics: Default::default(), - refunds: Refunds { - gas_refunded: tx_output.gas_refunded, - operator_suggested_refund: tx_output.gas_refunded, - }, + refunds: Default::default(), dynamic_factory_deps: Default::default(), - } - } - }, - Err(invalid_tx) => { - return VmExecutionResultAndLogs { - result: ExecutionResult::Revert { - output: VmRevertReason::General { - msg: format!("{:?}", invalid_tx), - data: vec![], - }, }, - logs: Default::default(), - statistics: Default::default(), - refunds: Default::default(), - dynamic_factory_deps: Default::default(), - } + witness, + ) } }; - VmExecutionResultAndLogs { - result: ExecutionResult::Success { - output: tx_output.clone(), - }, - logs: VmExecutionLogs { - storage_logs, - events: Default::default(), - user_l2_to_l1_logs: Default::default(), - system_l2_to_l1_logs: Default::default(), - total_log_queries_count: Default::default(), - }, - statistics: Default::default(), - refunds: Refunds { - gas_refunded, - operator_suggested_refund: gas_refunded, + ( + VmExecutionResultAndLogs { + result: ExecutionResult::Success { + output: tx_output.clone(), + }, + logs: VmExecutionLogs { + storage_logs, + events: Default::default(), + user_l2_to_l1_logs: Default::default(), + system_l2_to_l1_logs: Default::default(), + total_log_queries_count: Default::default(), + }, + statistics: Default::default(), + refunds: Refunds { + gas_refunded, + operator_suggested_refund: gas_refunded, + }, + dynamic_factory_deps, }, - dynamic_factory_deps, - } + witness, + ) } pub fn zkos_get_nonce_key(account: &Address) -> StorageKey { @@ -458,6 +503,8 @@ pub struct ZKOsVM { transactions: Vec, system_env: SystemEnv, batch_env: L1BatchEnv, + config: ZKOSConfig, + witness: Option>, _phantom: std::marker::PhantomData, } @@ -467,6 +514,7 @@ impl ZKOsVM { system_env: SystemEnv, storage: StoragePtr, raw_storage: &InMemoryStorage, + config: &ZKOSConfig, ) -> Self { let (tree, preimage) = { create_tree_from_full_state(raw_storage) }; ZKOsVM { @@ -476,6 +524,8 @@ impl ZKOsVM { transactions: vec![], system_env, batch_env, + witness: None, + config: config.clone(), _phantom: Default::default(), } } @@ -533,6 +583,15 @@ impl VmInterface for ZKOsVM { execution_mode: zksync_multivm::interface::InspectExecutionMode, ) -> VmExecutionResultAndLogs { if let InspectExecutionMode::Bootloader = execution_mode { + // This is called at the end of seal block. + // Now is the moment to collect the witness and store it. + + // TODO: add support for multiple transactions. + + if let Some(witness) = self.witness.clone() { + set_batch_witness(self.batch_env.number.0, witness); + } + return VmExecutionResultAndLogs { result: ExecutionResult::Success { output: vec![] }, logs: Default::default(), @@ -556,7 +615,7 @@ impl VmInterface for ZKOsVM { // TODO: add support for multiple transactions. let tx = self.transactions[0].clone(); - execute_tx_in_zkos( + let (result, witness) = execute_tx_in_zkos( &tx, &self.tree, &self.preimage, @@ -564,7 +623,11 @@ impl VmInterface for ZKOsVM { simulate_only, &self.batch_env, self.system_env.chain_id.as_u64(), - ) + self.config.zkos_bin_path.clone(), + ); + + self.witness = witness; + result } fn start_new_l2_block(&mut self, _l2_block_env: zksync_multivm::interface::L2BlockEnv) { diff --git a/crates/core/src/system_contracts.rs b/crates/core/src/system_contracts.rs index 3bb9295d..79ff4f74 100644 --- a/crates/core/src/system_contracts.rs +++ b/crates/core/src/system_contracts.rs @@ -1,6 +1,6 @@ use crate::deps::system_contracts::bytecode_from_slice; use crate::node::ImpersonationManager; -use anvil_zksync_config::types::SystemContractsOptions; +use anvil_zksync_config::types::{SystemContractsOptions, ZKOSConfig}; use zksync_contracts::{ read_bootloader_code, read_sys_contract_bytecode, BaseSystemContracts, BaseSystemContractsHashes, ContractLanguage, SystemContractCode, @@ -21,13 +21,13 @@ pub struct SystemContracts { // For now, store the zkos switch flag here. // Long term, we should probably refactor this code, and add another struct ('System') // that would hold separate things for ZKOS and for EraVM. (but that's too early for now). - pub use_zkos: bool, + pub zkos_config: ZKOSConfig, } impl Default for SystemContracts { /// Creates SystemContracts that use compiled-in contracts. fn default() -> Self { - SystemContracts::from_options(&SystemContractsOptions::BuiltIn, false, false) + SystemContracts::from_options(&SystemContractsOptions::BuiltIn, false, Default::default()) } } @@ -37,7 +37,7 @@ impl SystemContracts { pub fn from_options( options: &SystemContractsOptions, use_evm_emulator: bool, - use_zkos: bool, + zkos_config: ZKOSConfig, ) -> Self { Self { baseline_contracts: baseline_contracts(options, use_evm_emulator), @@ -52,14 +52,18 @@ impl SystemContracts { use_evm_emulator, ), use_evm_emulator, - use_zkos, + zkos_config, } } /// Whether it accepts the transactions that have 'null' as target. /// This is used only when EVM emulator is enabled, or we're running in zkos mode. pub fn allow_no_target(&self) -> bool { - self.use_zkos || self.use_evm_emulator + self.zkos_config.use_zkos || self.use_evm_emulator + } + + pub fn use_zkos(&self) -> bool { + self.zkos_config.use_zkos } pub fn contracts_for_l2_call(&self) -> &BaseSystemContracts { diff --git a/docs/rustbook/src/usage/experimental-zkos.md b/docs/rustbook/src/usage/experimental-zkos.md index 8b12262f..33a3bb17 100644 --- a/docs/rustbook/src/usage/experimental-zkos.md +++ b/docs/rustbook/src/usage/experimental-zkos.md @@ -3,10 +3,13 @@ ZKOS is the new backend for proving. The features below are still experimental and might break without warning. +Currently the code resides in `zkos-dev` branch (due to dependencies on private crates). + + ## Usage ``` -RUSTUP_TOOLCHAIN=nightly-2024-11-12 cargo run --features zkos -- --chain-id 31337 +cargo run -- --use-zkos ``` Afterwards, any regular forge script should work: @@ -15,10 +18,31 @@ Afterwards, any regular forge script should work: forge script script/Counter.s.sol --rpc-url http://localhost:8011 --private-key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 --broadcast --slow -g 400 ``` +## Witness & proving + +Anvil-zksync can also generate witnesses for batches, which can be then passed to the proving system. + +To generate witness, you have to also provide the path to 'zk_os' app.bin file (which contains RISC_v binary). +It can be computed with the https://github.com/matter-labs/zk_ee/blob/main/zk_os/dump_bin.sh + +Then you can run the anvil-zksync: + +``` +cargo run -- --use-zkos --zkos-bin-path=../zk_ee/zk_os/app.bin +``` + +And after sending some transactions, you can get the witness for the batch, by calling a new method: + +``` +http POST http://127.0.0.1:8011 \ + Content-Type:application/json \ + id:=1 jsonrpc="2.0" method="zkos_getWitness" params:='[1]' +``` + +The resulting data can be passed to tools like the prover cli: https://github.com/matter-labs/air_compiler/tree/main/tools/cli to generate the proof. + ## Caveats There is still no gas equivalency -- that's why this `-g` option that is increasing the gas limits. -Currently chain_id is hardcoded inside zkos to 31337, soon it will be passed as argument. - Many things will not work yet, but basic things like deploying contracts & calling them should work. \ No newline at end of file From b38e6dc77affb6cbef567b9d6ce76498be0d96c1 Mon Sep 17 00:00:00 2001 From: Marcin M <128217157+mm-zk@users.noreply.github.com> Date: Fri, 17 Jan 2025 08:19:36 +0100 Subject: [PATCH 4/6] changed from vec to hex string (#546) --- crates/api_decl/src/namespaces/zkos.rs | 2 +- crates/api_server/src/impls/zkos.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/api_decl/src/namespaces/zkos.rs b/crates/api_decl/src/namespaces/zkos.rs index dce42e06..e37cd28c 100644 --- a/crates/api_decl/src/namespaces/zkos.rs +++ b/crates/api_decl/src/namespaces/zkos.rs @@ -9,5 +9,5 @@ pub trait ZKOSNamespace { /// # Returns /// Bytes with the witness that can be passed to proving system. #[method(name = "getWitness")] - async fn get_witness(&self, batch: u32) -> RpcResult>>; + async fn get_witness(&self, batch: u32) -> RpcResult>; } diff --git a/crates/api_server/src/impls/zkos.rs b/crates/api_server/src/impls/zkos.rs index c0ed659c..48c719de 100644 --- a/crates/api_server/src/impls/zkos.rs +++ b/crates/api_server/src/impls/zkos.rs @@ -13,7 +13,7 @@ impl ZKOSNamespace { #[async_trait] impl ZKOSNamespaceServer for ZKOSNamespace { - async fn get_witness(&self, batch: u32) -> RpcResult>> { - Ok(zkos_get_batch_witness(&batch)) + async fn get_witness(&self, batch: u32) -> RpcResult> { + Ok(zkos_get_batch_witness(&batch).map(|data| hex::encode(data))) } } From daa0b80e0ae5e8303602e7b1c5bd96853ddc7809 Mon Sep 17 00:00:00 2001 From: Marcin M <128217157+mm-zk@users.noreply.github.com> Date: Fri, 17 Jan 2025 08:31:07 +0100 Subject: [PATCH 5/6] chore: merge main (#547) * refactor: reduce usage of `ForkStorage` outside `inner` module (#539) * reduce usage of `ForkStorage` outside `inner` module * adapt for zkos * fix destination path (#541) * fix: anvil-zksync able to start even if the port is busy (#542) * fix: closes #512 - start instance even if port is busy * chore: apply make lint:fix * chore: refactor test to make use of anvil-zksync instance * chore: remove no longer needed deps * chore: remove no longer needed deps * chore: bump actions/upload-artifact: v3 to v4 due to CI fail * chore: bump actions/upload-artifact / download: v3 to v4 due to CI fail * compilation fixes --------- Co-authored-by: Daniyar Itegulov Co-authored-by: Nisheeth Barthwal Co-authored-by: Dustin Brickwood --- .github/workflows/checks.yaml | 6 +- .github/workflows/e2e-docker.yml | 2 +- .github/workflows/e2e-rust.yml | 4 +- .github/workflows/e2e.yml | 2 +- .github/workflows/release.yml | 8 +- .github/workflows/spec.yml | 4 +- Makefile | 4 + crates/api_server/src/impls/anvil.rs | 18 ++- crates/api_server/src/server.rs | 22 +-- crates/cli/src/bytecode_override.rs | 2 +- crates/cli/src/main.rs | 60 ++++++- crates/core/src/node/debug.rs | 2 +- crates/core/src/node/eth.rs | 33 ++-- crates/core/src/node/in_memory.rs | 55 ++++--- crates/core/src/node/in_memory_ext.rs | 69 ++++---- crates/core/src/node/inner/fork.rs | 21 +++ crates/core/src/node/inner/in_memory_inner.rs | 71 ++++++--- crates/core/src/node/inner/mod.rs | 9 +- crates/core/src/node/inner/node_executor.rs | 147 +++++++++++++++++- crates/core/src/node/inner/storage.rs | 23 +++ crates/core/src/node/keys.rs | 27 ++-- crates/core/src/node/mod.rs | 2 +- crates/core/src/node/zks.rs | 26 +--- crates/core/src/utils.rs | 8 - e2e-tests-rust/Cargo.lock | 15 ++ e2e-tests-rust/src/lib.rs | 2 +- e2e-tests-rust/tests/lib.rs | 30 +++- scripts/refresh_contracts.sh | 2 +- 28 files changed, 477 insertions(+), 197 deletions(-) create mode 100644 crates/core/src/node/inner/storage.rs diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 340b2d08..900a51df 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -15,7 +15,7 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Rust uses: actions-rust-lang/setup-rust-toolchain@v1 with: @@ -39,7 +39,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Rust uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -55,7 +55,7 @@ jobs: tar -czf anvil-zksync-${{ matrix.os }}.tar.gz ./anvil-zksync* - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: anvil-zksync-${{ matrix.os }}.tar.gz path: ./target/release/anvil-zksync-${{ matrix.os }}.tar.gz diff --git a/.github/workflows/e2e-docker.yml b/.github/workflows/e2e-docker.yml index 68b8a4b9..fc791833 100644 --- a/.github/workflows/e2e-docker.yml +++ b/.github/workflows/e2e-docker.yml @@ -14,7 +14,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/.github/workflows/e2e-rust.yml b/.github/workflows/e2e-rust.yml index 4a1576f9..69bfc55f 100644 --- a/.github/workflows/e2e-rust.yml +++ b/.github/workflows/e2e-rust.yml @@ -11,12 +11,12 @@ jobs: os: [ ubuntu-latest, macos-latest ] name: e2e-rust steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: anvil-zksync-${{ matrix.os }}.tar.gz diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ef45f8a7..b92d326b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -22,7 +22,7 @@ jobs: cache-dependency-path: 'e2e-tests/yarn.lock' - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: anvil-zksync-${{ matrix.os }}.tar.gz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3f74d1e6..553eef17 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,7 @@ jobs: needs: [extract-version] steps: - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -99,7 +99,7 @@ jobs: # This is required to share artifacts between different jobs # ======================================================================= - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: anvil-zksync-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.arch }}.tar.gz path: anvil-zksync-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.arch }}.tar.gz @@ -121,7 +121,7 @@ jobs: steps: # This is necessary for generating the changelog. It has to come before "Download Artifacts" or else it deletes the artifacts. - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -129,7 +129,7 @@ jobs: # Download artifacts # ============================== - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 # ============================== # Create release draft diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml index 87a50ac0..3d8118a2 100644 --- a/.github/workflows/spec.yml +++ b/.github/workflows/spec.yml @@ -7,12 +7,12 @@ jobs: runs-on: ubuntu-latest name: spec steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: "recursive" - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: anvil-zksync-ubuntu-latest.tar.gz diff --git a/Makefile b/Makefile index 630f32d9..c445e687 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,10 @@ lint-fix: cd e2e-tests && yarn && yarn lint:fix && yarn fmt:fix cargo clippy --fix cargo fmt + cd e2e-tests-rust && cargo fmt --all + cd e2e-tests-rust && cargo clippy --fix + cd spec-tests && cargo fmt --all + cd spec-tests && cargo clippy --fix # Run unit tests for Rust code test: diff --git a/crates/api_server/src/impls/anvil.rs b/crates/api_server/src/impls/anvil.rs index 58829fea..6e20f3ad 100644 --- a/crates/api_server/src/impls/anvil.rs +++ b/crates/api_server/src/impls/anvil.rs @@ -155,11 +155,19 @@ impl AnvilNamespaceServer for AnvilNamespace { } async fn set_balance(&self, address: Address, balance: U256) -> RpcResult { - Ok(self.node.set_balance(address, balance).await) + Ok(self + .node + .set_balance(address, balance) + .await + .map_err(RpcError::from)?) } async fn set_nonce(&self, address: Address, nonce: U256) -> RpcResult { - Ok(self.node.set_nonce(address, nonce).await) + Ok(self + .node + .set_nonce(address, nonce) + .await + .map_err(RpcError::from)?) } async fn anvil_mine(&self, num_blocks: Option, interval: Option) -> RpcResult<()> { @@ -203,7 +211,11 @@ impl AnvilNamespaceServer for AnvilNamespace { } async fn set_storage_at(&self, address: Address, slot: U256, value: U256) -> RpcResult { - Ok(self.node.set_storage_at(address, slot, value).await) + Ok(self + .node + .set_storage_at(address, slot, value) + .await + .map_err(RpcError::from)?) } async fn set_chain_id(&self, id: u32) -> RpcResult<()> { diff --git a/crates/api_server/src/server.rs b/crates/api_server/src/server.rs index 5fe1577b..cfea2b6a 100644 --- a/crates/api_server/src/server.rs +++ b/crates/api_server/src/server.rs @@ -64,7 +64,7 @@ impl NodeServerBuilder { rpc } - pub async fn build(self, addr: SocketAddr) -> NodeServer { + pub async fn build(self, addr: SocketAddr) -> Result { let cors_layers = tower::util::option_layer(self.cors_enabled.then(|| { // `CorsLayer` adds CORS-specific headers to responses but does not do filtering by itself. // CORS relies on browsers respecting server's access list response headers. @@ -88,14 +88,18 @@ impl NodeServerBuilder { ) .set_rpc_middleware(RpcServiceBuilder::new().rpc_logger(100)); - let server = server_builder.build(addr).await.unwrap(); - let local_addr = server.local_addr().unwrap(); - let rpc = Self::default_rpc(self.node); - // `jsonrpsee` does `tokio::spawn` within `start` method, so we cannot invoke it here, as this method - // should only build the server. This way we delay the launch until the `NodeServer::run` is invoked. - NodeServer { - local_addr, - run_fn: Box::new(move || server.start(rpc)), + match server_builder.build(addr).await { + Ok(server) => { + let local_addr = server.local_addr().unwrap(); + let rpc = Self::default_rpc(self.node); + // `jsonrpsee` does `tokio::spawn` within `start` method, so we cannot invoke it here, as this method + // should only build the server. This way we delay the launch until the `NodeServer::run` is invoked. + Ok(NodeServer { + local_addr, + run_fn: Box::new(move || server.start(rpc)), + }) + } + Err(e) => Err(format!("Failed to bind to address {}: {}", addr, e)), } } } diff --git a/crates/cli/src/bytecode_override.rs b/crates/cli/src/bytecode_override.rs index f6dbe91e..cc71cd6f 100644 --- a/crates/cli/src/bytecode_override.rs +++ b/crates/cli/src/bytecode_override.rs @@ -41,7 +41,7 @@ pub async fn override_bytecodes(node: &InMemoryNode, bytecodes_dir: String) -> a let bytecode = Vec::from_hex(contract.bytecode.object) .with_context(|| format!("Failed to parse hex from {:?}", path))?; - node.override_bytecode(&address, &bytecode) + node.override_bytecode(address, bytecode) .await .expect("Failed to override bytecode"); tracing::info!("+++++ Replacing bytecode at address {:?} +++++", address); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 156d45e7..43d45ebf 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -13,7 +13,7 @@ use anvil_zksync_core::filters::EthFilters; use anvil_zksync_core::node::fork::ForkDetails; use anvil_zksync_core::node::{ BlockSealer, BlockSealerMode, ImpersonationManager, InMemoryNode, InMemoryNodeInner, - NodeExecutor, TestNodeFeeInputProvider, TxPool, + NodeExecutor, StorageKeyLayout, TestNodeFeeInputProvider, TxPool, }; use anvil_zksync_core::observability::Observability; use anvil_zksync_core::system_contracts::SystemContracts; @@ -223,18 +223,27 @@ async fn main() -> anyhow::Result<()> { config.use_evm_emulator, config.zkos_config.clone(), ); + let storage_key_layout = if config.zkos_config.use_zkos { + StorageKeyLayout::ZkOs + } else { + StorageKeyLayout::ZkEra + }; - let (node_inner, _fork_storage, blockchain, time) = InMemoryNodeInner::init( + let (node_inner, storage, blockchain, time) = InMemoryNodeInner::init( fork_details, fee_input_provider.clone(), filters, config.clone(), impersonation.clone(), system_contracts.clone(), + storage_key_layout, ); - let (node_executor, node_handle) = - NodeExecutor::new(node_inner.clone(), system_contracts.clone()); + let (node_executor, node_handle) = NodeExecutor::new( + node_inner.clone(), + system_contracts.clone(), + storage_key_layout, + ); let sealing_mode = if config.no_mining { BlockSealerMode::noop() } else if let Some(block_time) = config.block_time { @@ -248,6 +257,7 @@ async fn main() -> anyhow::Result<()> { let node: InMemoryNode = InMemoryNode::new( node_inner, blockchain, + storage, node_handle, Some(observability), time, @@ -255,6 +265,7 @@ async fn main() -> anyhow::Result<()> { pool, block_sealer_state, system_contracts, + storage_key_layout, ); if let Some(ref bytecodes_dir) = config.override_bytecodes_dir { @@ -306,10 +317,43 @@ async fn main() -> anyhow::Result<()> { } let mut server_handles = Vec::with_capacity(config.host.len()); for host in &config.host { - let addr = SocketAddr::new(*host, config.port); - let server = server_builder.clone().build(addr).await; - config.port = server.local_addr().port(); - server_handles.push(server.run()); + let mut addr = SocketAddr::new(*host, config.port); + + match server_builder.clone().build(addr).await { + Ok(server) => { + config.port = server.local_addr().port(); + server_handles.push(server.run()); + } + Err(err) => { + tracing::info!( + "Failed to bind to address {}:{}: {}. Retrying with a different port...", + host, + config.port, + err + ); + + // Attempt to bind to a dynamic port + addr.set_port(0); + match server_builder.clone().build(addr).await { + Ok(server) => { + config.port = server.local_addr().port(); + tracing::info!( + "Successfully started server on port {} for host {}", + config.port, + host + ); + server_handles.push(server.run()); + } + Err(err) => { + return Err(anyhow!( + "Failed to start server on host {} with port: {}", + host, + err + )); + } + } + } + } } let any_server_stopped = futures::future::select_all(server_handles.into_iter().map(|h| Box::pin(h.stopped()))); diff --git a/crates/core/src/node/debug.rs b/crates/core/src/node/debug.rs index 214d80e3..49aae644 100644 --- a/crates/core/src/node/debug.rs +++ b/crates/core/src/node/debug.rs @@ -71,7 +71,7 @@ impl InMemoryNode { // update the enforced_base_fee within l1_batch_env to match the logic in zksync_core l1_batch_env.enforced_base_fee = Some(l2_tx.common_data.fee.max_fee_per_gas.as_u64()); let system_env = inner.create_system_env(system_contracts.clone(), execution_mode); - let storage = StorageView::new(&inner.fork_storage).into_rc_ptr(); + let storage = StorageView::new(inner.read_storage()).into_rc_ptr(); let mut vm: Vm<_, HistoryDisabled> = Vm::new(l1_batch_env, system_env, storage); // We must inject *some* signature (otherwise bootloader code fails to generate hash). diff --git a/crates/core/src/node/eth.rs b/crates/core/src/node/eth.rs index cbc9fd82..cdfabbf6 100644 --- a/crates/core/src/node/eth.rs +++ b/crates/core/src/node/eth.rs @@ -28,8 +28,6 @@ use crate::{ utils::{h256_to_u64, TransparentError}, }; -use super::keys::StorageKeyLayout; - impl InMemoryNode { pub async fn call_impl( &self, @@ -78,7 +76,7 @@ impl InMemoryNode { } pub async fn send_raw_transaction_impl(&self, tx_bytes: Bytes) -> Result { - let chain_id = self.inner.read().await.fork_storage.chain_id; + let chain_id = self.chain_id().await; let (tx_req, hash) = TransactionRequest::from_bytes(&tx_bytes.0, chain_id)?; let mut l2_tx = @@ -102,10 +100,7 @@ impl InMemoryNode { ) -> Result { let (chain_id, l2_gas_price) = { let reader = self.inner.read().await; - ( - reader.fork_storage.chain_id, - reader.fee_input_provider.gas_price(), - ) + (self.chain_id().await, reader.fee_input_provider.gas_price()) }; let mut tx_req = TransactionRequest::from(tx.clone()); @@ -176,13 +171,10 @@ impl InMemoryNode { // TODO: Support _block: Option, ) -> anyhow::Result { - let balance_key = StorageKeyLayout::get_storage_key_for_base_token( - self.system_contracts.use_zkos(), - &address, - ); - - let inner_guard = self.inner.read().await; - match inner_guard.fork_storage.read_value_internal(&balance_key) { + let balance_key = self + .storage_key_layout + .get_storage_key_for_base_token(&address); + match self.storage.read_value_alt(&balance_key).await { Ok(balance) => Ok(h256_to_u256(balance)), Err(error) => Err(anyhow::anyhow!("failed to read account balance: {error}")), } @@ -251,12 +243,9 @@ impl InMemoryNode { // TODO: Support _block: Option, ) -> anyhow::Result { - let inner = self.inner.write().await; - let code_key = get_code_key(&address); - - match inner.fork_storage.read_value_internal(&code_key) { - Ok(code_hash) => match inner.fork_storage.load_factory_dep_internal(code_hash) { + match self.storage.read_value_alt(&code_key).await { + Ok(code_hash) => match self.storage.load_factory_dep_alt(code_hash).await { Ok(raw_code) => { let code = raw_code.unwrap_or_default(); Ok(Bytes::from(code)) @@ -273,10 +262,8 @@ impl InMemoryNode { // TODO: Support _block: Option, ) -> anyhow::Result { - let inner = self.inner.read().await; - let nonce_key = StorageKeyLayout::get_nonce_key(self.system_contracts.use_zkos(), &address); - - match inner.fork_storage.read_value_internal(&nonce_key) { + let nonce_key = self.storage_key_layout.get_nonce_key(&address); + match self.storage.read_value_alt(&nonce_key).await { Ok(result) => Ok(h256_to_u64(result).into()), Err(error) => Err(anyhow::anyhow!("failed to read nonce storage: {error}")), } diff --git a/crates/core/src/node/in_memory.rs b/crates/core/src/node/in_memory.rs index f8317246..698f4bb5 100644 --- a/crates/core/src/node/in_memory.rs +++ b/crates/core/src/node/in_memory.rs @@ -3,13 +3,15 @@ use super::inner::fork::ForkDetails; use super::inner::node_executor::NodeExecutorHandle; use super::inner::InMemoryNodeInner; use super::vm::AnvilVM; -use crate::deps::{storage_view::StorageView, InMemoryStorage}; +use crate::deps::storage_view::StorageView; +use crate::deps::InMemoryStorage; use crate::filters::EthFilters; use crate::node::call_error_tracer::CallErrorTracer; use crate::node::error::LoadStateError; use crate::node::fee_model::TestNodeFeeInputProvider; use crate::node::impersonate::{ImpersonationManager, ImpersonationState}; use crate::node::inner::blockchain::ReadBlockchain; +use crate::node::inner::storage::ReadStorageDyn; use crate::node::inner::time::ReadTime; use crate::node::sealer::BlockSealerState; use crate::node::state::VersionedState; @@ -45,21 +47,20 @@ use zksync_multivm::tracers::CallTracer; use zksync_multivm::utils::{get_batch_base_fee, get_max_batch_gas_limit}; use zksync_multivm::vm_latest::Vm; +use crate::node::keys::StorageKeyLayout; use zksync_multivm::vm_latest::{HistoryDisabled, ToTracerPointer}; use zksync_multivm::VmVersion; use zksync_types::api::{Block, DebugCall, TransactionReceipt, TransactionVariant}; use zksync_types::block::unpack_block_info; -use zksync_types::bytecode::BytecodeHash; use zksync_types::fee_model::BatchFeeInput; use zksync_types::l2::L2Tx; use zksync_types::storage::{ EMPTY_UNCLES_HASH, SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_BLOCK_INFO_POSITION, }; use zksync_types::web3::{keccak256, Bytes}; -use zksync_types::{get_code_key, h256_to_u256}; use zksync_types::{ - AccountTreeId, Address, Bloom, L1BatchNumber, L2BlockNumber, PackedEthSignature, StorageKey, - StorageValue, Transaction, H160, H256, H64, U256, U64, + h256_to_u256, AccountTreeId, Address, Bloom, L1BatchNumber, L2BlockNumber, L2ChainId, + PackedEthSignature, StorageKey, StorageValue, Transaction, H160, H256, H64, U256, U64, }; /// Max possible size of an ABI encoded tx (in bytes). @@ -247,6 +248,7 @@ pub struct InMemoryNode { /// A thread safe reference to the [InMemoryNodeInner]. pub(crate) inner: Arc>, pub(crate) blockchain: Box, + pub(crate) storage: Box, pub(crate) node_handle: NodeExecutorHandle, /// List of snapshots of the [InMemoryNodeInner]. This is bounded at runtime by [MAX_SNAPSHOTS]. pub(crate) snapshots: Arc>>, @@ -257,6 +259,7 @@ pub struct InMemoryNode { pub(crate) pool: TxPool, pub(crate) sealer_state: BlockSealerState, pub(crate) system_contracts: SystemContracts, + pub(crate) storage_key_layout: StorageKeyLayout, } impl InMemoryNode { @@ -264,6 +267,7 @@ impl InMemoryNode { pub fn new( inner: Arc>, blockchain: Box, + storage: Box, node_handle: NodeExecutorHandle, observability: Option, time: Box, @@ -271,10 +275,12 @@ impl InMemoryNode { pool: TxPool, sealer_state: BlockSealerState, system_contracts: SystemContracts, + storage_key_layout: StorageKeyLayout, ) -> Self { InMemoryNode { inner, blockchain, + storage, node_handle, snapshots: Default::default(), time, @@ -283,6 +289,7 @@ impl InMemoryNode { pool, sealer_state, system_contracts, + storage_key_layout, } } @@ -383,7 +390,7 @@ impl InMemoryNode { let (batch_env, _) = inner.create_l1_batch_env().await; let system_env = inner.create_system_env(base_contracts, execution_mode); - let storage = StorageView::new(&inner.fork_storage).into_rc_ptr(); + let storage = StorageView::new(inner.read_storage()).into_rc_ptr(); let mut vm = if self.system_contracts.use_zkos() { AnvilVM::ZKOs(super::zkos::ZKOsVM::<_, HistoryDisabled>::new( @@ -473,22 +480,10 @@ impl InMemoryNode { // Forcefully stores the given bytecode at a given account. pub async fn override_bytecode( &self, - address: &Address, - bytecode: &[u8], - ) -> Result<(), String> { - let inner = self.inner.write().await; - - let code_key = get_code_key(address); - - let bytecode_hash = BytecodeHash::for_bytecode(bytecode).value(); - - inner - .fork_storage - .store_factory_dep(bytecode_hash, bytecode.to_owned()); - - inner.fork_storage.set_value(code_key, bytecode_hash); - - Ok(()) + address: Address, + bytecode: Vec, + ) -> anyhow::Result<()> { + self.node_handle.set_code_sync(address, bytecode).await } pub async fn dump_state(&self, preserve_historical_states: bool) -> anyhow::Result { @@ -623,6 +618,10 @@ impl InMemoryNode { observability.set_logging(directive)?; Ok(true) } + + pub async fn chain_id(&self) -> L2ChainId { + self.inner.read().await.chain_id() + } } pub fn load_last_l1_batch(storage: StoragePtr) -> Option<(u64, u64)> { @@ -655,16 +654,22 @@ impl InMemoryNode { config.use_evm_emulator, config.zkos_config.clone(), ); - let (inner, _, blockchain, time) = InMemoryNodeInner::init( + let storage_key_layout = if config.zkos_config.use_zkos { + StorageKeyLayout::ZkOs + } else { + StorageKeyLayout::ZkEra + }; + let (inner, storage, blockchain, time) = InMemoryNodeInner::init( fork, fee_provider, Arc::new(RwLock::new(Default::default())), config, impersonation.clone(), system_contracts.clone(), + storage_key_layout, ); let (node_executor, node_handle) = - NodeExecutor::new(inner.clone(), system_contracts.clone()); + NodeExecutor::new(inner.clone(), system_contracts.clone(), storage_key_layout); let pool = TxPool::new( impersonation.clone(), anvil_zksync_types::TransactionOrder::Fifo, @@ -680,6 +685,7 @@ impl InMemoryNode { Self::new( inner, blockchain, + storage, node_handle, None, time, @@ -687,6 +693,7 @@ impl InMemoryNode { pool, block_sealer_state, system_contracts, + storage_key_layout, ) } diff --git a/crates/core/src/node/in_memory_ext.rs b/crates/core/src/node/in_memory_ext.rs index 55bb548b..d2c8889f 100644 --- a/crates/core/src/node/in_memory_ext.rs +++ b/crates/core/src/node/in_memory_ext.rs @@ -2,15 +2,13 @@ use super::inner::fork::ForkDetails; use super::pool::TxBatch; use super::sealer::BlockSealerMode; use super::InMemoryNode; -use crate::node::keys::StorageKeyLayout; -use crate::utils::bytecode_to_factory_dep; use anvil_zksync_types::api::{DetailedTransaction, ResetRequest}; -use anyhow::anyhow; +use anyhow::{anyhow, Context}; use std::time::Duration; use zksync_types::api::{Block, TransactionVariant}; +use zksync_types::bytecode::BytecodeHash; use zksync_types::u256_to_h256; -use zksync_types::{get_code_key, utils::nonces_to_full_nonce, L2BlockNumber, StorageKey}; -use zksync_types::{AccountTreeId, Address, H256, U256, U64}; +use zksync_types::{AccountTreeId, Address, L2BlockNumber, StorageKey, H256, U256, U64}; type Result = anyhow::Result; @@ -165,36 +163,24 @@ impl InMemoryNode { .map_err(|err| anyhow!("{}", err)) } - pub async fn set_balance(&self, address: Address, balance: U256) -> bool { - let writer = self.inner.write().await; - let balance_key = StorageKeyLayout::get_storage_key_for_base_token( - self.system_contracts.use_zkos(), - &address, - ); - writer - .fork_storage - .set_value(balance_key, u256_to_h256(balance)); + pub async fn set_balance(&self, address: Address, balance: U256) -> anyhow::Result { + self.node_handle.set_balance_sync(address, balance).await?; tracing::info!( "👷 Balance for address {:?} has been manually set to {} Wei", address, balance ); - true + Ok(true) } - pub async fn set_nonce(&self, address: Address, nonce: U256) -> bool { - let writer = self.inner.write().await; - let nonce_key = StorageKeyLayout::get_nonce_key(self.system_contracts.use_zkos(), &address); - let enforced_full_nonce = nonces_to_full_nonce(nonce, nonce); + pub async fn set_nonce(&self, address: Address, nonce: U256) -> anyhow::Result { + self.node_handle.set_nonce_sync(address, nonce).await?; tracing::info!( "👷 Nonces for address {:?} have been set to {}", address, nonce ); - writer - .fork_storage - .set_value(nonce_key, u256_to_h256(enforced_full_nonce)); - true + Ok(true) } pub async fn mine_blocks(&self, num_blocks: Option, interval: Option) -> Result<()> { @@ -316,24 +302,24 @@ impl InMemoryNode { } pub async fn set_code(&self, address: Address, code: String) -> Result<()> { - let writer = self.inner.write().await; - let code_key = get_code_key(&address); - tracing::info!("set code for address {address:#x}"); let code_slice = code .strip_prefix("0x") .ok_or_else(|| anyhow!("code must be 0x-prefixed"))?; - let code_bytes = hex::decode(code_slice)?; - let (hash, code) = bytecode_to_factory_dep(code_bytes)?; - writer.fork_storage.store_factory_dep(hash, code); - writer.fork_storage.set_value(code_key, hash); + let bytecode = hex::decode(code_slice)?; + zksync_types::bytecode::validate_bytecode(&bytecode).context("Invalid bytecode")?; + tracing::info!( + ?address, + bytecode_hash = ?BytecodeHash::for_bytecode(&bytecode).value(), + "set code" + ); + self.node_handle.set_code_sync(address, bytecode).await?; Ok(()) } - pub async fn set_storage_at(&self, address: Address, slot: U256, value: U256) -> bool { - let writer = self.inner.write().await; + pub async fn set_storage_at(&self, address: Address, slot: U256, value: U256) -> Result { let key = StorageKey::new(AccountTreeId::new(address), u256_to_h256(slot)); - writer.fork_storage.set_value(key, u256_to_h256(value)); - true + self.node_handle.set_storage_sync(key, value).await?; + Ok(true) } pub fn set_logging_enabled(&self, enable: bool) -> Result<()> { @@ -460,7 +446,7 @@ mod tests { let balance_before = node.get_balance_impl(address, None).await.unwrap(); - let result = node.set_balance(address, U256::from(1337)).await; + let result = node.set_balance(address, U256::from(1337)).await.unwrap(); assert!(result); let balance_after = node.get_balance_impl(address, None).await.unwrap(); @@ -478,7 +464,7 @@ mod tests { .await .unwrap(); - let result = node.set_nonce(address, U256::from(1337)).await; + let result = node.set_nonce(address, U256::from(1337)).await.unwrap(); assert!(result); let nonce_after = node @@ -488,7 +474,7 @@ mod tests { assert_eq!(nonce_after, U256::from(1337)); assert_ne!(nonce_before, nonce_after); - let result = node.set_nonce(address, U256::from(1336)).await; + let result = node.set_nonce(address, U256::from(1336)).await.unwrap(); assert!(result); let nonce_after = node @@ -582,7 +568,7 @@ mod tests { .get_transaction_count_impl(address, None) .await .unwrap(); - assert!(node.set_nonce(address, U256::from(1337)).await); + assert!(node.set_nonce(address, U256::from(1337)).await.unwrap()); assert!(node.reset_network(None).await.unwrap()); @@ -609,7 +595,10 @@ mod tests { Address::from_str("0xd8da6bf26964af9d7eed9e03e53415d37aa96045").unwrap(); // give impersonated account some balance - let result = node.set_balance(to_impersonate, U256::exp10(18)).await; + let result = node + .set_balance(to_impersonate, U256::exp10(18)) + .await + .unwrap(); assert!(result); // construct a tx @@ -707,7 +696,7 @@ mod tests { let value_before = node.inner.write().await.fork_storage.read_value(&key); assert_eq!(H256::default(), value_before); - let result = node.set_storage_at(address, slot, value).await; + let result = node.set_storage_at(address, slot, value).await.unwrap(); assert!(result); let value_after = node.inner.write().await.fork_storage.read_value(&key); diff --git a/crates/core/src/node/inner/fork.rs b/crates/core/src/node/inner/fork.rs index 6332253d..78c58549 100644 --- a/crates/core/src/node/inner/fork.rs +++ b/crates/core/src/node/inner/fork.rs @@ -3,6 +3,7 @@ //! There is ForkStorage (that is a wrapper over InMemoryStorage) //! And ForkDetails - that parses network address and fork height from arguments. +use crate::node::inner::storage::ReadStorageDyn; use crate::utils::block_on; use crate::{deps::InMemoryStorage, http_fork_source::HttpForkSource}; use anvil_zksync_config::constants::{ @@ -10,6 +11,7 @@ use anvil_zksync_config::constants::{ DEFAULT_FAIR_PUBDATA_PRICE, TEST_NODE_NETWORK_ID, }; use anvil_zksync_config::types::{CacheConfig, SystemContractsOptions}; +use async_trait::async_trait; use eyre::eyre; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; @@ -323,6 +325,25 @@ impl ReadStorage for &ForkStorage { } } +#[async_trait] +impl ReadStorageDyn for ForkStorage { + fn dyn_cloned(&self) -> Box { + Box::new(self.clone()) + } + + async fn read_value_alt(&self, key: &StorageKey) -> anyhow::Result { + // TODO: Get rid of `block_on` inside to propagate asynchronous execution up to this level + self.read_value_internal(key) + .map_err(|e| anyhow::anyhow!("failed reading value: {:?}", e)) + } + + async fn load_factory_dep_alt(&self, hash: H256) -> anyhow::Result>> { + // TODO: Get rid of `block_on` inside to propagate asynchronous execution up to this level + self.load_factory_dep_internal(hash) + .map_err(|e| anyhow::anyhow!("failed to load factory dep: {:?}", e)) + } +} + impl ForkStorage { pub fn set_value(&self, key: StorageKey, value: zksync_types::StorageValue) { let mut mutator = self.inner.write().unwrap(); diff --git a/crates/core/src/node/inner/in_memory_inner.rs b/crates/core/src/node/inner/in_memory_inner.rs index 3ff3d534..10bfc8f1 100644 --- a/crates/core/src/node/inner/in_memory_inner.rs +++ b/crates/core/src/node/inner/in_memory_inner.rs @@ -19,12 +19,13 @@ use crate::node::{ }; use crate::system_contracts::SystemContracts; -use crate::utils::{bytecode_to_factory_dep, create_debug_output}; +use crate::utils::create_debug_output; use crate::{delegate_vm, formatter, utils}; use anvil_zksync_config::constants::NON_FORK_FIRST_BLOCK_TIMESTAMP; use anvil_zksync_config::types::ZKOSConfig; use anvil_zksync_config::TestNodeConfig; use anvil_zksync_types::{ShowCalls, ShowGasDetails, ShowStorageLogs, ShowVMDetails}; +use anyhow::Context; use colored::Colorize; use indexmap::IndexMap; use once_cell::sync::OnceCell; @@ -55,6 +56,7 @@ use zksync_multivm::vm_latest::{ use zksync_multivm::VmVersion; use zksync_types::api::{BlockIdVariant, TransactionVariant}; use zksync_types::block::build_bloom; +use zksync_types::bytecode::BytecodeHash; use zksync_types::fee::Fee; use zksync_types::fee_model::{BatchFeeInput, PubdataIndependentBatchFeeModelInput}; use zksync_types::l2::{L2Tx, TransactionType}; @@ -63,7 +65,7 @@ use zksync_types::utils::{decompose_full_nonce, nonces_to_full_nonce}; use zksync_types::web3::{Bytes, Index}; use zksync_types::{ api, h256_to_address, h256_to_u256, u256_to_h256, AccountTreeId, Address, Bloom, BloomInput, - L1BatchNumber, L2BlockNumber, StorageKey, StorageValue, Transaction, + L1BatchNumber, L2BlockNumber, L2ChainId, StorageKey, StorageValue, Transaction, ACCOUNT_CODE_STORAGE_ADDRESS, H160, H256, MAX_L2_TX_GAS_LIMIT, U256, U64, }; use zksync_web3_decl::error::Web3Error; @@ -89,6 +91,7 @@ pub struct InMemoryNodeInner { pub rich_accounts: HashSet, /// Keeps track of historical states indexed via block hash. Limited to [MAX_PREVIOUS_STATES]. previous_states: IndexMap>, + storage_key_layout: StorageKeyLayout, } impl InMemoryNodeInner { @@ -103,6 +106,7 @@ impl InMemoryNodeInner { config: TestNodeConfig, impersonation: ImpersonationManager, system_contracts: SystemContracts, + storage_key_layout: StorageKeyLayout, ) -> Self { InMemoryNodeInner { blockchain, @@ -116,6 +120,7 @@ impl InMemoryNodeInner { impersonation, rich_accounts: HashSet::new(), previous_states: Default::default(), + storage_key_layout, } } @@ -428,11 +433,9 @@ impl InMemoryNodeInner { let mut bytecodes = HashMap::new(); for b in &*compressed_bytecodes { - let (hash, bytecode) = bytecode_to_factory_dep(b.original.clone()).map_err(|err| { - tracing::error!("{}", format!("cannot convert bytecode: {err}").on_red()); - err - })?; - bytecodes.insert(hash, bytecode); + zksync_types::bytecode::validate_bytecode(&b.original).context("Invalid bytecode")?; + let hash = BytecodeHash::for_bytecode(&b.original).value(); + bytecodes.insert(hash, b.original.clone()); } // Also add bytecodes that were created by EVM. for entry in &tx_result.dynamic_factory_deps { @@ -486,8 +489,8 @@ impl InMemoryNodeInner { } // Write all the factory deps. - for (hash, code) in bytecodes.iter() { - self.fork_storage.store_factory_dep(*hash, code.clone()) + for (hash, code) in bytecodes { + self.fork_storage.store_factory_dep(hash, code) } let logs = result @@ -822,7 +825,7 @@ impl InMemoryNodeInner { // In theory, if the transaction has failed with such large gas limit, we could have returned an API error here right away, // but doing it later on keeps the code more lean. - let result = InMemoryNodeInner::estimate_gas_step( + let result = self.estimate_gas_step( l2_tx.clone(), gas_per_pubdata_byte, BATCH_GAS_LIMIT, @@ -860,7 +863,7 @@ impl InMemoryNodeInner { ); let try_gas_limit = additional_gas_for_pubdata + mid; - let estimate_gas_result = InMemoryNodeInner::estimate_gas_step( + let estimate_gas_result = self.estimate_gas_step( l2_tx.clone(), gas_per_pubdata_byte, try_gas_limit, @@ -892,7 +895,7 @@ impl InMemoryNodeInner { * self.fee_input_provider.estimate_gas_scale_factor) as u64; - let estimate_gas_result = InMemoryNodeInner::estimate_gas_step( + let estimate_gas_result = self.estimate_gas_step( l2_tx.clone(), gas_per_pubdata_byte, suggested_gas_limit, @@ -1008,6 +1011,7 @@ impl InMemoryNodeInner { /// Runs fee estimation against a sandbox vm with the given gas_limit. #[allow(clippy::too_many_arguments)] fn estimate_gas_step( + &self, mut l2_tx: L2Tx, gas_per_pubdata_byte: u64, tx_gas_limit: u64, @@ -1033,8 +1037,9 @@ impl InMemoryNodeInner { // The nonce needs to be updated let nonce = l2_tx.nonce(); - let nonce_key = - StorageKeyLayout::get_nonce_key(zkos_config.use_zkos, &l2_tx.initiator_account()); + let nonce_key = self + .storage_key_layout + .get_nonce_key(&l2_tx.initiator_account()); let full_nonce = storage.borrow_mut().read_value(&nonce_key); let (_, deployment_nonce) = decompose_full_nonce(h256_to_u256(full_nonce)); let enforced_full_nonce = nonces_to_full_nonce(U256::from(nonce.0), deployment_nonce); @@ -1044,8 +1049,9 @@ impl InMemoryNodeInner { // We need to explicitly put enough balance into the account of the users let payer = l2_tx.payer(); - let balance_key = - StorageKeyLayout::get_storage_key_for_base_token(zkos_config.use_zkos, &payer); + let balance_key = self + .storage_key_layout + .get_storage_key_for_base_token(&payer); let mut current_balance = h256_to_u256(storage.borrow_mut().read_value(&balance_key)); let added_balance = l2_tx.common_data.fee.gas_limit * l2_tx.common_data.fee.max_fee_per_gas; current_balance += added_balance; @@ -1321,10 +1327,9 @@ impl InMemoryNodeInner { /// Adds a lot of tokens to a given account with a specified balance. pub fn set_rich_account(&mut self, address: H160, balance: U256) { - let key = StorageKeyLayout::get_storage_key_for_base_token( - self.system_contracts.use_zkos(), - &address, - ); + let key = self + .storage_key_layout + .get_storage_key_for_base_token(&address); let keys = { let mut storage_view = StorageView::new(&self.fork_storage); @@ -1338,6 +1343,15 @@ impl InMemoryNodeInner { } self.rich_accounts.insert(address); } + + pub fn read_storage(&self) -> Box { + Box::new(&self.fork_storage) + } + + // TODO: Remove, this should also be made available from somewhere else + pub fn chain_id(&self) -> L2ChainId { + self.fork_storage.chain_id + } } #[derive(Debug)] @@ -1389,6 +1403,11 @@ impl InMemoryNodeInner { config.use_evm_emulator, config.zkos_config.clone(), ); + let storage_key_layout = if config.zkos_config.use_zkos { + StorageKeyLayout::ZkOs + } else { + StorageKeyLayout::ZkEra + }; let (inner, _, _, _) = InMemoryNodeInner::init( None, fee_provider, @@ -1396,6 +1415,7 @@ impl InMemoryNodeInner { config, impersonation.clone(), system_contracts.clone(), + storage_key_layout, ); inner } @@ -1611,7 +1631,7 @@ mod tests { let system_contracts = node .system_contracts .system_contracts_for_initiator(&node.impersonation, &tx.initiator_account()); - let (block_ctx, batch_env, mut vm) = test_vm(&mut *node, system_contracts).await; + let (block_ctx, batch_env, mut vm) = test_vm(&mut node, system_contracts).await; let err = node .run_l2_tx(tx, 0, &block_ctx, &batch_env, &mut vm) .unwrap_err(); @@ -1630,7 +1650,7 @@ mod tests { let system_contracts = node .system_contracts .system_contracts_for_initiator(&node.impersonation, &tx.initiator_account()); - let (block_ctx, batch_env, mut vm) = test_vm(&mut *node, system_contracts).await; + let (block_ctx, batch_env, mut vm) = test_vm(&mut node, system_contracts).await; let err = node .run_l2_tx(tx, 0, &block_ctx, &batch_env, &mut vm) .unwrap_err(); @@ -1653,7 +1673,7 @@ mod tests { let system_contracts = node .system_contracts .system_contracts_for_initiator(&node.impersonation, &tx.initiator_account()); - let (block_ctx, batch_env, mut vm) = test_vm(&mut *node, system_contracts).await; + let (block_ctx, batch_env, mut vm) = test_vm(&mut node, system_contracts).await; let err = node .run_l2_tx(tx, 0, &block_ctx, &batch_env, &mut vm) .unwrap_err(); @@ -1714,6 +1734,7 @@ mod tests { TestNodeConfig::default(), impersonation, node.system_contracts.clone(), + node.storage_key_layout, ); let mut node = node.write().await; @@ -1722,7 +1743,7 @@ mod tests { let system_contracts = node .system_contracts .system_contracts_for_initiator(&node.impersonation, &tx.initiator_account()); - let (_, _, mut vm) = test_vm(&mut *node, system_contracts).await; + let (_, _, mut vm) = test_vm(&mut node, system_contracts).await; node.run_l2_tx_raw(tx, &mut vm) .expect("transaction must pass with external storage"); } @@ -1772,7 +1793,7 @@ mod tests { let system_contracts = node .system_contracts .system_contracts_for_initiator(&node.impersonation, &tx.initiator_account()); - let (_, _, mut vm) = test_vm(&mut *node, system_contracts).await; + let (_, _, mut vm) = test_vm(&mut node, system_contracts).await; let TxExecutionOutput { result, .. } = node.run_l2_tx_raw(tx, &mut vm).expect("failed tx"); match result.result { diff --git a/crates/core/src/node/inner/mod.rs b/crates/core/src/node/inner/mod.rs index 760af367..3b80f0c3 100644 --- a/crates/core/src/node/inner/mod.rs +++ b/crates/core/src/node/inner/mod.rs @@ -13,12 +13,15 @@ pub mod blockchain; pub mod fork; mod in_memory_inner; pub mod node_executor; +pub mod storage; pub mod time; pub use in_memory_inner::{InMemoryNodeInner, TxExecutionOutput}; use crate::filters::EthFilters; use crate::node::blockchain::Blockchain; +use crate::node::inner::storage::ReadStorageDyn; +use crate::node::keys::StorageKeyLayout; use crate::node::{ImpersonationManager, TestNodeFeeInputProvider}; use crate::system_contracts::SystemContracts; use anvil_zksync_config::constants::NON_FORK_FIRST_BLOCK_TIMESTAMP; @@ -39,9 +42,10 @@ impl InMemoryNodeInner { config: TestNodeConfig, impersonation: ImpersonationManager, system_contracts: SystemContracts, + storage_key_layout: StorageKeyLayout, ) -> ( Arc>, - ForkStorage, + Box, Box, Box, ) { @@ -72,11 +76,12 @@ impl InMemoryNodeInner { config.clone(), impersonation.clone(), system_contracts.clone(), + storage_key_layout, ); ( Arc::new(RwLock::new(node_inner)), - fork_storage, + Box::new(fork_storage), Box::new(blockchain), Box::new(time), ) diff --git a/crates/core/src/node/inner/node_executor.rs b/crates/core/src/node/inner/node_executor.rs index b06bd9d4..f963c8ba 100644 --- a/crates/core/src/node/inner/node_executor.rs +++ b/crates/core/src/node/inner/node_executor.rs @@ -1,27 +1,33 @@ use super::InMemoryNodeInner; +use crate::node::keys::StorageKeyLayout; use crate::node::pool::TxBatch; use crate::system_contracts::SystemContracts; use std::sync::Arc; use tokio::sync::{mpsc, oneshot, RwLock}; use zksync_multivm::interface::TxExecutionMode; -use zksync_types::L2BlockNumber; +use zksync_types::bytecode::BytecodeHash; +use zksync_types::utils::nonces_to_full_nonce; +use zksync_types::{get_code_key, u256_to_h256, Address, L2BlockNumber, StorageKey, U256}; pub struct NodeExecutor { node_inner: Arc>, system_contracts: SystemContracts, command_receiver: mpsc::Receiver, + storage_key_layout: StorageKeyLayout, } impl NodeExecutor { pub fn new( node_inner: Arc>, system_contracts: SystemContracts, + storage_key_layout: StorageKeyLayout, ) -> (Self, NodeExecutorHandle) { let (command_sender, command_receiver) = mpsc::channel(128); let this = Self { node_inner, system_contracts, command_receiver, + storage_key_layout, }; let handle = NodeExecutorHandle { command_sender }; (this, handle) @@ -36,6 +42,18 @@ impl NodeExecutor { Command::SealBlocks(tx_batches, interval, reply) => { self.seal_blocks(tx_batches, interval, reply).await; } + Command::SetCode(address, code, reply) => { + self.set_code(address, code, reply).await; + } + Command::SetStorage(key, value, reply) => { + self.set_storage(key, value, reply).await; + } + Command::SetBalance(address, balance, reply) => { + self.set_balance(address, balance, reply).await; + } + Command::SetNonce(address, nonce, reply) => { + self.set_nonce(address, nonce, reply).await; + } Command::IncreaseTime(delta, reply) => { self.increase_time(delta, reply).await; } @@ -138,6 +156,66 @@ impl NodeExecutor { } } + async fn set_code(&self, address: Address, bytecode: Vec, reply: oneshot::Sender<()>) { + let code_key = get_code_key(&address); + let bytecode_hash = BytecodeHash::for_bytecode(&bytecode).value(); + // TODO: Likely fork_storage can be moved to `NodeExecutor` instead + let node_inner = self.node_inner.read().await; + node_inner + .fork_storage + .store_factory_dep(bytecode_hash, bytecode); + node_inner.fork_storage.set_value(code_key, bytecode_hash); + drop(node_inner); + // Reply to sender if we can + if reply.send(()).is_err() { + tracing::info!("failed to reply as receiver has been dropped"); + } + } + + async fn set_storage(&self, key: StorageKey, value: U256, reply: oneshot::Sender<()>) { + // TODO: Likely fork_storage can be moved to `NodeExecutor` instead + self.node_inner + .read() + .await + .fork_storage + .set_value(key, u256_to_h256(value)); + // Reply to sender if we can + if reply.send(()).is_err() { + tracing::info!("failed to reply as receiver has been dropped"); + } + } + + async fn set_balance(&self, address: Address, balance: U256, reply: oneshot::Sender<()>) { + let balance_key = self + .storage_key_layout + .get_storage_key_for_base_token(&address); + // TODO: Likely fork_storage can be moved to `NodeExecutor` instead + self.node_inner + .read() + .await + .fork_storage + .set_value(balance_key, u256_to_h256(balance)); + // Reply to sender if we can + if reply.send(()).is_err() { + tracing::info!("failed to reply as receiver has been dropped"); + } + } + + async fn set_nonce(&self, address: Address, nonce: U256, reply: oneshot::Sender<()>) { + let nonce_key = self.storage_key_layout.get_nonce_key(&address); + let enforced_full_nonce = nonces_to_full_nonce(nonce, nonce); + // TODO: Likely fork_storage can be moved to `NodeExecutor` instead + self.node_inner + .read() + .await + .fork_storage + .set_value(nonce_key, u256_to_h256(enforced_full_nonce)); + // Reply to sender if we can + if reply.send(()).is_err() { + tracing::info!("failed to reply as receiver has been dropped"); + } + } + async fn increase_time(&self, delta: u64, reply: oneshot::Sender<()>) { self.node_inner.write().await.time.increase_time(delta); // Reply to sender if we can @@ -267,6 +345,68 @@ impl NodeExecutorHandle { } } + /// Request [`NodeExecutor`] to set bytecode for given address. Waits for the change to take place. + pub async fn set_code_sync(&self, address: Address, bytecode: Vec) -> anyhow::Result<()> { + let (response_sender, response_receiver) = oneshot::channel(); + self.command_sender + .send(Command::SetCode(address, bytecode, response_sender)) + .await + .map_err(|_| anyhow::anyhow!("failed to set code as node executor is dropped"))?; + match response_receiver.await { + Ok(()) => Ok(()), + Err(_) => { + anyhow::bail!("failed to set code as node executor is dropped") + } + } + } + + /// Request [`NodeExecutor`] to set storage key-value pair. Waits for the change to take place. + pub async fn set_storage_sync(&self, key: StorageKey, value: U256) -> anyhow::Result<()> { + let (response_sender, response_receiver) = oneshot::channel(); + self.command_sender + .send(Command::SetStorage(key, value, response_sender)) + .await + .map_err(|_| anyhow::anyhow!("failed to set storage as node executor is dropped"))?; + match response_receiver.await { + Ok(()) => Ok(()), + Err(_) => { + anyhow::bail!("failed to set storage as node executor is dropped") + } + } + } + + /// Request [`NodeExecutor`] to set account's balance to the given value. Waits for the change + /// to take place. + pub async fn set_balance_sync(&self, address: Address, balance: U256) -> anyhow::Result<()> { + let (response_sender, response_receiver) = oneshot::channel(); + self.command_sender + .send(Command::SetBalance(address, balance, response_sender)) + .await + .map_err(|_| anyhow::anyhow!("failed to set balance as node executor is dropped"))?; + match response_receiver.await { + Ok(()) => Ok(()), + Err(_) => { + anyhow::bail!("failed to set balance as node executor is dropped") + } + } + } + + /// Request [`NodeExecutor`] to set account's nonce to the given value. Waits for the change + /// to take place. + pub async fn set_nonce_sync(&self, address: Address, nonce: U256) -> anyhow::Result<()> { + let (response_sender, response_receiver) = oneshot::channel(); + self.command_sender + .send(Command::SetNonce(address, nonce, response_sender)) + .await + .map_err(|_| anyhow::anyhow!("failed to set nonce as node executor is dropped"))?; + match response_receiver.await { + Ok(()) => Ok(()), + Err(_) => { + anyhow::bail!("failed to set nonce as node executor is dropped") + } + } + } + /// Request [`NodeExecutor`] to increase time by the given delta (in seconds). Waits for the /// change to take place. pub async fn increase_time_sync(&self, delta: u64) -> anyhow::Result<()> { @@ -357,6 +497,11 @@ enum Command { u64, oneshot::Sender>>, ), + // Storage manipulation commands + SetCode(Address, Vec, oneshot::Sender<()>), + SetStorage(StorageKey, U256, oneshot::Sender<()>), + SetBalance(Address, U256, oneshot::Sender<()>), + SetNonce(Address, U256, oneshot::Sender<()>), // Time manipulation commands. Caveat: reply-able commands can hold user connections alive for // a long time (until the command is processed). IncreaseTime(u64, oneshot::Sender<()>), diff --git a/crates/core/src/node/inner/storage.rs b/crates/core/src/node/inner/storage.rs new file mode 100644 index 00000000..eaa3c5b2 --- /dev/null +++ b/crates/core/src/node/inner/storage.rs @@ -0,0 +1,23 @@ +use async_trait::async_trait; +use zksync_multivm::interface::storage::ReadStorage; +use zksync_types::{StorageKey, StorageValue, H256}; + +#[async_trait] +pub trait ReadStorageDyn: ReadStorage + Send + Sync { + /// Alternative for [`Clone::clone`] that is object safe. + fn dyn_cloned(&self) -> Box; + + /// Alternative version of [`ReadStorage::read_value`] that is fallible, async and does not + /// require `&mut self`. + async fn read_value_alt(&self, key: &StorageKey) -> anyhow::Result; + + /// Alternative version of [`ReadStorage::load_factory_dep`] that is fallible, async and does not + /// require `&mut self`. + async fn load_factory_dep_alt(&self, hash: H256) -> anyhow::Result>>; +} + +impl Clone for Box { + fn clone(&self) -> Self { + self.dyn_cloned() + } +} diff --git a/crates/core/src/node/keys.rs b/crates/core/src/node/keys.rs index 776a459b..adb06f33 100644 --- a/crates/core/src/node/keys.rs +++ b/crates/core/src/node/keys.rs @@ -1,24 +1,23 @@ use zksync_types::{Address, StorageKey}; -pub struct StorageKeyLayout {} +#[derive(Copy, Clone)] +pub enum StorageKeyLayout { + ZkEra, + ZkOs, +} impl StorageKeyLayout { - pub fn get_nonce_key(is_zkos: bool, account: &Address) -> StorageKey { - if is_zkos { - crate::node::zkos::zkos_get_nonce_key(account) - } else { - zksync_types::get_nonce_key(account) + pub fn get_nonce_key(&self, account: &Address) -> StorageKey { + match self { + StorageKeyLayout::ZkEra => zksync_types::get_nonce_key(account), + StorageKeyLayout::ZkOs => crate::node::zkos::zkos_get_nonce_key(account), } } - pub fn get_storage_key_for_base_token(is_zkos: bool, address: &Address) -> StorageKey { - if is_zkos { - crate::node::zkos::zkos_storage_key_for_eth_balance(address) - } else { - zksync_types::utils::storage_key_for_standard_token_balance( - zksync_types::AccountTreeId::new(zksync_types::L2_BASE_TOKEN_ADDRESS), - address, - ) + pub fn get_storage_key_for_base_token(&self, address: &Address) -> StorageKey { + match self { + StorageKeyLayout::ZkEra => zksync_types::utils::storage_key_for_eth_balance(address), + StorageKeyLayout::ZkOs => crate::node::zkos::zkos_storage_key_for_eth_balance(address), } } } diff --git a/crates/core/src/node/mod.rs b/crates/core/src/node/mod.rs index 32717844..f5bb0d30 100644 --- a/crates/core/src/node/mod.rs +++ b/crates/core/src/node/mod.rs @@ -19,7 +19,7 @@ mod zkos; mod zks; pub use self::{ - fee_model::TestNodeFeeInputProvider, impersonate::ImpersonationManager, + fee_model::TestNodeFeeInputProvider, impersonate::ImpersonationManager, keys::StorageKeyLayout, node_executor::NodeExecutor, pool::TxPool, sealer::BlockSealer, sealer::BlockSealerMode, state::VersionedState, }; diff --git a/crates/core/src/node/zks.rs b/crates/core/src/node/zks.rs index f8973875..5c776c14 100644 --- a/crates/core/src/node/zks.rs +++ b/crates/core/src/node/zks.rs @@ -125,22 +125,14 @@ impl InMemoryNode { let tokens = self.get_confirmed_tokens_impl(0, 100).await?; let balances = { - let writer = self.inner.write().await; let mut balances = HashMap::new(); for token in tokens { + // TODO: Use StorageKeyLayout once zkos can lookup other tokens let balance_key = storage_key_for_standard_token_balance( AccountTreeId::new(token.l2_address), &address, ); - let balance = match writer.fork_storage.read_value_internal(&balance_key) { - Ok(balance) => balance, - Err(error) => { - return Err(Web3Error::InternalError(anyhow::anyhow!( - "failed reading value: {:?}", - error - ))); - } - }; + let balance = self.storage.read_value_alt(&balance_key).await?; if !balance.is_zero() { balances.insert(token.l2_address, h256_to_u256(balance)); } @@ -223,19 +215,11 @@ impl InMemoryNode { } pub async fn get_bytecode_by_hash_impl(&self, hash: H256) -> anyhow::Result>> { - let writer = self.inner.write().await; - - let maybe_bytecode = match writer.fork_storage.load_factory_dep_internal(hash) { - Ok(maybe_bytecode) => maybe_bytecode, - Err(error) => { - return Err(anyhow::anyhow!("failed to load factory dep: {:?}", error)); - } - }; - - if maybe_bytecode.is_some() { - return Ok(maybe_bytecode); + if let Some(bytecode) = self.storage.load_factory_dep_alt(hash).await? { + return Ok(Some(bytecode)); } + let writer = self.inner.write().await; let maybe_fork_details = &writer .fork_storage .inner diff --git a/crates/core/src/utils.rs b/crates/core/src/utils.rs index 9e688b85..f84d2b54 100644 --- a/crates/core/src/utils.rs +++ b/crates/core/src/utils.rs @@ -39,14 +39,6 @@ pub fn to_human_size(input: U256) -> String { tmp.iter().rev().collect() } -// TODO: Approach to encoding bytecode has changed in the core, so this function is likely no -// longer needed. See `zksync_contracts::SystemContractCode` for general approach. -pub fn bytecode_to_factory_dep(bytecode: Vec) -> Result<(H256, Vec), anyhow::Error> { - zksync_types::bytecode::validate_bytecode(&bytecode).context("Invalid bytecode")?; - let bytecode_hash = zksync_types::bytecode::BytecodeHash::for_bytecode(&bytecode).value(); - Ok((bytecode_hash, bytecode)) -} - /// Returns the actual [U64] block number from [BlockNumber]. /// /// # Arguments diff --git a/e2e-tests-rust/Cargo.lock b/e2e-tests-rust/Cargo.lock index d704cb5c..20e2dc5f 100644 --- a/e2e-tests-rust/Cargo.lock +++ b/e2e-tests-rust/Cargo.lock @@ -956,6 +956,7 @@ dependencies = [ "tempdir", "tokio", "tower 0.5.1", + "tower-http", ] [[package]] @@ -6285,6 +6286,20 @@ dependencies = [ "tower-service", ] +[[package]] +name = "tower-http" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" +dependencies = [ + "bitflags 2.6.0", + "bytes", + "http 1.1.0", + "pin-project-lite", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-layer" version = "0.3.3" diff --git a/e2e-tests-rust/src/lib.rs b/e2e-tests-rust/src/lib.rs index f0423224..596ff525 100644 --- a/e2e-tests-rust/src/lib.rs +++ b/e2e-tests-rust/src/lib.rs @@ -10,4 +10,4 @@ pub use provider::{ init_testing_provider, init_testing_provider_with_client, AnvilZKsyncApi, TestingProvider, DEFAULT_TX_VALUE, }; -pub use utils::get_node_binary_path; +pub use utils::{get_node_binary_path, LockedPort}; diff --git a/e2e-tests-rust/tests/lib.rs b/e2e-tests-rust/tests/lib.rs index 23fc97f5..9ae3d38f 100644 --- a/e2e-tests-rust/tests/lib.rs +++ b/e2e-tests-rust/tests/lib.rs @@ -4,11 +4,12 @@ use alloy::providers::Provider; use alloy::{ network::primitives::BlockTransactionsKind, primitives::U256, signers::local::PrivateKeySigner, }; +use alloy_zksync::node_bindings::AnvilZKsync; use anvil_zksync_core::node::VersionedState; use anvil_zksync_core::utils::write_json_file; use anvil_zksync_e2e_tests::{ get_node_binary_path, init_testing_provider, init_testing_provider_with_client, AnvilZKsyncApi, - ReceiptExt, ZksyncWalletProviderExt, DEFAULT_TX_VALUE, + LockedPort, ReceiptExt, ZksyncWalletProviderExt, DEFAULT_TX_VALUE, }; use anyhow::Context; use flate2::read::GzDecoder; @@ -778,3 +779,30 @@ async fn load_state_on_fork() -> anyhow::Result<()> { Ok(()) } + +#[tokio::test] +async fn test_server_port_fallback() -> anyhow::Result<()> { + let locked_port = LockedPort::acquire_unused().await?; + + let node1 = AnvilZKsync::new() + .path(get_node_binary_path()) + .port(locked_port.port) + .spawn(); + let port1 = node1.port(); + + let node2 = AnvilZKsync::new() + .path(get_node_binary_path()) + .port(locked_port.port) + .spawn(); + let port2 = node2.port(); + + assert_ne!( + port1, port2, + "The second instance should have a different port due to fallback" + ); + + drop(node1); + drop(node2); + + Ok(()) +} diff --git a/scripts/refresh_contracts.sh b/scripts/refresh_contracts.sh index 34bf88fc..a1319a8f 100755 --- a/scripts/refresh_contracts.sh +++ b/scripts/refresh_contracts.sh @@ -3,7 +3,7 @@ set -xe SRC_DIR=contracts/system-contracts/artifacts-zk/contracts-preprocessed DEV_CONTRACTS_SRC_DIR=contracts/l2-contracts/artifacts-zk/contracts/dev-contracts/ -DST_DIR=src/deps/contracts/ +DST_DIR=crates/core/src/deps/contracts/ mkdir -p $DST_DIR From e765daf9f385857c49873abbf641a89500dcc861 Mon Sep 17 00:00:00 2001 From: mm Date: Fri, 17 Jan 2025 11:28:18 +0100 Subject: [PATCH 6/6] fix clippy --- crates/api_server/src/impls/zkos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/api_server/src/impls/zkos.rs b/crates/api_server/src/impls/zkos.rs index 48c719de..ffc2a69c 100644 --- a/crates/api_server/src/impls/zkos.rs +++ b/crates/api_server/src/impls/zkos.rs @@ -14,6 +14,6 @@ impl ZKOSNamespace { #[async_trait] impl ZKOSNamespaceServer for ZKOSNamespace { async fn get_witness(&self, batch: u32) -> RpcResult> { - Ok(zkos_get_batch_witness(&batch).map(|data| hex::encode(data))) + Ok(zkos_get_batch_witness(&batch).map(hex::encode)) } }