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
14 changes: 5 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ incremental = false
# patched for quantity U256 responses <https://github.com/recmo/uint/issues/224>
ruint = { git = "https://github.com/paradigmxyz/uint" }

revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }

[workspace.dependencies]
## eth
revm = { version = "3" }
Expand Down
6 changes: 6 additions & 0 deletions crates/revm/revm-inspectors/src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ impl ParityTraceBuilder {
let mut diff = StateDiff::default();

for (node, trace_address) in self.nodes.iter().zip(trace_addresses) {
// skip precompiles
if node.is_precompile() {
continue
}

if with_traces {
let trace = node.parity_transaction_trace(trace_address);
traces.push(trace);
Expand All @@ -145,6 +150,7 @@ impl ParityTraceBuilder {
self.nodes
.into_iter()
.zip(trace_addresses)
.filter(|(node, _)| !node.is_precompile())
.map(|(node, trace_address)| node.parity_transaction_trace(trace_address))
}

Expand Down
13 changes: 13 additions & 0 deletions crates/revm/revm-inspectors/src/tracing/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct TracingInspectorConfig {
pub record_stack_snapshots: bool,
/// Whether to record state diffs.
pub record_state_diff: bool,
/// Whether to ignore precompile calls.
pub exclude_precompile_calls: bool,
}

impl TracingInspectorConfig {
Expand All @@ -24,6 +26,7 @@ impl TracingInspectorConfig {
record_memory_snapshots: true,
record_stack_snapshots: true,
record_state_diff: false,
exclude_precompile_calls: false,
}
}

Expand All @@ -36,6 +39,7 @@ impl TracingInspectorConfig {
record_memory_snapshots: false,
record_stack_snapshots: false,
record_state_diff: false,
exclude_precompile_calls: true,
}
}

Expand All @@ -48,6 +52,7 @@ impl TracingInspectorConfig {
record_memory_snapshots: true,
record_stack_snapshots: true,
record_state_diff: true,
exclude_precompile_calls: false,
}
}

Expand All @@ -61,6 +66,14 @@ impl TracingInspectorConfig {
}
}

/// Configure whether calls to precompiles should be ignored.
///
/// If set to `true`, calls to precompiles without value transfers will be ignored.
pub fn set_exclude_precompile_calls(mut self, exclude_precompile_calls: bool) -> Self {
self.exclude_precompile_calls = exclude_precompile_calls;
self
}

/// Configure whether individual opcode level steps should be recorded
pub fn set_steps(mut self, record_steps: bool) -> Self {
self.record_steps = record_steps;
Expand Down
20 changes: 20 additions & 0 deletions crates/revm/revm-inspectors/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl TracingInspector {
/// Starts tracking a new trace.
///
/// Invoked on [Inspector::call].
#[allow(clippy::too_many_arguments)]
fn start_trace_on_call(
&mut self,
depth: usize,
Expand All @@ -109,6 +110,7 @@ impl TracingInspector {
value: U256,
kind: CallKind,
caller: Address,
maybe_precompile: Option<bool>,
) {
self.trace_stack.push(self.traces.push_trace(
0,
Expand All @@ -121,6 +123,7 @@ impl TracingInspector {
status: InstructionResult::Continue,
caller,
last_call_return_value: self.last_call_return_data.clone(),
maybe_precompile,
..Default::default()
},
));
Expand Down Expand Up @@ -318,13 +321,20 @@ where
_ => (inputs.context.caller, inputs.context.address),
};

// if calls to precompiles should be excluded, check whether this is a call to a precompile
let maybe_precompile = self
.config
.exclude_precompile_calls
.then(|| is_precompile_call(data, &to, inputs.transfer.value));

self.start_trace_on_call(
data.journaled_state.depth() as usize,
to,
inputs.input.clone(),
inputs.transfer.value,
inputs.context.scheme.into(),
from,
maybe_precompile,
);

(InstructionResult::Continue, Gas::new(0), Bytes::new())
Expand Down Expand Up @@ -367,6 +377,7 @@ where
inputs.value,
inputs.scheme.into(),
inputs.caller,
Some(false),
);

(InstructionResult::Continue, None, Gas::new(inputs.gas_limit), Bytes::default())
Expand Down Expand Up @@ -421,3 +432,12 @@ struct StackStep {
trace_idx: usize,
step_idx: usize,
}

/// Returns true if this a call to a precompile contract with `depth > 0 && value == 0`.
#[inline]
fn is_precompile_call<DB: Database>(data: &EVMData<'_, DB>, to: &Address, value: U256) -> bool {
if data.precompiles.contains(to) {
return data.journaled_state.depth() > 0 && value == U256::ZERO
}
false
}
10 changes: 10 additions & 0 deletions crates/revm/revm-inspectors/src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ pub(crate) struct CallTrace {
/// In other words, this is the callee if the [CallKind::Call] or the address of the created
/// contract if [CallKind::Create].
pub(crate) address: Address,
/// Whether this is a call to a precompile
///
/// Note: This is an Option because not all tracers make use of this
pub(crate) maybe_precompile: Option<bool>,
/// Holds the target for the selfdestruct refund target if `status` is
/// [InstructionResult::SelfDestruct]
pub(crate) selfdestruct_refund_target: Option<Address>,
Expand Down Expand Up @@ -168,6 +172,7 @@ impl Default for CallTrace {
kind: Default::default(),
value: Default::default(),
data: Default::default(),
maybe_precompile: None,
output: Default::default(),
last_call_return_value: None,
gas_used: Default::default(),
Expand Down Expand Up @@ -233,6 +238,11 @@ impl CallTraceNode {
stack
}

/// Returns true if this is a call to a precompile
pub(crate) fn is_precompile(&self) -> bool {
self.trace.maybe_precompile.unwrap_or(false)
}

/// Returns the kind of call the trace belongs to
pub(crate) fn kind(&self) -> CallKind {
self.trace.kind
Expand Down