Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vm2 call tracer #2905

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ rand.workspace = true
test-casing.workspace = true
zksync_test_account.workspace = true
zksync_eth_signer.workspace = true
serde_json.workspace = true
3 changes: 3 additions & 0 deletions core/lib/multivm/src/tracers/call_tracer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub mod vm_virtual_blocks;
#[derive(Debug, Clone)]
pub struct CallTracer {
stack: Vec<FarcallAndNearCallCount>,
finished_calls: Vec<Call>,

result: Arc<OnceCell<Vec<Call>>>,

max_stack_depth: usize,
Expand All @@ -41,6 +43,7 @@ impl CallTracer {
pub fn new(result: Arc<OnceCell<Vec<Call>>>) -> Self {
Self {
stack: vec![],
finished_calls: vec![],
result,
max_stack_depth: 0,
max_near_calls: 0,
Expand Down
7 changes: 4 additions & 3 deletions core/lib/multivm/src/tracers/call_tracer/vm_latest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for CallTracer {
_bootloader_state: &BootloaderState,
_stop_reason: VmExecutionStopReason,
) {
self.store_result()
let result = std::mem::take(&mut self.finished_calls);
let cell = self.result.as_ref();
cell.set(result).unwrap();
}
}

Expand Down Expand Up @@ -191,15 +193,14 @@ 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
// Otherwise, push the current call to the stack, because it's the top level call
if let Some(parent_call) = self.stack.last_mut() {
parent_call.farcall.calls.push(current_call.farcall);
} else {
self.push_call_and_update_stats(current_call.farcall, current_call.near_calls_after);
self.finished_calls.push(current_call.farcall);
}
}
}
Loading
Loading