diff --git a/core/lib/multivm/src/interface/traits/vm.rs b/core/lib/multivm/src/interface/traits/vm.rs index 035ffa90f35..45daf770681 100644 --- a/core/lib/multivm/src/interface/traits/vm.rs +++ b/core/lib/multivm/src/interface/traits/vm.rs @@ -1,51 +1,52 @@ -/// This module contains traits for the VM interface. -/// All VMs should implement these traits to be used in our system. -/// The trait is generic over the storage type, allowing it to be used with any storage implementation. -/// Additionally, this trait is generic over HistoryMode, allowing it to be used with or without history. -/// -/// `TracerDispatcher` is an associated type used to dispatch tracers in VMs. -/// It manages tracers across different VM versions. -/// Even though we use the same interface for all VM versions, -/// we can now specify only the necessary trait bounds for each VM version. -/// -/// Generally speaking, in most cases, the tracer dispatcher is a wrapper around `Vec>`, -/// where `VmTracer` is a trait implemented for a specific VM version. -/// -/// Example usage: -/// ``` -/// use std::{ -/// cell::RefCell, -/// rc::Rc, -/// sync::Arc -/// }; -/// use once_cell::sync::OnceCell; -/// use multivm::{ -/// interface::{L1BatchEnv, SystemEnv, VmInterface}, -/// tracers::CallTracer , -/// vm_latest::ToTracerPointer -/// }; -/// use zksync_state::{InMemoryStorage, StorageView}; -/// use zksync_types::Transaction; -/// -/// // Prepare the environment for the VM. -/// let l1_batch_env = L1BatchEnv::new(); -/// let system_env = SystemEnv::default(); -/// // Create storage -/// let storage = Rc::new(RefCell::new(StorageView::new(InMemoryStorage::default()))); -/// // Instantiate VM with the desired version. -/// let mut vm = multivm::vm_latest::Vm::new(l1_batch_env, system_env, storage); -/// // Push a transaction to the VM. -/// let tx = Transaction::default(); -/// vm.push_transaction(tx); -/// // Instantiate a tracer. -/// let result = Arc::new(OnceCell::new()); -/// let call_tracer = CallTracer::new(result.clone()).into_tracer_pointer(); -/// // Inspect the transaction with a tracer. You can use either one tracer or a vector of tracers. -/// let result = vm.inspect(call_tracer.into(), multivm::interface::VmExecutionMode::OneTx); -/// -/// // To obtain the result of the entire batch, you can use the following code: -/// let result = vm.execute(multivm::interface::VmExecutionMode::Batch); -/// ``` +//! This module contains traits for the VM interface. +//! All VMs should implement these traits to be used in our system. +//! The trait is generic over the storage type, allowing it to be used with any storage implementation. +//! Additionally, this trait is generic over HistoryMode, allowing it to be used with or without history. +//! +//! `TracerDispatcher` is an associated type used to dispatch tracers in VMs. +//! It manages tracers across different VM versions. +//! Even though we use the same interface for all VM versions, +//! we can now specify only the necessary trait bounds for each VM version. +//! +//! Generally speaking, in most cases, the tracer dispatcher is a wrapper around `Vec>`, +//! where `VmTracer` is a trait implemented for a specific VM version. +//! +//! Example usage: +//! ``` +//! use std::{ +//! cell::RefCell, +//! rc::Rc, +//! sync::Arc +//! }; +//! use once_cell::sync::OnceCell; +//! use multivm::{ +//! interface::{L1BatchEnv, SystemEnv, VmInterface}, +//! tracers::CallTracer , +//! vm_latest::ToTracerPointer +//! }; +//! use zksync_state::{InMemoryStorage, StorageView}; +//! use zksync_types::Transaction; +//! +//! // Prepare the environment for the VM. +//! let l1_batch_env = L1BatchEnv::new(); +//! let system_env = SystemEnv::default(); +//! // Create storage +//! let storage = Rc::new(RefCell::new(StorageView::new(InMemoryStorage::default()))); +//! // Instantiate VM with the desired version. +//! let mut vm = multivm::vm_latest::Vm::new(l1_batch_env, system_env, storage); +//! // Push a transaction to the VM. +//! let tx = Transaction::default(); +//! vm.push_transaction(tx); +//! // Instantiate a tracer. +//! let result = Arc::new(OnceCell::new()); +//! let call_tracer = CallTracer::new(result.clone()).into_tracer_pointer(); +//! // Inspect the transaction with a tracer. You can use either one tracer or a vector of tracers. +//! let result = vm.inspect(call_tracer.into(), multivm::interface::VmExecutionMode::OneTx); +//! +//! // To obtain the result of the entire batch, you can use the following code: +//! let result = vm.execute(multivm::interface::VmExecutionMode::Batch); +//! ``` + use crate::interface::types::errors::BytecodeCompressionError; use crate::interface::types::inputs::{L1BatchEnv, L2BlockEnv, SystemEnv, VmExecutionMode}; use crate::interface::types::outputs::{ diff --git a/core/lib/multivm/src/tracers/call_tracer/mod.rs b/core/lib/multivm/src/tracers/call_tracer/mod.rs index e168569a077..6694dd760d5 100644 --- a/core/lib/multivm/src/tracers/call_tracer/mod.rs +++ b/core/lib/multivm/src/tracers/call_tracer/mod.rs @@ -5,11 +5,12 @@ use zksync_types::vm_trace::Call; pub mod vm_latest; pub mod vm_virtual_blocks; -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub struct CallTracer { stack: Vec, - result: Option>>>, + result: Arc>>, } + #[derive(Debug, Clone)] struct FarcallAndNearCallCount { farcall: Call, @@ -20,7 +21,7 @@ impl CallTracer { pub fn new(result: Arc>>) -> Self { Self { stack: vec![], - result: Some(result), + result, } } @@ -32,11 +33,8 @@ impl CallTracer { } fn store_result(&mut self) { - if self.result.is_none() { - return; - } let result = self.extract_result(); - let cell = self.result.as_ref().unwrap(); + let cell = self.result.as_ref(); cell.set(result).unwrap(); } } diff --git a/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs b/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs index a8e44be24af..2d04098253c 100644 --- a/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs +++ b/core/lib/multivm/src/tracers/validator/vm_latest/mod.rs @@ -26,9 +26,6 @@ use crate::tracers::validator::{ValidationRoundResult, ValidationTracer}; use crate::vm_latest::{BootloaderState, ZkSyncVmState}; -/// Tracer that is used to ensure that the validation adheres to all the rules -/// to prevent DDoS attacks on the server. - impl ValidationTracer { fn check_user_restrictions_vm_latest( &mut self, diff --git a/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs b/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs index ff754e7ceb5..d2155f4ecf8 100644 --- a/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs +++ b/core/lib/multivm/src/tracers/validator/vm_virtual_blocks/mod.rs @@ -22,8 +22,6 @@ use crate::interface::VmExecutionResultAndLogs; use crate::tracers::validator::types::{NewTrustedValidationItems, ValidationTracerMode}; use crate::tracers::validator::{ValidationRoundResult, ValidationTracer}; -/// Tracer that is used to ensure that the validation adheres to all the rules -/// to prevent DDoS attacks on the server. impl ValidationTracer { fn check_user_restrictions_vm_virtual_blocks( &mut self, diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs b/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs index 65b96ddf0d2..241c192dbf8 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/dispatcher.rs @@ -86,6 +86,7 @@ impl VmTracer for TracerDispatcher tracer.initialize_tracer(_state); } } + /// Run after each vm execution cycle #[inline(always)] fn finish_cycle( @@ -99,6 +100,7 @@ impl VmTracer for TracerDispatcher } result } + /// Run after the vm execution fn after_vm_execution( &mut self, diff --git a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs index e5ea69f4d12..713d2df250f 100644 --- a/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs +++ b/core/lib/multivm/src/versions/vm_virtual_blocks/tracers/dispatcher.rs @@ -93,6 +93,7 @@ impl ExecutionProcessing for TracerDispat tracer.initialize_tracer(_state); } } + /// Run after each vm execution cycle fn after_cycle( &mut self,