Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(op): fix inspection call #2184

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 19 additions & 1 deletion crates/handler/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@ impl<
{
}

/// Main logic of Ethereum Mainnet execution.
///
/// The starting point for execution is the `run` method. And without overriding
/// any methods allows you to execute Ethereum mainnet transactions.
///
/// If there is a need to change parts of execution logic this can be done by changing default
/// method implementation.
///
/// Handler logic is split in four parts:
/// * Verification - loads caller account checks initial gas requirement.
/// * Pre execution - loads and warms rest of accounts and deducts initial gas.
/// * Execution - Executed the main frame loop. It calls [`Frame`] for sub call logic.
/// * Post execution - Calculates the final refund, checks gas floor, reimburses caller and
/// rewards beneficiary.
pub trait Handler {
/// The EVM type that contains Context, Instruction, Precompiles.
type Evm: EvmTr<Context: ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>>>;
/// Error that is going to be returned.
type Error: EvmTrError<Self::Evm>;
/// Frame type contains data for frame execution. EthFrame currently supports Call, Create and EofCreate frames.
// TODO `FrameResult` should be a generic trait.
// TODO `FrameInit` should be a generic.
type Frame: Frame<
Expand All @@ -43,7 +60,8 @@ pub trait Handler {
FrameResult = FrameResult,
FrameInit = FrameInput,
>;
// TODO `HaltReason` should be part of the output.
/// Halt reason type is part of the output
/// TODO `HaltReason` should be part of the output.
type HaltReason: HaltReasonTr;

#[inline]
Expand Down
8 changes: 5 additions & 3 deletions crates/optimism/src/api/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use revm::{
Cfg, ContextTr, Database, JournalTr,
},
handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider},
inspector::{InspectCommitEvm, InspectEvm, Inspector, JournalExt},
inspector::{
InspectCommitEvm, InspectEvm, Inspector, InspectorEvmTr, InspectorHandler, JournalExt,
},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
};
Expand Down Expand Up @@ -83,14 +85,14 @@ where

fn inspect_previous(&mut self) -> Self::Output {
let mut h = OpHandler::<_, _, EthFrame<_, _, _>>::new();
h.run(self)
h.inspect_run(self)
}
}

impl<CTX, INSP, PRECOMPILE> InspectCommitEvm
for OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE>
where
CTX: OpContextTr<Journal: JournalExt, Db: DatabaseCommit>,
CTX: OpContextTr<Journal: JournalExt, Db: DatabaseCommit> + InspectorEvmTr,
INSP: Inspector<CTX, EthInterpreter>,
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
{
Expand Down
32 changes: 32 additions & 0 deletions crates/optimism/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use revm::{
instructions::{EthInstructions, InstructionProvider},
EvmTr,
},
inspector::{InspectorEvmTr, JournalExt},
interpreter::{
interpreter::EthInterpreter, Host, Interpreter, InterpreterAction, InterpreterTypes,
},
Inspector,
};

pub struct OpEvm<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = OpPrecompiles>(
Expand All @@ -25,6 +27,36 @@ impl<CTX: Host, INSP> OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, OpP
}
}

impl<CTX: ContextSetters, INSP, I, P> InspectorEvmTr for OpEvm<CTX, INSP, I, P>
where
CTX: ContextTr<Journal: JournalExt>,
I: InstructionProvider<
Context = CTX,
InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
>,
INSP: Inspector<CTX, I::InterpreterTypes>,
{
type Inspector = INSP;

fn inspector(&mut self) -> &mut Self::Inspector {
&mut self.0.data.inspector
}

fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) {
(&mut self.0.data.ctx, &mut self.0.data.inspector)
}

fn run_inspect_interpreter(
&mut self,
interpreter: &mut Interpreter<
<Self::Instructions as InstructionProvider>::InterpreterTypes,
>,
) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
{
self.0.run_inspect_interpreter(interpreter)
}
}

impl<CTX: ContextSetters, INSP, I, P> ContextSetters for OpEvm<CTX, INSP, I, P> {
type Tx = <CTX as ContextSetters>::Tx;
type Block = <CTX as ContextSetters>::Block;
Expand Down
Loading