Skip to content

Commit 66adad0

Browse files
authored
feat: Restructuring Part3 inspector crate (#1788)
* feat: Restructuring Part3 inspector crate * fix serde include * fix docs
1 parent fa1e546 commit 66adad0

File tree

17 files changed

+125
-93
lines changed

17 files changed

+125
-93
lines changed

Cargo.lock

+13-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"crates/revm",
1010
"crates/primitives",
1111
"crates/interpreter",
12+
"crates/inspector",
1213
"crates/precompile",
1314
"crates/optimism",
1415
"crates/database",
@@ -39,6 +40,7 @@ state = { path = "crates/state", package = "revm-state", version = "1.0.0", defa
3940
wiring = { path = "crates/wiring", package = "revm-wiring", version = "1.0.0", default-features = false }
4041
revm = { path = "crates/revm", version = "14.0.1", default-features = false }
4142
interpreter = { path = "crates/interpreter", package = "revm-interpreter", version = "10.0.1", default-features = false }
43+
inspector = { path = "crates/inspector", package = "revm-inspector", version = "1.0.0", default-features = false }
4244
precompile = { path = "crates/precompile", package = "revm-precompile", version = "11.0.1", default-features = false }
4345

4446
[workspace.package]

bins/revme/Cargo.toml

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ license.workspace = true
99
repository.workspace = true
1010

1111
[dependencies]
12-
database.workspace = true
1312
# revm
14-
revm = { workspace = true, features = [
15-
"std",
16-
"serde-json",
17-
"hashbrown",
18-
"c-kzg",
19-
"blst",
20-
] }
13+
database.workspace = true
14+
revm = { workspace = true, features = ["std", "hashbrown", "c-kzg", "blst"] }
15+
inspector = { workspace = true, features = ["std", "serde", "serde-json"] }
2116

2217
hash-db = "0.15"
2318
hex = "0.4"

bins/revme/src/cmd/evmrunner.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use clap::Parser;
22
use database::BenchmarkDB;
3+
use inspector::{inspector_handle_register, inspectors::TracerEip3155};
34
use revm::{
45
bytecode::{Bytecode, BytecodeDecodeError},
5-
inspector_handle_register,
6-
inspectors::TracerEip3155,
76
primitives::{address, Address, TxKind},
87
wiring::EthereumWiring,
98
Database, Evm,

bins/revme/src/cmd/statetest/runner.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ use super::{
55
};
66
use database::State;
77
use indicatif::{ProgressBar, ProgressDrawTarget};
8+
use inspector::{inspector_handle_register, inspectors::TracerEip3155};
89
use revm::{
910
bytecode::Bytecode,
1011
database_interface::EmptyDB,
11-
inspector_handle_register,
12-
inspectors::TracerEip3155,
1312
interpreter::analysis::to_analysed,
1413
primitives::{keccak256, Bytes, TxKind, B256},
1514
specification::{eip7702::AuthorizationList, hardfork::SpecId},

crates/inspector/Cargo.toml

+16-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,28 @@ rust_2018_idioms = "deny"
2222
all = "warn"
2323

2424
[dependencies]
25+
# revm
26+
revm.workspace = true
27+
28+
# mics
29+
auto_impl = { version = "1.2", default-features = false }
30+
derive-where = { version = "1.2.7", default-features = false }
31+
2532
# Optional
2633
serde = { version = "1.0", default-features = false, features = [
2734
"derive",
2835
"rc",
2936
], optional = true }
37+
serde_json = { version = "1.0", default-features = false, features = [
38+
"alloc",
39+
], optional = true }
3040

41+
[dev-dependencies]
42+
database = { workspace = true, features = ["serde"] }
3143

3244
[features]
3345
default = ["std"]
34-
std = ["serde?/std"]
35-
serde = ["dep:serde"]
36-
serde-json = ["serde"]
46+
# Preserve ordeder of json
47+
std = ["serde?/std", "serde_json?/std", "serde_json?/preserve_order"]
48+
serde = ["dep:serde", "revm/serde", "database/serde"]
49+
serde-json = ["serde", "dep:serde_json"]

crates/revm/src/inspector/customprinter.rs renamed to crates/inspector/src/customprinter.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//! Custom print inspector, it has step level information of execution.
22
//! It is a great tool if some debugging is needed.
33
4-
use crate::{inspectors::GasInspector, EvmContext, EvmWiring, Inspector};
5-
use interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, OpCode};
6-
use primitives::{Address, U256};
4+
use crate::{inspectors::GasInspector, Inspector};
5+
use revm::{
6+
interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, OpCode},
7+
primitives::{Address, U256},
8+
EvmContext, EvmWiring,
9+
};
710

811
/// Custom print [Inspector], it has step level information of execution.
912
///
@@ -111,13 +114,17 @@ impl<EvmWiringT: EvmWiring> Inspector<EvmWiringT> for CustomPrintTracer {
111114
#[cfg(test)]
112115
mod test {
113116
use super::*;
114-
use crate::{inspector_handle_register, Evm};
115-
use bytecode::Bytecode;
117+
use crate::inspector_handle_register;
118+
116119
use database::InMemoryDB;
117-
use primitives::{address, bytes, keccak256, Bytes, TxKind, U256};
118-
use specification::hardfork::SpecId;
119-
use state::AccountInfo;
120-
use wiring::EthereumWiring;
120+
use revm::{
121+
bytecode::Bytecode,
122+
primitives::{address, bytes, keccak256, Bytes, TxKind, U256},
123+
specification::hardfork::SpecId,
124+
state::AccountInfo,
125+
wiring::EthereumWiring,
126+
Evm,
127+
};
121128

122129
#[test]
123130
fn gas_calculation_underflow() {

crates/revm/src/inspector/eip3155.rs renamed to crates/inspector/src/eip3155.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
use crate::{inspectors::GasInspector, EvmContext, EvmWiring, Inspector};
1+
use crate::{inspectors::GasInspector, Inspector};
22
use derive_where::derive_where;
3-
4-
use interpreter::{
5-
CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult, OpCode,
3+
use revm::{
4+
interpreter::{
5+
CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter, InterpreterResult,
6+
OpCode,
7+
},
8+
primitives::{hex, HashMap, B256, U256},
9+
wiring::Transaction,
10+
EvmContext, EvmWiring,
611
};
7-
use primitives::{hex, HashMap, B256, U256};
812
use serde::Serialize;
913
use std::io::Write;
10-
use wiring::Transaction;
1114

1215
/// [EIP-3155](https://eips.ethereum.org/EIPS/eip-3155) tracer [Inspector].
1316
#[derive_where(Debug)]

crates/revm/src/inspector/gas.rs renamed to crates/inspector/src/gas.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! GasIspector. Helper Inspector to calculate gas for others.
22
3-
use crate::{EvmContext, EvmWiring, Inspector};
4-
use interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter};
3+
use crate::Inspector;
4+
use revm::{
5+
interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter},
6+
EvmContext, EvmWiring,
7+
};
58

69
/// Helper [Inspector] that keeps track of gas.
710
#[allow(dead_code)]
@@ -70,12 +73,16 @@ impl<EvmWiringT: EvmWiring> Inspector<EvmWiringT> for GasInspector {
7073
#[cfg(test)]
7174
mod tests {
7275
use super::*;
73-
use crate::{inspector::inspector_handle_register, Evm, EvmWiring};
74-
use bytecode::Bytecode;
76+
use crate::inspector_handle_register;
7577
use database::BenchmarkDB;
76-
use interpreter::{opcode, Interpreter};
77-
use primitives::{address, Bytes, Log, TxKind};
78-
use wiring::{DefaultEthereumWiring, EthereumWiring, EvmWiring as PrimitiveEvmWiring};
78+
use revm::{
79+
bytecode::Bytecode,
80+
interpreter::{opcode, Interpreter},
81+
primitives::{address, Bytes, Log, TxKind},
82+
wiring::EvmWiring as PrimitiveEvmWiring,
83+
wiring::{DefaultEthereumWiring, EthereumWiring},
84+
Evm, EvmWiring,
85+
};
7986

8087
type TestEvmWiring = DefaultEthereumWiring;
8188

crates/revm/src/inspector/handler_register.rs renamed to crates/inspector/src/handler_register.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::{
2-
handler::register::EvmHandler, Context, EvmWiring, FrameOrResult, FrameResult, Inspector,
3-
JournalEntry,
4-
};
1+
use crate::Inspector;
52
use core::cell::RefCell;
6-
use interpreter::{opcode, opcode::DynInstruction, InstructionResult, Interpreter};
3+
use revm::{
4+
handler::register::EvmHandler,
5+
interpreter::{opcode, opcode::DynInstruction, InstructionResult, Interpreter},
6+
wiring::result::EVMResultGeneric,
7+
Context, EvmWiring, FrameOrResult, FrameResult, JournalEntry,
8+
};
79
use std::{rc::Rc, sync::Arc, vec::Vec};
8-
use wiring::result::EVMResultGeneric;
910

1011
/// Provides access to an `Inspector` instance.
1112
pub trait GetInspector<EvmWiringT: EvmWiring> {
@@ -261,15 +262,16 @@ fn inspector_instruction<EvmWiringT>(
261262
#[cfg(test)]
262263
mod tests {
263264
use super::*;
264-
use crate::{
265-
inspector::inspector_handle_register, inspectors::NoOpInspector, Evm, EvmContext, EvmWiring,
266-
};
267-
use bytecode::Bytecode;
265+
use crate::{inspector_handle_register, inspectors::NoOpInspector};
268266
use database::BenchmarkDB;
269-
use database_interface::EmptyDB;
270-
use interpreter::{opcode, CallInputs, CallOutcome, CreateInputs, CreateOutcome};
271-
use primitives::{address, Bytes, TxKind};
272-
use wiring::{DefaultEthereumWiring, EthereumWiring, EvmWiring as PrimitiveEvmWiring};
267+
use revm::{
268+
bytecode::Bytecode,
269+
database_interface::EmptyDB,
270+
interpreter::{opcode, CallInputs, CallOutcome, CreateInputs, CreateOutcome},
271+
primitives::{address, Bytes, TxKind},
272+
wiring::{DefaultEthereumWiring, EthereumWiring, EvmWiring as PrimitiveEvmWiring},
273+
Evm, EvmContext, EvmWiring,
274+
};
273275

274276
type TestEvmWiring = DefaultEthereumWiring;
275277

crates/revm/src/inspector.rs renamed to crates/inspector/src/inspector.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
1-
#[cfg(feature = "std")]
2-
mod customprinter;
3-
#[cfg(all(feature = "std", feature = "serde-json"))]
4-
mod eip3155;
5-
mod gas;
6-
mod handler_register;
7-
mod noop;
8-
9-
pub use handler_register::{inspector_handle_register, GetInspector};
10-
11-
use interpreter::{
12-
CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter,
13-
};
14-
15-
use crate::{EvmContext, EvmWiring};
161
use auto_impl::auto_impl;
17-
use primitives::{Address, Log, U256};
18-
19-
/// [Inspector] implementations.
20-
pub mod inspectors {
21-
#[cfg(feature = "std")]
22-
pub use super::customprinter::CustomPrintTracer;
23-
#[cfg(all(feature = "std", feature = "serde-json"))]
24-
pub use super::eip3155::TracerEip3155;
25-
pub use super::gas::GasInspector;
26-
pub use super::noop::NoOpInspector;
27-
}
2+
use revm::{
3+
interpreter::{
4+
CallInputs, CallOutcome, CreateInputs, CreateOutcome, EOFCreateInputs, Interpreter,
5+
},
6+
primitives::{Address, Log, U256},
7+
EvmContext, EvmWiring,
8+
};
289

2910
/// EVM [Interpreter] callbacks.
3011
#[auto_impl(&mut, Box)]
3112
pub trait Inspector<EvmWiringT: EvmWiring> {
3213
/// Called before the interpreter is initialized.
3314
///
34-
/// If `interp.instruction_result` is set to anything other than [crate::interpreter::InstructionResult::Continue] then the execution of the interpreter
15+
/// If `interp.instruction_result` is set to anything other than [revm::interpreter::InstructionResult::Continue] then the execution of the interpreter
3516
/// is skipped.
3617
#[inline]
3718
fn initialize_interp(
@@ -59,7 +40,7 @@ pub trait Inspector<EvmWiringT: EvmWiring> {
5940

6041
/// Called after `step` when the instruction has been executed.
6142
///
62-
/// Setting `interp.instruction_result` to anything other than [crate::interpreter::InstructionResult::Continue] alters the execution
43+
/// Setting `interp.instruction_result` to anything other than [revm::interpreter::InstructionResult::Continue] alters the execution
6344
/// of the interpreter.
6445
#[inline]
6546
fn step_end(&mut self, interp: &mut Interpreter, context: &mut EvmContext<EvmWiringT>) {
@@ -77,7 +58,7 @@ pub trait Inspector<EvmWiringT: EvmWiring> {
7758

7859
/// Called whenever a call to a contract is about to start.
7960
///
80-
/// InstructionResulting anything other than [crate::interpreter::InstructionResult::Continue] overrides the result of the call.
61+
/// InstructionResulting anything other than [revm::interpreter::InstructionResult::Continue] overrides the result of the call.
8162
#[inline]
8263
fn call(
8364
&mut self,

crates/inspector/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,25 @@
44

55
#[cfg(not(feature = "std"))]
66
extern crate alloc as std;
7+
8+
#[cfg(feature = "std")]
9+
mod customprinter;
10+
#[cfg(all(feature = "std", feature = "serde-json"))]
11+
mod eip3155;
12+
mod gas;
13+
mod handler_register;
14+
mod inspector;
15+
mod noop;
16+
17+
pub use handler_register::{inspector_handle_register, GetInspector};
18+
pub use inspector::Inspector;
19+
20+
/// [Inspector] implementations.
21+
pub mod inspectors {
22+
#[cfg(feature = "std")]
23+
pub use super::customprinter::CustomPrintTracer;
24+
#[cfg(all(feature = "std", feature = "serde-json"))]
25+
pub use super::eip3155::TracerEip3155;
26+
pub use super::gas::GasInspector;
27+
pub use super::noop::NoOpInspector;
28+
}

crates/revm/src/inspector/noop.rs renamed to crates/inspector/src/noop.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{EvmWiring, Inspector};
1+
use crate::Inspector;
2+
use revm::EvmWiring;
23

34
/// Dummy [Inspector], helpful as standalone replacement.
45
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]

crates/optimism/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ default = ["std", "c-kzg", "secp256k1", "portable", "blst"]
4949
std = ["serde?/std", "revm/std", "precompile/std"]
5050
hashbrown = ["revm/hashbrown"]
5151
serde = ["dep:serde", "revm/serde"]
52-
serde-json = ["serde", "revm/serde-json"]
5352
portable = ["revm/portable"]
5453

5554
dev = [

0 commit comments

Comments
 (0)