Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ alloy = { version = "1.0.25", default-features = false, features = [
] }

revm = { version = "27.1", default-features = false }
revm-inspectors = { version = "0.27.1", optional = true }

dashmap = { version = "6.1.0", optional = true }
tracing = { version = "0.1.41", optional = true }
Expand All @@ -69,6 +70,7 @@ default = [
"call",
"concurrent-db",
"estimate_gas",
"tracing-inspectors",
"revm/std",
"revm/c-kzg",
"revm/blst",
Expand Down Expand Up @@ -111,3 +113,4 @@ full_env_cfg = [
"optional_eip3607",
"optional_no_base_fee",
]
tracing-inspectors = ["dep:revm-inspectors", "alloy/rpc-types-trace"]
6 changes: 6 additions & 0 deletions src/inspectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ pub use layer::Layered;
mod timeout;
pub use timeout::TimeLimit;

#[cfg(feature = "tracing-inspectors")]
mod tracing;

mod set;
pub use set::InspectorSet;

mod spanning;
pub use spanning::SpanningInspector;

mod with_output;
pub use with_output::InspectorWithOutput;

#[cfg(test)]
mod test {
use super::*;
Expand Down
20 changes: 20 additions & 0 deletions src/inspectors/tracing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::{helpers::Ctx, inspectors::InspectorWithOutput};
use alloy::rpc::types::trace::geth::FourByteFrame;
use revm::Database;
use revm_inspectors::tracing::FourByteInspector;

impl<Db: Database> InspectorWithOutput<Ctx<Db>> for FourByteInspector {
type Output = FourByteFrame;

fn has_output(&self) -> bool {
!self.inner().is_empty()
}

fn reset_output(&mut self) {
*self = Self::default();
}

fn take_output(&mut self) -> Self::Output {
std::mem::take(self).into()
}
}
49 changes: 49 additions & 0 deletions src/inspectors/with_output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::{helpers::Ctx, Trevm};
use revm::{inspector::CountInspector, Database};

/// An inspector that can produce an output value after EVM execution.
pub trait InspectorWithOutput<CTX>: revm::inspector::Inspector<CTX> {
/// The type of output produced by the inspector.
type Output;

/// Returns `true` if the inspector has a valid output value.
fn has_output(&self) -> bool;

/// Reset the output value to the default state, discarding any current
/// value.
fn reset_output(&mut self) {
self.take_output();
}

/// Take the output value from the inspector, resetting it to the default
/// state.
fn take_output(&mut self) -> Self::Output;
}

impl<Db: Database, Insp> Trevm<Db, Insp>
where
Insp: InspectorWithOutput<Ctx<Db>>,
{
/// Take the output value from the inspector.
///
/// This will also reset the output value in the inspector.
pub fn take_output(&mut self) -> Insp::Output {
self.inspector_mut().take_output()
}
}

impl<Ctx> InspectorWithOutput<Ctx> for CountInspector {
type Output = Self;

fn has_output(&self) -> bool {
self.total_opcodes() > 0
}

fn reset_output(&mut self) {
self.clear();
}

fn take_output(&mut self) -> Self::Output {
std::mem::take(self)
}
}