Skip to content

feat: add InspectorFor trait to enable multi-context EVM factories - #297

Draft
stevencartavia wants to merge 1 commit into
alloy-rs:mainfrom
stevencartavia:InspectorFor
Draft

stevencartavia wants to merge 1 commit into
alloy-rs:mainfrom
stevencartavia:InspectorFor

Conversation

@stevencartavia

Copy link
Copy Markdown
Contributor

Introduces InspectorFor<DB, I>, a new trait that separates factory metadata (EvmFactory) from inspector compatibility. The motivation is unblocking BlockExecutorFactory for multi-context EVM factories like EitherEvm — the current type Context<DB> generic associated type on EvmFactory makes it impossible to express dual inspector bounds (I: Inspector<EthEvmContext<DB>> + Inspector<OpContext<DB>>), which are required by foundry's enum EVM dispatcher. BlockExecutorFactory::create_executor is updated to bound on F::EvmFactory: InspectorFor<&mut State<DB>, I> instead. It makes multi-context EVM factories possible here and is a step toward network-agnostic block execution.

Path forward:

  1. alloy-op-evm — mechanical PR: remove type Evm<DB, I> and type Context<DB> GATs, implement InspectorFor<DB, I> where I: Inspector<OpContext<DB>>
  2. foundry — implement EitherEvmFactory wrapping existing EVM creation logic, wire TransactionExecutor as BlockExecutorFactory

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@mablr mablr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that customizable inspector is required by the current Foundry Evm design. And I haven't found so far any prettier way to do so directly in Foundry.

Comment thread crates/evm/src/evm.rs
Comment on lines +298 to +306
type Evm: Evm<
DB = DB,
Tx = <Self as EvmFactory>::Tx,
HaltReason = <Self as EvmFactory>::HaltReason,
Error = <Self as EvmFactory>::Error<DB::Error>,
Spec = <Self as EvmFactory>::Spec,
BlockEnv = <Self as EvmFactory>::BlockEnv,
Precompiles = <Self as EvmFactory>::Precompiles,
Inspector = I,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there's no other way than type erasure to implement Foundry's EitherEvm. The question is whether we're going to keep this pattern.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it serves as a good bridge for eventually removing it in the future but i think we should keep it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants