From cc8fb04df30a74e0fe9b830fe8f5439bbad5e0f4 Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Tue, 24 Sep 2024 19:17:57 +0200 Subject: [PATCH] add gas calcs and call type --- Cargo.lock | 8 ++--- Cargo.toml | 2 +- .../src/tracers/call_tracer/vm_latest/mod.rs | 1 - .../src/versions/vm_fast/call_tracer.rs | 29 +++++++++++++++---- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50f0784d9fa..3fff1cca297 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10966,8 +10966,8 @@ dependencies = [ [[package]] name = "zksync_vm2" -version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2.git?rev=74577d9be13b1bff9d1a712389731f669b179e47#74577d9be13b1bff9d1a712389731f669b179e47" +version = "0.2.0" +source = "git+https://github.com/matter-labs/vm2.git?rev=83da8c5d447482aa167f5f1a9d8751b7328f6baf#83da8c5d447482aa167f5f1a9d8751b7328f6baf" dependencies = [ "enum_dispatch", "primitive-types", @@ -10978,8 +10978,8 @@ dependencies = [ [[package]] name = "zksync_vm2_interface" -version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2.git?rev=74577d9be13b1bff9d1a712389731f669b179e47#74577d9be13b1bff9d1a712389731f669b179e47" +version = "0.2.0" +source = "git+https://github.com/matter-labs/vm2.git?rev=83da8c5d447482aa167f5f1a9d8751b7328f6baf#83da8c5d447482aa167f5f1a9d8751b7328f6baf" dependencies = [ "primitive-types", ] diff --git a/Cargo.toml b/Cargo.toml index 5a8a507b034..56bfcf6d126 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -227,7 +227,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" } zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.5" } # New VM; pinned to a specific commit because of instability -zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "74577d9be13b1bff9d1a712389731f669b179e47" } +zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "83da8c5d447482aa167f5f1a9d8751b7328f6baf" } # Consensus dependencies. zksync_concurrency = "=0.1.1" diff --git a/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs b/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs index c7266b41e9d..afa02d24f20 100644 --- a/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs +++ b/core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs @@ -193,7 +193,6 @@ impl CallTracer { .farcall .parent_gas .saturating_sub(state.vm_local_state.callstack.current.ergs_remaining as u64); - self.save_output_latest(state, memory, ret_opcode, &mut current_call.farcall); // If there is a parent call, push the current call to it diff --git a/core/lib/multivm/src/versions/vm_fast/call_tracer.rs b/core/lib/multivm/src/versions/vm_fast/call_tracer.rs index 8f3be69182e..60a4b16f8bf 100644 --- a/core/lib/multivm/src/versions/vm_fast/call_tracer.rs +++ b/core/lib/multivm/src/versions/vm_fast/call_tracer.rs @@ -5,6 +5,7 @@ use zksync_vm_interface::Call; #[derive(Debug, Clone, Default)] pub struct CallTracer { stack: Vec, + finished_calls: Vec, current_stack_depth: usize, max_stack_depth: usize, @@ -19,8 +20,8 @@ struct FarcallAndNearCallCount { } impl CallTracer { - pub fn result(&self) -> Vec { - self.stack.iter().map(|x| x.farcall.clone()).collect() + pub fn result(self) -> Vec { + self.finished_calls } } @@ -31,12 +32,27 @@ impl Tracer for CallTracer { self.current_stack_depth += 1; self.max_stack_depth = self.max_stack_depth.max(self.current_stack_depth); + let current_gas = state.current_frame().gas() as u64; + let from = state.current_frame().caller(); + let to = state.current_frame().address(); self.stack.push(FarcallAndNearCallCount { farcall: Call { - r#type: /*match tipe { - zksync_vm2::zksync_vm2_interface::CallingMode::Normal => {*/ + r#type: match tipe { + zksync_vm2::interface::CallingMode::Normal => { zksync_vm_interface::CallType::Call(FarCallOpcode::Normal) - , + } + zksync_vm2::interface::CallingMode::Delegate => { + zksync_vm_interface::CallType::Call(FarCallOpcode::Delegate) + } + zksync_vm2::interface::CallingMode::Mimic => { + zksync_vm_interface::CallType::Call(FarCallOpcode::Mimic) + } + }, + from, + to, + // The previous frame always exists directly after a far call + parent_gas: current_gas + state.callframe(1).gas() as u64, + gas: current_gas, ..Default::default() }, near_calls_after: 0, @@ -59,6 +75,7 @@ impl Tracer for CallTracer { }; if current_call.near_calls_after == 0 { + // Might overflow due to stipend current_call.farcall.gas_used = current_call .farcall .parent_gas @@ -71,7 +88,7 @@ impl Tracer for CallTracer { if let Some(parent_call) = self.stack.last_mut() { parent_call.farcall.calls.push(current_call.farcall); } else { - self.stack.push(current_call); + self.finished_calls.push(current_call.farcall); } } else { current_call.near_calls_after -= 1;