Skip to content

Commit

Permalink
add gas calcs and call type
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed Sep 25, 2024
1 parent 23b5343 commit cc8fb04
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 4 additions & 4 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 @@ -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"
Expand Down
1 change: 0 additions & 1 deletion core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 23 additions & 6 deletions core/lib/multivm/src/versions/vm_fast/call_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use zksync_vm_interface::Call;
#[derive(Debug, Clone, Default)]
pub struct CallTracer {
stack: Vec<FarcallAndNearCallCount>,
finished_calls: Vec<Call>,

current_stack_depth: usize,
max_stack_depth: usize,
Expand All @@ -19,8 +20,8 @@ struct FarcallAndNearCallCount {
}

impl CallTracer {
pub fn result(&self) -> Vec<Call> {
self.stack.iter().map(|x| x.farcall.clone()).collect()
pub fn result(self) -> Vec<Call> {
self.finished_calls
}
}

Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit cc8fb04

Please sign in to comment.