Skip to content

Commit 2e1746f

Browse files
committed
feat: add inspect_system_call method to Evm trait
Adds a dedicated inspect_system_call method that executes system calls with inspection enabled without committing state changes. This separates the concerns of inspection and transaction execution for system calls. - Add inspect_system_call to Evm trait with documentation - Implement across all EVM types (Either, EthEvm, OpEvm) - Refactor transact_system_call to always use non-inspecting variant - Add required ResultAndState import to either.rs
1 parent c36acc5 commit 2e1746f

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

crates/evm/src/either.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Evm, EvmEnv};
22
use alloy_primitives::{Address, Bytes};
3-
use revm::context::{either, BlockEnv};
3+
use revm::context::{either, result::ResultAndState, BlockEnv};
44

55
impl<L, R> Evm for either::Either<L, R>
66
where
@@ -45,6 +45,15 @@ where
4545
either::for_both!(self, evm => evm.transact(tx))
4646
}
4747

48+
fn inspect_system_call(
49+
&mut self,
50+
caller: Address,
51+
contract: Address,
52+
data: Bytes,
53+
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
54+
either::for_both!(self, evm => evm.inspect_system_call(caller, contract, data))
55+
}
56+
4857
fn transact_system_call(
4958
&mut self,
5059
caller: Address,

crates/evm/src/eth/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,22 @@ where
137137
}
138138
}
139139

140+
fn inspect_system_call(
141+
&mut self,
142+
caller: Address,
143+
contract: Address,
144+
data: Bytes,
145+
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
146+
self.inner.inspect_system_call_with_caller(caller, contract, data)
147+
}
148+
140149
fn transact_system_call(
141150
&mut self,
142151
caller: Address,
143152
contract: Address,
144153
data: Bytes,
145154
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
146-
if self.inspect {
147-
self.inner.inspect_system_call_with_caller(caller, contract, data)
148-
} else {
149-
self.inner.system_call_with_caller(caller, contract, data)
150-
}
155+
self.inner.system_call_with_caller(caller, contract, data)
151156
}
152157

153158
fn finish(self) -> (Self::DB, EvmEnv<Self::Spec>) {

crates/evm/src/evm.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ pub trait Evm {
8888
self.transact_raw(tx.into_tx_env())
8989
}
9090

91+
/// Inspects a system call without committing state changes.
92+
///
93+
/// This method executes a system call with inspection enabled, allowing observation of the
94+
/// execution without modifying the underlying state. Similar to [`Evm::transact_system_call`]
95+
/// but returns the result with state changes that can be examined or discarded.
96+
fn inspect_system_call(
97+
&mut self,
98+
caller: Address,
99+
contract: Address,
100+
data: Bytes,
101+
) -> Result<ResultAndState<Self::HaltReason>, Self::Error>;
102+
91103
/// Executes a system call.
92104
///
93105
/// Note: this will only keep the target `contract` in the state. This is done because revm is

crates/op-evm/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,22 @@ where
116116
}
117117
}
118118

119+
fn inspect_system_call(
120+
&mut self,
121+
caller: Address,
122+
contract: Address,
123+
data: Bytes,
124+
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
125+
self.inner.inspect_system_call_with_caller(caller, contract, data)
126+
}
127+
119128
fn transact_system_call(
120129
&mut self,
121130
caller: Address,
122131
contract: Address,
123132
data: Bytes,
124133
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
125-
if self.inspect {
126-
self.inner.inspect_system_call_with_caller(caller, contract, data)
127-
} else {
128-
self.inner.system_call_with_caller(caller, contract, data)
129-
}
134+
self.inner.system_call_with_caller(caller, contract, data)
130135
}
131136

132137
fn finish(self) -> (Self::DB, EvmEnv<Self::Spec>) {

0 commit comments

Comments
 (0)