diff --git a/Cargo.lock b/Cargo.lock index 67c48847968b5..87d8bfba5f4d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -600,6 +600,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "alphanet-instructions" +version = "0.0.0" +source = "git+https://github.com/paradigmxyz/alphanet.git?rev=87be409#87be409101bab9c8977b0e74edfb25334511a74c" +dependencies = [ + "revm", + "revm-interpreter", + "revm-precompile", + "revm-primitives", +] + [[package]] name = "ammonia" version = "3.3.0" @@ -3948,6 +3959,7 @@ dependencies = [ "alloy-rpc-types", "alloy-sol-types", "alloy-transport", + "alphanet-instructions", "arrayvec", "auto_impl", "const-hex", diff --git a/Cargo.toml b/Cargo.toml index 3513cf6c18e5f..cff98f6027d75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -147,6 +147,7 @@ revm-primitives = { version = "3", default-features = false } revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "813d7e7", features = [ "serde", ] } +alphanet-instructions = { git = "https://github.com/paradigmxyz/alphanet.git", rev = "87be409", features = ["optimism"] } ## ethers ethers = { version = "2.0.14", default-features = false } diff --git a/crates/evm/core/Cargo.toml b/crates/evm/core/Cargo.toml index 9b558e350d530..70006b49db172 100644 --- a/crates/evm/core/Cargo.toml +++ b/crates/evm/core/Cargo.toml @@ -17,6 +17,7 @@ foundry-compilers.workspace = true foundry-config.workspace = true foundry-macros.workspace = true +alphanet-instructions.workspace = true alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] } alloy-json-abi.workspace = true alloy-primitives = { workspace = true, features = ["serde", "getrandom", "arbitrary", "rlp"] } diff --git a/crates/evm/core/src/utils.rs b/crates/evm/core/src/utils.rs index 20d8aa6478644..55d52f237d35c 100644 --- a/crates/evm/core/src/utils.rs +++ b/crates/evm/core/src/utils.rs @@ -1,5 +1,6 @@ pub use crate::ic::*; use crate::{constants::DEFAULT_CREATE2_DEPLOYER, InspectorExt}; +use alphanet_instructions::{context::InstructionsContext, eip3074, BoxedInstructionWithOpCode}; use alloy_json_abi::{Function, JsonAbi}; use alloy_primitives::{Address, FixedBytes, U256}; use alloy_rpc_types::{Block, Transaction}; @@ -245,9 +246,29 @@ where // performance issues. let revm::primitives::EnvWithHandlerCfg { env, handler_cfg } = env; let context = revm::Context::new(revm::EvmContext::new_with_env(db, env), inspector); + let instructions_context = InstructionsContext::default(); let mut handler = revm::Handler::new(handler_cfg); handler.append_handler_register_plain(revm::inspector_handle_register); handler.append_handler_register_plain(create2_handler_register); + handler.append_handler_register_box(Box::new(move |handler| { + if let Some(ref mut table) = handler.instruction_table { + for boxed_instruction_with_opcode in + eip3074::boxed_instructions(instructions_context.clone()) + { + table.insert_boxed( + boxed_instruction_with_opcode.opcode, + boxed_instruction_with_opcode.boxed_instruction, + ); + } + } + let post_execution_context = instructions_context.clone(); + handler.post_execution.end = Arc::new(move |_, outcome: _| { + // at the end if the transaction execution we clear the instructions + post_execution_context.clear(); + outcome + }); + })); + revm::Evm::new(context, handler) }