From 30a12bc992605cda49a92c515d04b3014b27f0f1 Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Mon, 28 Oct 2024 18:37:23 +0100 Subject: [PATCH 1/5] integrate stage1 (tracers don't handle hooks yet) --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- .../multivm/src/versions/vm_fast/circuits_tracer.rs | 11 +++++++++-- prover/Cargo.lock | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 597da3c1b31b..2a3df5e9da2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11343,7 +11343,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=df5bec3d04d64d434f9b0ccb285ba4681008f7b3#df5bec3d04d64d434f9b0ccb285ba4681008f7b3" +source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" dependencies = [ "enum_dispatch", "primitive-types", @@ -11355,7 +11355,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=df5bec3d04d64d434f9b0ccb285ba4681008f7b3#df5bec3d04d64d434f9b0ccb285ba4681008f7b3" +source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" dependencies = [ "primitive-types", ] diff --git a/Cargo.toml b/Cargo.toml index 6d51e5060aa8..dfdacb44a573 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,7 +230,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" } zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" } # New VM; pinned to a specific commit because of instability -zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "df5bec3d04d64d434f9b0ccb285ba4681008f7b3" } +zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "f71f0650cb84888d37d58e5deece42f69eae5200" } # Consensus dependencies. zksync_concurrency = "=0.5.0" diff --git a/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs b/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs index f588f20ab25d..3585ea876daf 100644 --- a/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs +++ b/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs @@ -1,5 +1,7 @@ use circuit_sequencer_api_1_5_0::{geometry_config::get_geometry_config, toolset::GeometryConfig}; -use zksync_vm2::interface::{CycleStats, GlobalStateInterface, Opcode, OpcodeType, Tracer}; +use zksync_vm2::interface::{ + CycleStats, ExecutionStatus, GlobalStateInterface, Opcode, OpcodeType, Tracer, +}; use zksync_vm_interface::CircuitStatistic; use crate::vm_latest::tracers::circuits_capacity::*; @@ -24,7 +26,10 @@ pub struct CircuitsTracer { } impl Tracer for CircuitsTracer { - fn after_instruction(&mut self, _: &mut S) { + fn after_instruction( + &mut self, + _: &mut S, + ) -> ExecutionStatus { self.main_vm_cycles += 1; match OP::VALUE { @@ -110,6 +115,8 @@ impl Tracer for CircuitsTracer { self.ram_permutation_cycles += UMA_READ_RAM_CYCLES; } } + + ExecutionStatus::Running } fn on_extra_prover_cycles(&mut self, stats: CycleStats) { diff --git a/prover/Cargo.lock b/prover/Cargo.lock index d68ef368a4aa..b4a1f786a81c 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -8685,7 +8685,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=df5bec3d04d64d434f9b0ccb285ba4681008f7b3#df5bec3d04d64d434f9b0ccb285ba4681008f7b3" +source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" dependencies = [ "enum_dispatch", "primitive-types", @@ -8697,7 +8697,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=df5bec3d04d64d434f9b0ccb285ba4681008f7b3#df5bec3d04d64d434f9b0ccb285ba4681008f7b3" +source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" dependencies = [ "primitive-types", ] From 1983bd171aa53c69a890a1836e1e7b2ba395e96a Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Tue, 29 Oct 2024 12:39:56 +0100 Subject: [PATCH 2/5] version of vm2 that inlines ExecutionStatus::merge --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- prover/Cargo.lock | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a3df5e9da2e..4160b66ed1d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11343,7 +11343,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" +source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" dependencies = [ "enum_dispatch", "primitive-types", @@ -11355,7 +11355,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" +source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" dependencies = [ "primitive-types", ] diff --git a/Cargo.toml b/Cargo.toml index dfdacb44a573..41c3df46c355 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,7 +230,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" } zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" } # New VM; pinned to a specific commit because of instability -zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "f71f0650cb84888d37d58e5deece42f69eae5200" } +zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "fd27994d1d88ea4868d9ad74746bf274b97126d1" } # Consensus dependencies. zksync_concurrency = "=0.5.0" diff --git a/prover/Cargo.lock b/prover/Cargo.lock index b4a1f786a81c..3449f0758554 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -8685,7 +8685,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" +source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" dependencies = [ "enum_dispatch", "primitive-types", @@ -8697,7 +8697,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=f71f0650cb84888d37d58e5deece42f69eae5200#f71f0650cb84888d37d58e5deece42f69eae5200" +source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" dependencies = [ "primitive-types", ] From c25c17adcbb51f55bdc363144c6115f2db9e353a Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Thu, 31 Oct 2024 12:59:13 +0100 Subject: [PATCH 3/5] update to version that differentiates tracer stop --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- .../multivm/src/versions/vm_fast/circuits_tracer.rs | 6 +++--- core/lib/multivm/src/versions/vm_fast/vm.rs | 10 ++++++++++ prover/Cargo.lock | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4160b66ed1d5..ba85adcef11d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11343,7 +11343,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" +source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" dependencies = [ "enum_dispatch", "primitive-types", @@ -11355,7 +11355,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" +source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" dependencies = [ "primitive-types", ] diff --git a/Cargo.toml b/Cargo.toml index 41c3df46c355..948f0eb4f27b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,7 +230,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" } zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" } # New VM; pinned to a specific commit because of instability -zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "fd27994d1d88ea4868d9ad74746bf274b97126d1" } +zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "edb7c4538414c7e587fad3dd73835fb536af2e56" } # Consensus dependencies. zksync_concurrency = "=0.5.0" diff --git a/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs b/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs index 3585ea876daf..dc1bdce6d67c 100644 --- a/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs +++ b/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs @@ -1,6 +1,6 @@ use circuit_sequencer_api_1_5_0::{geometry_config::get_geometry_config, toolset::GeometryConfig}; use zksync_vm2::interface::{ - CycleStats, ExecutionStatus, GlobalStateInterface, Opcode, OpcodeType, Tracer, + CycleStats, GlobalStateInterface, Opcode, OpcodeType, ShouldStop, Tracer, }; use zksync_vm_interface::CircuitStatistic; @@ -29,7 +29,7 @@ impl Tracer for CircuitsTracer { fn after_instruction( &mut self, _: &mut S, - ) -> ExecutionStatus { + ) -> ShouldStop { self.main_vm_cycles += 1; match OP::VALUE { @@ -116,7 +116,7 @@ impl Tracer for CircuitsTracer { } } - ExecutionStatus::Running + ShouldStop::Continue } fn on_extra_prover_cycles(&mut self, stats: CycleStats) { diff --git a/core/lib/multivm/src/versions/vm_fast/vm.rs b/core/lib/multivm/src/versions/vm_fast/vm.rs index 6ebc4b9c5716..684f01dac5eb 100644 --- a/core/lib/multivm/src/versions/vm_fast/vm.rs +++ b/core/lib/multivm/src/versions/vm_fast/vm.rs @@ -205,6 +205,16 @@ impl Vm { }; break (ExecutionResult::Halt { reason }, true); } + ExecutionEnd::StoppedByTracer => { + break ( + ExecutionResult::Halt { + reason: Halt::TracerCustom( + "Unexpectedly stopped by tracer".to_string(), + ), + }, + false, + ); + } }; match Hook::from_u32(hook) { diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 3449f0758554..d3ab0bcc4255 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -8685,7 +8685,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" +source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" dependencies = [ "enum_dispatch", "primitive-types", @@ -8697,7 +8697,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=fd27994d1d88ea4868d9ad74746bf274b97126d1#fd27994d1d88ea4868d9ad74746bf274b97126d1" +source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" dependencies = [ "primitive-types", ] From d0c7c3372c6c7a359a057215752e6e573b4cbd5c Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Thu, 31 Oct 2024 13:25:33 +0100 Subject: [PATCH 4/5] point to master of vm2 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- prover/Cargo.lock | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba85adcef11d..bb8ef1848fd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11343,7 +11343,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" +source = "git+https://github.com/matter-labs/vm2.git?rev=457d8a7eea9093af9440662e33e598c13ba41633#457d8a7eea9093af9440662e33e598c13ba41633" dependencies = [ "enum_dispatch", "primitive-types", @@ -11355,7 +11355,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" +source = "git+https://github.com/matter-labs/vm2.git?rev=457d8a7eea9093af9440662e33e598c13ba41633#457d8a7eea9093af9440662e33e598c13ba41633" dependencies = [ "primitive-types", ] diff --git a/Cargo.toml b/Cargo.toml index 948f0eb4f27b..e021de82e1ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,7 +230,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" } zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" } # New VM; pinned to a specific commit because of instability -zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "edb7c4538414c7e587fad3dd73835fb536af2e56" } +zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "457d8a7eea9093af9440662e33e598c13ba41633" } # Consensus dependencies. zksync_concurrency = "=0.5.0" diff --git a/prover/Cargo.lock b/prover/Cargo.lock index d3ab0bcc4255..809ed9b3a66d 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -8685,7 +8685,7 @@ dependencies = [ [[package]] name = "zksync_vm2" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" +source = "git+https://github.com/matter-labs/vm2.git?rev=457d8a7eea9093af9440662e33e598c13ba41633#457d8a7eea9093af9440662e33e598c13ba41633" dependencies = [ "enum_dispatch", "primitive-types", @@ -8697,7 +8697,7 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" version = "0.2.1" -source = "git+https://github.com/matter-labs/vm2.git?rev=edb7c4538414c7e587fad3dd73835fb536af2e56#edb7c4538414c7e587fad3dd73835fb536af2e56" +source = "git+https://github.com/matter-labs/vm2.git?rev=457d8a7eea9093af9440662e33e598c13ba41633#457d8a7eea9093af9440662e33e598c13ba41633" dependencies = [ "primitive-types", ] From 9d4fb3e5929fefd9ed1e63ba7fa33465444c83fe Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Fri, 1 Nov 2024 12:57:44 +0100 Subject: [PATCH 5/5] resolve conflict --- .../lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs b/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs index d869796cd2c1..1bc0ff5134f1 100644 --- a/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs +++ b/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs @@ -6,7 +6,7 @@ use zksync_system_constants::{CONTRACT_DEPLOYER_ADDRESS, KNOWN_CODES_STORAGE_ADD use zksync_types::U256; use zksync_utils::{bytecode::hash_evm_bytecode, h256_to_u256}; use zksync_vm2::interface::{ - CallframeInterface, CallingMode, GlobalStateInterface, Opcode, OpcodeType, Tracer, + CallframeInterface, CallingMode, GlobalStateInterface, Opcode, OpcodeType, ShouldStop, Tracer, }; use super::utils::read_fat_pointer; @@ -76,9 +76,13 @@ impl EvmDeployTracer { impl Tracer for EvmDeployTracer { #[inline(always)] - fn after_instruction(&mut self, state: &mut S) { + fn after_instruction( + &mut self, + state: &mut S, + ) -> ShouldStop { if matches!(OP::VALUE, Opcode::FarCall(CallingMode::Normal)) { self.handle_far_call(state); } + ShouldStop::Continue } }