Skip to content

Commit

Permalink
feat: expose storage to tracers (#77)
Browse files Browse the repository at this point in the history
Tracers can now read storage slots. This is required for the validation
tracer.
  • Loading branch information
joonazan authored Oct 18, 2024
1 parent a233d44 commit df5bec3
Show file tree
Hide file tree
Showing 24 changed files with 385 additions and 259 deletions.
14 changes: 8 additions & 6 deletions crates/vm2-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
//! ```
//! # use zksync_vm2_interface as zksync_vm2_interface_v1;
//! use zksync_vm2_interface_v1::{
//! StateInterface as StateInterfaceV1, Tracer as TracerV1, opcodes::NearCall,
//! StateInterface as StateInterfaceV1, GlobalStateInterface as GlobalStateInterfaceV1, Tracer as TracerV1, opcodes::NearCall,
//! };
//!
//! trait StateInterface: StateInterfaceV1 {
//! fn get_some_new_field(&self) -> u32;
//! }
//!
//! trait GlobalStateInterface: StateInterface + GlobalStateInterfaceV1 {}
//!
//! pub struct NewOpcode;
//!
//! #[derive(PartialEq, Eq)]
Expand All @@ -57,12 +59,12 @@
//! }
//!
//! trait Tracer {
//! fn before_instruction<OP: OpcodeType, S: StateInterface>(&mut self, _state: &mut S) {}
//! fn after_instruction<OP: OpcodeType, S: StateInterface>(&mut self, _state: &mut S) {}
//! fn before_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, state: &mut S) {}
//! fn after_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, state: &mut S) {}
//! }
//!
//! impl<T: TracerV1> Tracer for T {
//! fn before_instruction<OP: OpcodeType, S: StateInterface>(&mut self, state: &mut S) {
//! fn before_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, state: &mut S) {
//! match OP::VALUE {
//! Opcode::NewOpcode => {}
//! // Do this for every old opcode
Expand All @@ -71,13 +73,13 @@
//! }
//! }
//! }
//! fn after_instruction<OP: OpcodeType, S: StateInterface>(&mut self, _state: &mut S) {}
//! fn after_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, state: &mut S) {}
//! }
//!
//! // Now you can use the new features by implementing TracerV2
//! struct MyTracer;
//! impl Tracer for MyTracer {
//! fn before_instruction<OP: OpcodeType, S: StateInterface>(&mut self, state: &mut S) {
//! fn before_instruction<OP: OpcodeType, S: GlobalStateInterface>(&mut self, state: &mut S) {
//! if OP::VALUE == Opcode::NewOpcode {
//! state.get_some_new_field();
//! }
Expand Down
Loading

0 comments on commit df5bec3

Please sign in to comment.