Skip to content

Commit

Permalink
feat: allow vm2 tracers to stop execution (#3183)
Browse files Browse the repository at this point in the history
Makes validation tracer nicer to implement.
  • Loading branch information
joonazan authored Nov 1, 2024
1 parent 069d38d commit 9dae839
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,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 = "457d8a7eea9093af9440662e33e598c13ba41633" }

# Consensus dependencies.
zksync_concurrency = "=0.5.0"
Expand Down
11 changes: 9 additions & 2 deletions core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs
Original file line number Diff line number Diff line change
@@ -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, GlobalStateInterface, Opcode, OpcodeType, ShouldStop, Tracer,
};
use zksync_vm_interface::CircuitStatistic;

use crate::vm_latest::tracers::circuits_capacity::*;
Expand All @@ -24,7 +26,10 @@ pub(super) struct CircuitsTracer {
}

impl Tracer for CircuitsTracer {
fn after_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, _: &mut S) {
fn after_instruction<OP: OpcodeType, S: GlobalStateInterface>(
&mut self,
_: &mut S,
) -> ShouldStop {
self.main_vm_cycles += 1;

match OP::VALUE {
Expand Down Expand Up @@ -110,6 +115,8 @@ impl Tracer for CircuitsTracer {
self.ram_permutation_cycles += UMA_READ_RAM_CYCLES;
}
}

ShouldStop::Continue
}

fn on_extra_prover_cycles(&mut self, stats: CycleStats) {
Expand Down
8 changes: 6 additions & 2 deletions core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,9 +76,13 @@ impl EvmDeployTracer {

impl Tracer for EvmDeployTracer {
#[inline(always)]
fn after_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, state: &mut S) {
fn after_instruction<OP: OpcodeType, S: GlobalStateInterface>(
&mut self,
state: &mut S,
) -> ShouldStop {
if matches!(OP::VALUE, Opcode::FarCall(CallingMode::Normal)) {
self.handle_far_call(state);
}
ShouldStop::Continue
}
}
10 changes: 10 additions & 0 deletions core/lib/multivm/src/versions/vm_fast/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ impl<S: ReadStorage, Tr: Tracer + Default> Vm<S, Tr> {
};
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) {
Expand Down
4 changes: 2 additions & 2 deletions prover/Cargo.lock

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

0 comments on commit 9dae839

Please sign in to comment.