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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.27.7"
version = "0.27.8"
rust-version = "1.83.0"
edition = "2021"
authors = ["init4"]
Expand Down
60 changes: 60 additions & 0 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,66 @@ where
}
}

// Layered inspector
impl<Db, Outer, Inner, TrevmState> Trevm<Db, Layered<Outer, Inner>, TrevmState>
where
Db: Database,
Outer: Inspector<Ctx<Db>>,
Inner: Inspector<Ctx<Db>>,
{
/// Remove the outer-layer inspector, leaving the inner-layer inspector in
/// place.
pub fn take_outer(self) -> (Outer, Trevm<Db, Inner, TrevmState>) {
let (outer, inner) = self.inner.inspector.into_parts();

(
outer,
Trevm {
inner: Box::new(Evm {
ctx: self.inner.ctx,
inspector: inner,
instruction: self.inner.instruction,
precompiles: self.inner.precompiles,
frame_stack: self.inner.frame_stack,
}),
state: self.state,
},
)
}

/// Remove the outer-layer inspector, leaving the inner-layer inspector in
/// place.
pub fn remove_outer(self) -> Trevm<Db, Inner, TrevmState> {
self.take_outer().1
}

/// Remove the inner-layer inspector, leaving the outer-layer inspector in
/// place.
pub fn take_inner(self) -> (Inner, Trevm<Db, Outer, TrevmState>) {
let (outer, inner) = self.inner.inspector.into_parts();

(
inner,
Trevm {
inner: Box::new(Evm {
ctx: self.inner.ctx,
inspector: outer,
instruction: self.inner.instruction,
precompiles: self.inner.precompiles,
frame_stack: self.inner.frame_stack,
}),
state: self.state,
},
)
}

/// Remove the inner-layer inspector, leaving the outer-layer inspector in
/// place.
pub fn remove_inner(self) -> Trevm<Db, Outer, TrevmState> {
self.take_inner().1
}
}

// --- ALL STATES, WITH State<Db>

impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Expand Down
10 changes: 8 additions & 2 deletions src/inspectors/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ impl<Outer, Inner> Layered<Outer, Inner> {
Layered { outer: self, inner }
}

/// Get a reference to the current inspector.
/// Decompose the [`Layered`] inspector into its outer and inner
/// inspectors.
pub fn into_parts(self) -> (Outer, Inner) {
(self.outer, self.inner)
}

/// Get a reference to the outer inspector.
pub const fn outer(&self) -> &Outer {
&self.outer
}

/// Get a mutable reference to the current inspector.
/// Get a mutable reference to the outer inspector.
pub const fn outer_mut(&mut self) -> &mut Outer {
&mut self.outer
}
Expand Down
2 changes: 2 additions & 0 deletions src/inspectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub use timeout::TimeLimit;

#[cfg(feature = "tracing-inspectors")]
mod tracing;
#[cfg(feature = "tracing-inspectors")]
pub use tracing::TracingInspectorOutput;

mod set;
pub use set::InspectorSet;
Expand Down
52 changes: 51 additions & 1 deletion src/inspectors/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
use crate::{helpers::Ctx, inspectors::InspectorWithOutput};
use alloy::rpc::types::trace::geth::FourByteFrame;
use revm::Database;
use revm_inspectors::tracing::FourByteInspector;
use revm_inspectors::tracing::{
CallTraceArena, FourByteInspector, GethTraceBuilder, ParityTraceBuilder, TracingInspector,
};

/// Output produced by the [`TracingInspector`].
#[derive(Clone, Debug)]
pub struct TracingInspectorOutput {
traces: CallTraceArena,
}

impl TracingInspectorOutput {
/// Creates a new output instance.
pub const fn new(traces: CallTraceArena) -> Self {
Self { traces }
}

/// Returns a reference to the traces produced by the inspector.
pub const fn traces(&self) -> &CallTraceArena {
&self.traces
}

/// Consumes the output and produces a Parity trace builder.
pub fn into_parity_builder(self) -> ParityTraceBuilder {
// NB: the second arguments are actually currently unused. This is
// weird.
ParityTraceBuilder::new(self.traces.into_nodes(), None, Default::default())
}

/// Consumes the output and produces a Geth trace builder.
pub fn into_geth_builder(self) -> GethTraceBuilder<'static> {
GethTraceBuilder::new(self.traces.into_nodes())
}
}

impl<Db: Database> InspectorWithOutput<Ctx<Db>> for TracingInspector {
type Output = TracingInspectorOutput;

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

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

fn take_output(&mut self) -> Self::Output {
let this = self.clone();
self.fuse();
TracingInspectorOutput::new(this.into_traces())
}
}

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