Skip to content

Commit

Permalink
Remove result tracer and moved logic into vm run
Browse files Browse the repository at this point in the history
having the result handling in a tracer made the everything very obfuscating
  • Loading branch information
MarcosNicolau committed Aug 26, 2024
1 parent 36752f3 commit 210d8ca
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 171 deletions.
1 change: 0 additions & 1 deletion core/lib/multivm/src/tracers/call_tracer/era_vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use zksync_types::{
};

use super::CallTracer;

use crate::{
era_vm::tracers::traits::{Tracer, VmTracer},
interface::VmRevertReason,
Expand Down
75 changes: 6 additions & 69 deletions core/lib/multivm/src/versions/era_vm/tracers/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use zksync_state::{ReadStorage, StoragePtr};

use super::{
circuits_tracer::CircuitsTracer, dispatcher::TracerDispatcher, pubdata_tracer::PubdataTracer,
refunds_tracer::RefundsTracer, result_tracer::ResultTracer, traits::VmTracer,
refunds_tracer::RefundsTracer, traits::VmTracer,
};
use crate::{
era_vm::{bootloader_state::utils::apply_l2_block, hook::Hook, vm::Vm},
Expand All @@ -20,16 +20,14 @@ use crate::{
pub struct VmTracerManager<S: ReadStorage> {
execution_mode: VmExecutionMode,
pub dispatcher: TracerDispatcher<S>,
// this tracer collects the vm results for every transaction
// when the vm stops, the result would be available here
pub result_tracer: ResultTracer,
// This tracer is designed specifically for calculating refunds and saves the results to `VmResultAndLogs`.
// it is marked as optional, because tipically we want to track refunds when we are in OneTx mode.
pub refund_tracer: Option<RefundsTracer>,
// The pubdata tracer is responsible for inserting the pubdata packing information into the bootloader
// memory at the end of the batch. Its separation from the custom tracer
// ensures static dispatch, enhancing performance by avoiding dynamic dispatch overhe
// memory at the end of the batch.
pub pubdata_tracer: PubdataTracer,
// This tracers keeps track of opcodes calls and collects circuits statistics
// used later by the prover
pub circuits_tracer: CircuitsTracer,
storage: StoragePtr<S>,
}
Expand All @@ -47,54 +45,10 @@ impl<S: ReadStorage + 'static> VmTracerManager<S> {
dispatcher,
refund_tracer,
circuits_tracer: CircuitsTracer::new(),
result_tracer: ResultTracer::new(),
pubdata_tracer: pubdata_tracer.unwrap_or(PubdataTracer::new(execution_mode)),
storage,
}
}

fn set_final_batch_info(&self, vm: &mut Vm<S>) {
// set fictive l2 block
let txs_index = vm.bootloader_state.free_tx_index();
let l2_block = vm.bootloader_state.insert_fictive_l2_block();
let mut memory = vec![];
apply_l2_block(&mut memory, l2_block, txs_index);
vm.write_to_bootloader_heap(memory);
}

fn handle_execution_output(
&mut self,
vm: &mut Vm<S>,
output: ExecutionOutput,
) -> TracerExecutionStatus {
match output {
ExecutionOutput::SuspendedOnHook {
hook,
pc_to_resume_from,
} => {
vm.suspended_at = pc_to_resume_from;
vm.inner.execution.current_frame_mut().unwrap().pc = vm.suspended_at as u64;
let hook = Hook::from_u32(hook);
self.bootloader_hook_call(vm, hook.clone(), &vm.get_hook_params());
match hook {
Hook::TxHasEnded => {
if let VmExecutionMode::OneTx = self.execution_mode {
TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish)
} else {
TracerExecutionStatus::Continue
}
}
Hook::FinalBatchInfo => {
self.set_final_batch_info(vm);
TracerExecutionStatus::Continue
}
_ => TracerExecutionStatus::Continue,
}
}
// any other output means the vm has finished executing
_ => TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish),
}
}
}

impl<S: ReadStorage> Tracer for VmTracerManager<S> {
Expand All @@ -103,7 +57,6 @@ impl<S: ReadStorage> Tracer for VmTracerManager<S> {
self.dispatcher.before_decoding(execution, state);

// Individual tracers
self.result_tracer.before_decoding(execution, state);
if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.before_decoding(execution, state);
}
Expand All @@ -116,7 +69,6 @@ impl<S: ReadStorage> Tracer for VmTracerManager<S> {
self.dispatcher.after_decoding(opcode, execution, state);

// Individual tracers
self.result_tracer.after_decoding(opcode, execution, state);
if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.after_decoding(opcode, execution, state);
}
Expand All @@ -135,8 +87,6 @@ impl<S: ReadStorage> Tracer for VmTracerManager<S> {
self.dispatcher.before_execution(opcode, execution, state);

// Individual tracers
self.result_tracer
.before_execution(opcode, execution, state);
if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.before_execution(opcode, execution, state);
}
Expand All @@ -151,7 +101,6 @@ impl<S: ReadStorage> Tracer for VmTracerManager<S> {
self.dispatcher.after_execution(opcode, execution, state);

// Individual tracers
self.result_tracer.after_execution(opcode, execution, state);
if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.after_execution(opcode, execution, state);
}
Expand All @@ -168,8 +117,6 @@ impl<S: ReadStorage + 'static> VmTracer<S> for VmTracerManager<S> {
self.dispatcher.before_bootloader_execution(state);

// Individual tracers
self.result_tracer.before_bootloader_execution(state);

if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.before_bootloader_execution(state);
}
Expand All @@ -182,7 +129,6 @@ impl<S: ReadStorage + 'static> VmTracer<S> for VmTracerManager<S> {
self.dispatcher.after_bootloader_execution(state);

// Individual tracers
self.result_tracer.after_bootloader_execution(state);
if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.after_bootloader_execution(state);
}
Expand All @@ -201,8 +147,6 @@ impl<S: ReadStorage + 'static> VmTracer<S> for VmTracerManager<S> {
.bootloader_hook_call(state, hook.clone(), hook_params);

// Individual tracers
self.result_tracer
.bootloader_hook_call(state, hook.clone(), hook_params);
if let Some(refunds_tracer) = &mut self.refund_tracer {
refunds_tracer.bootloader_hook_call(state, hook.clone(), hook_params);
}
Expand All @@ -220,10 +164,6 @@ impl<S: ReadStorage + 'static> VmTracer<S> for VmTracerManager<S> {
let mut result = self.dispatcher.after_vm_run(vm, output.clone());

// Individual tracers
result = self
.result_tracer
.after_vm_run(vm, output.clone())
.stricter(&result);
if let Some(refunds_tracer) = &mut self.refund_tracer {
result = refunds_tracer
.after_vm_run(vm, output.clone())
Expand All @@ -233,11 +173,8 @@ impl<S: ReadStorage + 'static> VmTracer<S> for VmTracerManager<S> {
.pubdata_tracer
.after_vm_run(vm, output.clone())
.stricter(&result);
result = self
.circuits_tracer
self.circuits_tracer
.after_vm_run(vm, output.clone())
.stricter(&result);

self.handle_execution_output(vm, output).stricter(&result)
.stricter(&result)
}
}
1 change: 0 additions & 1 deletion core/lib/multivm/src/versions/era_vm/tracers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ pub mod dispatcher;
pub mod manager;
pub mod pubdata_tracer;
pub mod refunds_tracer;
pub mod result_tracer;
pub mod traits;
85 changes: 0 additions & 85 deletions core/lib/multivm/src/versions/era_vm/tracers/result_tracer.rs

This file was deleted.

Loading

0 comments on commit 210d8ca

Please sign in to comment.