-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add vm error tracer
- Loading branch information
Showing
7 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use multivm::{ | ||
interface::dyn_tracers::vm_1_5_0::DynTracer, | ||
vm_latest::{HistoryMode, SimpleMemory, VmTracer}, | ||
zk_evm_latest::{ | ||
tracing::{AfterDecodingData, VmLocalStateData}, | ||
vm_state::ErrorFlags, | ||
}, | ||
}; | ||
use zksync_state::{ReadStorage, WriteStorage}; | ||
|
||
/// A tracer to allow logging low-level vm errors. | ||
#[derive(Debug, Default)] | ||
pub struct ErrorTracer; | ||
|
||
impl<S: ReadStorage, H: HistoryMode> DynTracer<S, SimpleMemory<H>> for ErrorTracer { | ||
fn after_decoding( | ||
&mut self, | ||
_state: VmLocalStateData<'_>, | ||
data: AfterDecodingData, | ||
_memory: &SimpleMemory<H>, | ||
) { | ||
if data.error_flags_accumulated.is_empty() { | ||
return; | ||
} | ||
|
||
let errors = parse_error_flags(&data.error_flags_accumulated); | ||
tracing::error!("vm error: {}", errors.join(", ")); | ||
} | ||
} | ||
|
||
impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for ErrorTracer {} | ||
|
||
fn parse_error_flags(error_flags: &ErrorFlags) -> Vec<String> { | ||
let mut errors = vec![]; | ||
if error_flags.contains(ErrorFlags::INVALID_OPCODE) { | ||
errors.push(String::from("Invalid opcode")); | ||
} | ||
if error_flags.contains(ErrorFlags::NOT_ENOUGH_ERGS) { | ||
errors.push(String::from("Not enough gas")); | ||
} | ||
if error_flags.contains(ErrorFlags::PRIVILAGED_ACCESS_NOT_FROM_KERNEL) { | ||
errors.push(String::from("Unauthorized privileged access")); | ||
} | ||
if error_flags.contains(ErrorFlags::WRITE_IN_STATIC_CONTEXT) { | ||
errors.push(String::from("Write applied in static context")); | ||
} | ||
if error_flags.contains(ErrorFlags::CALLSTACK_IS_FULL) { | ||
errors.push(String::from("Call stack full")); | ||
} | ||
errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// Contains tracer implementations for the zkEVM | ||
pub mod bootloader { | ||
pub use era_test_node::bootloader_debug::{BootloaderDebug, BootloaderDebugTracer}; | ||
} | ||
pub mod cheatcode; | ||
pub mod error; |