Skip to content

Commit dfea9f0

Browse files
committed
integrate new revm version
1 parent 2a9d9ca commit dfea9f0

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

crates/evm/evm/src/inspectors/revert_diagnostic.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
use alloy_primitives::{Address, U256};
22
use alloy_sol_types::SolValue;
33
use foundry_evm_core::{
4-
backend::DatabaseExt,
4+
backend::DatabaseError,
55
constants::{CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS},
66
};
77
use revm::{
8+
bytecode::opcode::{EXTCODESIZE, REVERT},
9+
context::{Cfg, ContextTr, JournalTr},
10+
inspector::JournalExt,
811
interpreter::{
9-
opcode::{EXTCODESIZE, REVERT},
10-
CallInputs, CallOutcome, CallScheme, InstructionResult, Interpreter, InterpreterAction,
11-
InterpreterResult,
12+
interpreter::EthInterpreter, interpreter_types::Jumps, CallInputs, CallOutcome, CallScheme,
13+
InstructionResult, Interpreter, InterpreterAction, InterpreterResult,
1214
},
1315
precompile::{PrecompileSpecId, Precompiles},
14-
primitives::SpecId,
15-
Database, EvmContext, Inspector,
16+
primitives::hardfork::SpecId,
17+
Database, Inspector,
1618
};
1719
use std::fmt;
1820

@@ -62,9 +64,9 @@ impl fmt::Display for DetailedRevertReason {
6264
#[derive(Clone, Debug, Default)]
6365
pub struct RevertDiagnostic {
6466
/// Tracks calls with calldata that target an address without executable code.
65-
pub non_contract_call: Option<(Address, CallScheme, u64)>,
67+
pub non_contract_call: Option<(Address, CallScheme, usize)>,
6668
/// Tracks EXTCODESIZE checks that target an address without executable code.
67-
pub non_contract_size_check: Option<(Address, u64)>,
69+
pub non_contract_size_check: Option<(Address, usize)>,
6870
/// Whether the step opcode is EXTCODESIZE or not.
6971
pub is_extcodesize_step: bool,
7072
}
@@ -109,31 +111,36 @@ impl RevertDiagnostic {
109111
/// Injects the revert diagnostic into the debug traces. Should only be called after a revert.
110112
fn handle_revert_diagnostic(&self, interp: &mut Interpreter) {
111113
if let Some(reason) = self.reason() {
112-
interp.instruction_result = InstructionResult::Revert;
113-
interp.next_action = InterpreterAction::Return {
114+
interp.control.instruction_result = InstructionResult::Revert;
115+
interp.control.next_action = InterpreterAction::Return {
114116
result: InterpreterResult {
115117
output: reason.to_string().abi_encode().into(),
116-
gas: interp.gas,
118+
gas: interp.control.gas,
117119
result: InstructionResult::Revert,
118120
},
119121
};
120122
}
121123
}
122124
}
123125

124-
impl<DB: Database + DatabaseExt> Inspector<DB> for RevertDiagnostic {
126+
impl<CTX, D> Inspector<CTX, EthInterpreter> for RevertDiagnostic
127+
where
128+
D: Database<Error = DatabaseError>,
129+
CTX: ContextTr<Db = D>,
130+
CTX::Journal: JournalExt,
131+
{
125132
/// Tracks the first call with non-zero calldata that targets a non-contract address. Excludes
126133
/// precompiles and test addresses.
127-
fn call(&mut self, ctx: &mut EvmContext<DB>, inputs: &mut CallInputs) -> Option<CallOutcome> {
134+
fn call(&mut self, ctx: &mut CTX, inputs: &mut CallInputs) -> Option<CallOutcome> {
128135
let target = self.code_target_address(inputs);
129136

130-
if IGNORE.contains(&target) || self.is_precompile(ctx.spec_id(), target) {
137+
if IGNORE.contains(&target) || self.is_precompile(ctx.cfg().spec().into(), target) {
131138
return None;
132139
}
133140

134-
if let Ok(state) = ctx.code(target) {
141+
if let Ok(state) = ctx.journal().code(target) {
135142
if state.is_empty() && !inputs.input.is_empty() {
136-
self.non_contract_call = Some((target, inputs.scheme, ctx.journaled_state.depth()));
143+
self.non_contract_call = Some((target, inputs.scheme, ctx.journal().depth()));
137144
}
138145
}
139146
None
@@ -150,14 +157,14 @@ impl<DB: Database + DatabaseExt> Inspector<DB> for RevertDiagnostic {
150157
/// When an `EXTCODESIZE` opcode occurs:
151158
/// - Optimistically caches the target address and current depth in `non_contract_size_check`,
152159
/// pending later validation.
153-
fn step(&mut self, interp: &mut Interpreter, ctx: &mut EvmContext<DB>) {
160+
fn step(&mut self, interp: &mut Interpreter, ctx: &mut CTX) {
154161
// REVERT (offset, size)
155-
if REVERT == interp.current_opcode() {
156-
if let Ok(size) = interp.stack().peek(1) {
162+
if REVERT == interp.bytecode.opcode() {
163+
if let Ok(size) = interp.stack.peek(1) {
157164
if size == U256::ZERO {
158165
// Check empty revert with same depth as a non-contract call
159166
if let Some((_, _, depth)) = self.non_contract_call {
160-
if ctx.journaled_state.depth() == depth {
167+
if ctx.journal().depth() == depth {
161168
self.handle_revert_diagnostic(interp);
162169
} else {
163170
self.non_contract_call = None;
@@ -167,7 +174,7 @@ impl<DB: Database + DatabaseExt> Inspector<DB> for RevertDiagnostic {
167174

168175
// Check empty revert with same depth as a non-contract size check
169176
if let Some((_, depth)) = self.non_contract_size_check {
170-
if depth == ctx.journaled_state.depth() {
177+
if depth == ctx.journal().depth() {
171178
self.handle_revert_diagnostic(interp);
172179
} else {
173180
self.non_contract_size_check = None;
@@ -177,24 +184,24 @@ impl<DB: Database + DatabaseExt> Inspector<DB> for RevertDiagnostic {
177184
}
178185
}
179186
// EXTCODESIZE (address)
180-
else if EXTCODESIZE == interp.current_opcode() {
181-
if let Ok(word) = interp.stack().peek(0) {
187+
else if EXTCODESIZE == interp.bytecode.opcode() {
188+
if let Ok(word) = interp.stack.peek(0) {
182189
let addr = Address::from_word(word.into());
183-
if IGNORE.contains(&addr) || self.is_precompile(ctx.spec_id(), addr) {
190+
if IGNORE.contains(&addr) || self.is_precompile(ctx.cfg().spec().into(), addr) {
184191
return;
185192
}
186193

187194
// Optimistically cache --> validated and cleared (if necessary) at `fn step_end()`
188-
self.non_contract_size_check = Some((addr, ctx.journaled_state.depth()));
195+
self.non_contract_size_check = Some((addr, ctx.journal().depth()));
189196
self.is_extcodesize_step = true;
190197
}
191198
}
192199
}
193200

194201
/// Tracks `EXTCODESIZE` output. If the bytecode size is 0, clears the cache.
195-
fn step_end(&mut self, interp: &mut Interpreter, _ctx: &mut EvmContext<DB>) {
202+
fn step_end(&mut self, interp: &mut Interpreter, _ctx: &mut CTX) {
196203
if self.is_extcodesize_step {
197-
if let Ok(size) = interp.stack().peek(0) {
204+
if let Ok(size) = interp.stack.peek(0) {
198205
if size != U256::ZERO {
199206
self.non_contract_size_check = None;
200207
}

0 commit comments

Comments
 (0)