Skip to content

Commit

Permalink
Add bootloader hook fn to tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosNicolau committed Aug 23, 2024
1 parent 6803dc6 commit 0334465
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/era_vm/hook.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[derive(Debug)]

pub(crate) enum Hook {
pub enum Hook {
AccountValidationEntered,
PaymasterValidationEntered,
AccountValidationExited,
Expand Down
4 changes: 4 additions & 0 deletions core/lib/multivm/src/versions/era_vm/tracers/traits.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
pub use era_vm::tracers::tracer::Tracer;
use zksync_state::ReadStorage;
use zksync_types::U256;

use crate::era_vm::hook::Hook;
pub use crate::{era_vm::vm::Vm, vm_latest::ExecutionResult};

pub trait VmTracer<S: ReadStorage>: Tracer {
fn before_bootloader_execution(&mut self, _state: &mut Vm<S>) {}

fn after_bootloader_execution(&mut self, _state: &mut Vm<S>, _stop_reason: ExecutionResult) {}

fn bootloader_hook_call(&mut self, _state: &mut Vm<S>, _hook: Hook, _hook_params: &[U256; 3]) {}
}
11 changes: 2 additions & 9 deletions core/lib/multivm/src/versions/era_vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ impl<S: ReadStorage + 'static> Vm<S> {
}
};

tracer.bootloader_hook_call(self, Hook::from_u32(result), &self.get_hook_params());

match Hook::from_u32(result) {
Hook::PaymasterValidationEntered => {
// unused
Expand Down Expand Up @@ -372,15 +374,6 @@ impl<S: ReadStorage + 'static> Vm<S> {
(stop_reason, refunds)
}

fn get_vm_hook_params(&self, heap: &era_vm::execution::Heap) -> Vec<U256> {
(get_vm_hook_start_position_latest()..get_vm_hook_start_position_latest() + 2)
.map(|word| {
let res = heap.read((word * 32) as u32);
res
})
.collect()
}

pub(crate) fn insert_bytecodes<'a>(&mut self, bytecodes: impl IntoIterator<Item = &'a [u8]>) {
for code in bytecodes {
let mut program_code = vec![];
Expand Down

0 comments on commit 0334465

Please sign in to comment.