diff --git a/Cargo.lock b/Cargo.lock index 294f541e6b..976007cb4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2815,7 +2815,6 @@ dependencies = [ "alloy-provider", "alloy-sol-types", "anyhow", - "auto_impl", "criterion", "derive-where", "dyn-clone", @@ -2833,7 +2832,6 @@ dependencies = [ "revm-wiring", "rstest", "serde", - "serde_json", ] [[package]] @@ -2883,6 +2881,18 @@ dependencies = [ "serde", ] +[[package]] +name = "revm-inspector" +version = "1.0.0" +dependencies = [ + "auto_impl", + "derive-where", + "revm", + "revm-database", + "serde", + "serde_json", +] + [[package]] name = "revm-interpreter" version = "10.0.1" @@ -3011,6 +3021,7 @@ dependencies = [ "plain_hasher", "revm", "revm-database", + "revm-inspector", "serde", "serde_json", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 1bb9b0b2c3..884d8d16cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "crates/revm", "crates/primitives", "crates/interpreter", + "crates/inspector", "crates/precompile", "crates/optimism", "crates/database", @@ -39,6 +40,7 @@ state = { path = "crates/state", package = "revm-state", version = "1.0.0", defa wiring = { path = "crates/wiring", package = "revm-wiring", version = "1.0.0", default-features = false } revm = { path = "crates/revm", version = "14.0.1", default-features = false } interpreter = { path = "crates/interpreter", package = "revm-interpreter", version = "10.0.1", default-features = false } +inspector = { path = "crates/inspector", package = "revm-inspector", version = "1.0.0", default-features = false } precompile = { path = "crates/precompile", package = "revm-precompile", version = "11.0.1", default-features = false } [workspace.package] diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index 12ec072bef..0bda112fd6 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -9,15 +9,10 @@ license.workspace = true repository.workspace = true [dependencies] -database.workspace = true # revm -revm = { workspace = true, features = [ - "std", - "serde-json", - "hashbrown", - "c-kzg", - "blst", -] } +database.workspace = true +revm = { workspace = true, features = ["std", "hashbrown", "c-kzg", "blst"] } +inspector = { workspace = true, features = ["std", "serde", "serde-json"] } hash-db = "0.15" hex = "0.4" diff --git a/bins/revme/src/cmd/evmrunner.rs b/bins/revme/src/cmd/evmrunner.rs index f33a962007..780f0a0039 100644 --- a/bins/revme/src/cmd/evmrunner.rs +++ b/bins/revme/src/cmd/evmrunner.rs @@ -1,9 +1,8 @@ use clap::Parser; use database::BenchmarkDB; +use inspector::{inspector_handle_register, inspectors::TracerEip3155}; use revm::{ bytecode::{Bytecode, BytecodeDecodeError}, - inspector_handle_register, - inspectors::TracerEip3155, primitives::{address, Address, TxKind}, wiring::EthereumWiring, Database, Evm, diff --git a/bins/revme/src/cmd/statetest/runner.rs b/bins/revme/src/cmd/statetest/runner.rs index 9e1d501bc0..1ca40dbeb6 100644 --- a/bins/revme/src/cmd/statetest/runner.rs +++ b/bins/revme/src/cmd/statetest/runner.rs @@ -5,11 +5,10 @@ use super::{ }; use database::State; use indicatif::{ProgressBar, ProgressDrawTarget}; +use inspector::{inspector_handle_register, inspectors::TracerEip3155}; use revm::{ bytecode::Bytecode, database_interface::EmptyDB, - inspector_handle_register, - inspectors::TracerEip3155, interpreter::analysis::to_analysed, primitives::{keccak256, Bytes, TxKind, B256}, specification::{eip7702::AuthorizationList, hardfork::SpecId}, diff --git a/crates/inspector/Cargo.toml b/crates/inspector/Cargo.toml index b03c3cacb1..458b8c45eb 100644 --- a/crates/inspector/Cargo.toml +++ b/crates/inspector/Cargo.toml @@ -22,15 +22,28 @@ rust_2018_idioms = "deny" all = "warn" [dependencies] +# revm +revm.workspace = true + +# mics +auto_impl = { version = "1.2", default-features = false } +derive-where = { version = "1.2.7", default-features = false } + # Optional serde = { version = "1.0", default-features = false, features = [ "derive", "rc", ], optional = true } +serde_json = { version = "1.0", default-features = false, features = [ + "alloc", +], optional = true } +[dev-dependencies] +database = { workspace = true, features = ["serde"] } [features] default = ["std"] -std = ["serde?/std"] -serde = ["dep:serde"] -serde-json = ["serde"] +# Preserve ordeder of json +std = ["serde?/std", "serde_json?/std", "serde_json?/preserve_order"] +serde = ["dep:serde", "revm/serde", "database/serde"] +serde-json = ["serde", "dep:serde_json"] diff --git a/crates/revm/src/inspector/customprinter.rs b/crates/inspector/src/customprinter.rs similarity index 91% rename from crates/revm/src/inspector/customprinter.rs rename to crates/inspector/src/customprinter.rs index 1ba61e7cd0..2a1abb8250 100644 --- a/crates/revm/src/inspector/customprinter.rs +++ b/crates/inspector/src/customprinter.rs @@ -1,9 +1,12 @@ //! Custom print inspector, it has step level information of execution. //! It is a great tool if some debugging is needed. -use crate::{inspectors::GasInspector, EvmContext, EvmWiring, Inspector}; -use interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, OpCode}; -use primitives::{Address, U256}; +use crate::{inspectors::GasInspector, Inspector}; +use revm::{ + interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, OpCode}, + primitives::{Address, U256}, + EvmContext, EvmWiring, +}; /// Custom print [Inspector], it has step level information of execution. /// @@ -111,13 +114,17 @@ impl Inspector for CustomPrintTracer { #[cfg(test)] mod test { use super::*; - use crate::{inspector_handle_register, Evm}; - use bytecode::Bytecode; + use crate::inspector_handle_register; + use database::InMemoryDB; - use primitives::{address, bytes, keccak256, Bytes, TxKind, U256}; - use specification::hardfork::SpecId; - use state::AccountInfo; - use wiring::EthereumWiring; + use revm::{ + bytecode::Bytecode, + primitives::{address, bytes, keccak256, Bytes, TxKind, U256}, + specification::hardfork::SpecId, + state::AccountInfo, + wiring::EthereumWiring, + Evm, + }; #[test] fn gas_calculation_underflow() { diff --git a/crates/revm/src/inspector/eip3155.rs b/crates/inspector/src/eip3155.rs similarity index 96% rename from crates/revm/src/inspector/eip3155.rs rename to crates/inspector/src/eip3155.rs index 394a5dee91..06be7a5261 100644 --- a/crates/revm/src/inspector/eip3155.rs +++ b/crates/inspector/src/eip3155.rs @@ -1,13 +1,16 @@ -use crate::{inspectors::GasInspector, EvmContext, EvmWiring, Inspector}; +use crate::{inspectors::GasInspector, Inspector}; use derive_where::derive_where; - -use interpreter::{ - CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult, OpCode, +use revm::{ + interpreter::{ + CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult, + OpCode, + }, + primitives::{hex, HashMap, B256, U256}, + wiring::Transaction, + EvmContext, EvmWiring, }; -use primitives::{hex, HashMap, B256, U256}; use serde::Serialize; use std::io::Write; -use wiring::Transaction; /// [EIP-3155](https://eips.ethereum.org/EIPS/eip-3155) tracer [Inspector]. #[derive_where(Debug)] diff --git a/crates/revm/src/inspector/gas.rs b/crates/inspector/src/gas.rs similarity index 92% rename from crates/revm/src/inspector/gas.rs rename to crates/inspector/src/gas.rs index b0be32ce54..f9e505993d 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/inspector/src/gas.rs @@ -1,7 +1,10 @@ //! GasIspector. Helper Inspector to calculate gas for others. -use crate::{EvmContext, EvmWiring, Inspector}; -use interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter}; +use crate::Inspector; +use revm::{ + interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter}, + EvmContext, EvmWiring, +}; /// Helper [Inspector] that keeps track of gas. #[allow(dead_code)] @@ -70,12 +73,16 @@ impl Inspector for GasInspector { #[cfg(test)] mod tests { use super::*; - use crate::{inspector::inspector_handle_register, Evm, EvmWiring}; - use bytecode::Bytecode; + use crate::inspector_handle_register; use database::BenchmarkDB; - use interpreter::{opcode, Interpreter}; - use primitives::{address, Bytes, Log, TxKind}; - use wiring::{DefaultEthereumWiring, EthereumWiring, EvmWiring as PrimitiveEvmWiring}; + use revm::{ + bytecode::Bytecode, + interpreter::{opcode, Interpreter}, + primitives::{address, Bytes, Log, TxKind}, + wiring::EvmWiring as PrimitiveEvmWiring, + wiring::{DefaultEthereumWiring, EthereumWiring}, + Evm, EvmWiring, + }; type TestEvmWiring = DefaultEthereumWiring; diff --git a/crates/revm/src/inspector/handler_register.rs b/crates/inspector/src/handler_register.rs similarity index 95% rename from crates/revm/src/inspector/handler_register.rs rename to crates/inspector/src/handler_register.rs index f7b81225de..5bfbe510dc 100644 --- a/crates/revm/src/inspector/handler_register.rs +++ b/crates/inspector/src/handler_register.rs @@ -1,11 +1,12 @@ -use crate::{ - handler::register::EvmHandler, Context, EvmWiring, FrameOrResult, FrameResult, Inspector, - JournalEntry, -}; +use crate::Inspector; use core::cell::RefCell; -use interpreter::{opcode, opcode::DynInstruction, InstructionResult, Interpreter}; +use revm::{ + handler::register::EvmHandler, + interpreter::{opcode, opcode::DynInstruction, InstructionResult, Interpreter}, + wiring::result::EVMResultGeneric, + Context, EvmWiring, FrameOrResult, FrameResult, JournalEntry, +}; use std::{rc::Rc, sync::Arc, vec::Vec}; -use wiring::result::EVMResultGeneric; /// Provides access to an `Inspector` instance. pub trait GetInspector { @@ -261,15 +262,16 @@ fn inspector_instruction( #[cfg(test)] mod tests { use super::*; - use crate::{ - inspector::inspector_handle_register, inspectors::NoOpInspector, Evm, EvmContext, EvmWiring, - }; - use bytecode::Bytecode; + use crate::{inspector_handle_register, inspectors::NoOpInspector}; use database::BenchmarkDB; - use database_interface::EmptyDB; - use interpreter::{opcode, CallInputs, CallOutcome, CreateInputs, CreateOutcome}; - use primitives::{address, Bytes, TxKind}; - use wiring::{DefaultEthereumWiring, EthereumWiring, EvmWiring as PrimitiveEvmWiring}; + use revm::{ + bytecode::Bytecode, + database_interface::EmptyDB, + interpreter::{opcode, CallInputs, CallOutcome, CreateInputs, CreateOutcome}, + primitives::{address, Bytes, TxKind}, + wiring::{DefaultEthereumWiring, EthereumWiring, EvmWiring as PrimitiveEvmWiring}, + Evm, EvmContext, EvmWiring, + }; type TestEvmWiring = DefaultEthereumWiring; diff --git a/crates/revm/src/inspector.rs b/crates/inspector/src/inspector.rs similarity index 80% rename from crates/revm/src/inspector.rs rename to crates/inspector/src/inspector.rs index 70db076d2d..923f91c8ef 100644 --- a/crates/revm/src/inspector.rs +++ b/crates/inspector/src/inspector.rs @@ -1,37 +1,18 @@ -#[cfg(feature = "std")] -mod customprinter; -#[cfg(all(feature = "std", feature = "serde-json"))] -mod eip3155; -mod gas; -mod handler_register; -mod noop; - -pub use handler_register::{inspector_handle_register, GetInspector}; - -use interpreter::{ - CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, -}; - -use crate::{EvmContext, EvmWiring}; use auto_impl::auto_impl; -use primitives::{Address, Log, U256}; - -/// [Inspector] implementations. -pub mod inspectors { - #[cfg(feature = "std")] - pub use super::customprinter::CustomPrintTracer; - #[cfg(all(feature = "std", feature = "serde-json"))] - pub use super::eip3155::TracerEip3155; - pub use super::gas::GasInspector; - pub use super::noop::NoOpInspector; -} +use revm::{ + interpreter::{ + CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter, + }, + primitives::{Address, Log, U256}, + EvmContext, EvmWiring, +}; /// EVM [Interpreter] callbacks. #[auto_impl(&mut, Box)] pub trait Inspector { /// Called before the interpreter is initialized. /// - /// If `interp.instruction_result` is set to anything other than [crate::interpreter::InstructionResult::Continue] then the execution of the interpreter + /// If `interp.instruction_result` is set to anything other than [revm::interpreter::InstructionResult::Continue] then the execution of the interpreter /// is skipped. #[inline] fn initialize_interp( @@ -59,7 +40,7 @@ pub trait Inspector { /// Called after `step` when the instruction has been executed. /// - /// Setting `interp.instruction_result` to anything other than [crate::interpreter::InstructionResult::Continue] alters the execution + /// Setting `interp.instruction_result` to anything other than [revm::interpreter::InstructionResult::Continue] alters the execution /// of the interpreter. #[inline] fn step_end(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { @@ -77,7 +58,7 @@ pub trait Inspector { /// Called whenever a call to a contract is about to start. /// - /// InstructionResulting anything other than [crate::interpreter::InstructionResult::Continue] overrides the result of the call. + /// InstructionResulting anything other than [revm::interpreter::InstructionResult::Continue] overrides the result of the call. #[inline] fn call( &mut self, diff --git a/crates/inspector/src/lib.rs b/crates/inspector/src/lib.rs index 349d232839..59c784b2b4 100644 --- a/crates/inspector/src/lib.rs +++ b/crates/inspector/src/lib.rs @@ -4,3 +4,25 @@ #[cfg(not(feature = "std"))] extern crate alloc as std; + +#[cfg(feature = "std")] +mod customprinter; +#[cfg(all(feature = "std", feature = "serde-json"))] +mod eip3155; +mod gas; +mod handler_register; +mod inspector; +mod noop; + +pub use handler_register::{inspector_handle_register, GetInspector}; +pub use inspector::Inspector; + +/// [Inspector] implementations. +pub mod inspectors { + #[cfg(feature = "std")] + pub use super::customprinter::CustomPrintTracer; + #[cfg(all(feature = "std", feature = "serde-json"))] + pub use super::eip3155::TracerEip3155; + pub use super::gas::GasInspector; + pub use super::noop::NoOpInspector; +} diff --git a/crates/revm/src/inspector/noop.rs b/crates/inspector/src/noop.rs similarity index 84% rename from crates/revm/src/inspector/noop.rs rename to crates/inspector/src/noop.rs index 07a66c9c36..b95a21554b 100644 --- a/crates/revm/src/inspector/noop.rs +++ b/crates/inspector/src/noop.rs @@ -1,4 +1,5 @@ -use crate::{EvmWiring, Inspector}; +use crate::Inspector; +use revm::EvmWiring; /// Dummy [Inspector], helpful as standalone replacement. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/optimism/Cargo.toml b/crates/optimism/Cargo.toml index 46ce6feda2..cc188727f4 100644 --- a/crates/optimism/Cargo.toml +++ b/crates/optimism/Cargo.toml @@ -49,7 +49,6 @@ default = ["std", "c-kzg", "secp256k1", "portable", "blst"] std = ["serde?/std", "revm/std", "precompile/std"] hashbrown = ["revm/hashbrown"] serde = ["dep:serde", "revm/serde"] -serde-json = ["serde", "revm/serde-json"] portable = ["revm/portable"] dev = [ diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 81e0e7a1b9..8a3dd079b9 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -34,7 +34,6 @@ bytecode.workspace = true database = { workspace = true, optional = true } # misc -auto_impl = { version = "1.2", default-features = false } derive-where = { version = "1.2.7", default-features = false } dyn-clone = "1.0" @@ -43,9 +42,6 @@ serde = { version = "1.0", default-features = false, features = [ "derive", "rc", ], optional = true } -serde_json = { version = "1.0", default-features = false, features = [ - "alloc", -], optional = true } [dev-dependencies] database.workspace = true @@ -65,14 +61,11 @@ alloy-provider = "0.3" default = ["std", "c-kzg", "secp256k1", "portable", "blst"] std = [ "serde?/std", - "serde_json?/std", - "serde_json?/preserve_order", "interpreter/std", "precompile/std", ] hashbrown = ["interpreter/hashbrown", "precompile/hashbrown"] serde = ["dep:serde", "interpreter/serde", "database-interface/serde"] -serde-json = ["serde", "dep:serde_json"] arbitrary = ["primitives/arbitrary"] asm-keccak = ["primitives/asm-keccak"] portable = ["wiring/portable"] diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 3e3f0c64a7..da02554dc3 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -26,7 +26,6 @@ mod evm; mod evm_wiring; mod frame; pub mod handler; -mod inspector; mod journaled_state; // Export items. @@ -42,5 +41,4 @@ pub use evm::{Evm, CALL_STACK_LIMIT}; pub use evm_wiring::EvmWiring; pub use frame::{CallFrame, CreateFrame, Frame, FrameData, FrameOrResult, FrameResult}; pub use handler::{register::EvmHandler, Handler}; -pub use inspector::{inspector_handle_register, inspectors, GetInspector, Inspector}; pub use journaled_state::{JournalCheckpoint, JournalEntry, JournaledState}; diff --git a/graph.png b/graph.png deleted file mode 100644 index e69de29bb2..0000000000