Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Dec 20, 2024
1 parent 26eed85 commit 8fb15a6
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 115 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ alloy-rpc-types-eth = "0.8"
alloy-rpc-types-trace = "0.8"
alloy-sol-types = "0.8"
alloy-primitives = { version = "0.8", features = ["map"] }
revm = { git = "https://github.com/bluealloy/revm.git", rev = "ab62fe1a", default-features = false, features = [
revm = { git = "https://github.com/bluealloy/revm.git", rev = "235ad5c8", default-features = false, features = [
"std",
] }
revm-inspector = { git = "https://github.com/bluealloy/revm.git", rev = "ab62fe1a", default-features = false, features = [
revm-inspector = { git = "https://github.com/bluealloy/revm.git", rev = "235ad5c8", default-features = false, features = [
"std",
] }

Expand All @@ -55,7 +55,7 @@ boa_gc = { version = "0.19", optional = true }

[dev-dependencies]
snapbox = { version = "0.6", features = ["term-svg"] }
revm-database = { git = "https://github.com/bluealloy/revm.git", rev = "ab62fe1a", default-features = false, features = [
revm-database = { git = "https://github.com/bluealloy/revm.git", rev = "235ad5c8", default-features = false, features = [
"std",
] }

Expand Down
15 changes: 11 additions & 4 deletions src/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use alloy_primitives::{Address, B256};
use alloy_rpc_types_eth::{AccessList, AccessListItem};
use revm::{
bytecode::opcode,
context_interface::Journal,
interpreter::{
interpreter::EthInterpreter,
interpreter_types::{InputsTrait, Jumps},
Interpreter,
},
Database,
Context, Database,
};
use revm_inspector::{Inspector, PrevContext};
use revm_inspector::Inspector;
use std::collections::{BTreeSet, HashMap, HashSet};

/// An [Inspector] that collects touched accounts and storage slots.
Expand Down Expand Up @@ -64,11 +65,17 @@ impl AccessListInspector {
}
}

impl<DB,W> Inspector<ContextWire<DB,W>, EthInterpreter> for AccessListInspector
impl<DB, BLOCK, TX, CFG, JOURNAL, CHAIN>
Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>, EthInterpreter> for AccessListInspector
where
DB: Database,
JOURNAL: Journal<Database = DB>,
{
fn step(&mut self, interp: &mut Interpreter<EthInterpreter>, _context: &mut PrevContext<DB>) {
fn step(
&mut self,
interp: &mut Interpreter<EthInterpreter>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
) {
match interp.bytecode.opcode() {
opcode::SLOAD | opcode::SSTORE => {
if let Ok(slot) = interp.stack.peek(0) {
Expand Down
35 changes: 22 additions & 13 deletions src/opcode.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use alloy_rpc_types_trace::opcode::OpcodeGas;
use revm::{
bytecode::opcode::{self, OpCode},
context_interface::Journal,
interpreter::{
interpreter::EthInterpreter,
interpreter_types::{Immediates, Jumps, LoopControl},
Interpreter,
},
Database,
Context, Database,
};
use revm_inspector::{Inspector, PrevContext};
use revm_inspector::Inspector;
use std::collections::HashMap;

/// An Inspector that counts opcodes and measures gas usage per opcode.
Expand Down Expand Up @@ -60,11 +61,17 @@ impl OpcodeGasInspector {
}
}

impl<DB,W> Inspector<ContextWire<DB,W>, EthInterpreter> for OpcodeGasInspector
impl<DB, BLOCK, TX, CFG, JOURNAL, CHAIN>
Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>, EthInterpreter> for OpcodeGasInspector
where
DB: Database,
JOURNAL: Journal<Database = DB>,
{
fn step(&mut self, interp: &mut Interpreter<EthInterpreter>, _context: &mut PrevContext<DB>) {
fn step(
&mut self,
interp: &mut Interpreter<EthInterpreter>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
) {
let opcode_value = interp.bytecode.opcode();
if let Some(opcode) = OpCode::new(opcode_value) {
// keep track of opcode counts
Expand All @@ -78,7 +85,7 @@ where
fn step_end(
&mut self,
interp: &mut Interpreter<EthInterpreter>,
_context: &mut PrevContext<DB>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
) {
// update gas usage for the last opcode
if let Some((opcode, gas_remaining)) = self.last_opcode_gas_remaining.take() {
Expand Down Expand Up @@ -133,10 +140,11 @@ mod tests {
);
let db = CacheDB::new(EmptyDB::default());

for _ in &opcodes {
opcode_counter
.step(&mut interpreter, &mut PrevContext::new(db.clone(), SpecId::BERLIN));
}
// TODO(rakita) fix this
// let mut context = PrevContext::new(db.clone(), SpecId::BERLIN);
// for _ in &opcodes {
// opcode_counter.step(&mut interpreter, &mut context);
// }
}

#[test]
Expand Down Expand Up @@ -164,9 +172,10 @@ mod tests {
);
let db = CacheDB::new(EmptyDB::default());

for _ in opcodes.iter() {
opcode_counter
.step(&mut interpreter, &mut PrevContext::new(db.clone(), SpecId::LATEST));
}
// TODO(rakita): fix this
// let mut context: Context<> = Context::new(db.clone(), SpecId::LATEST);
// for _ in opcodes.iter() {
// opcode_counter.step(&mut interpreter, &mut context);
// }
}
}
16 changes: 9 additions & 7 deletions src/tracing/fourbyte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
use alloy_primitives::{hex, Selector};
use alloy_rpc_types_trace::geth::FourByteFrame;
use revm::{
context::{BlockEnv, CfgEnv, ContextWire, ContextWiring, TxEnv},
context::{BlockEnv, CfgEnv, TxEnv},
context_interface::Journal,
interpreter::{interpreter::EthInterpreter, CallInputs, CallOutcome},
Context, Database,
};
use revm_inspector::{Inspector, PrevContext};
use revm_inspector::Inspector;
use std::collections::HashMap;

/// Fourbyte tracing inspector that records all function selectors and their calldata sizes.
Expand All @@ -45,16 +46,17 @@ impl FourByteInspector {
}
}

/// TODO : rakita the type parameter `CTXW` is not constrained by the impl trait, self type, or predicates
/// unconstrained type parameter
impl<DB, CTXW> Inspector<ContextWire<DB, CTXW>, EthInterpreter> for FourByteInspector
/// TODO rakita the type parameter `CTXW` is not constrained by the impl trait, self type, or
/// predicates unconstrained type parameter
impl<DB, BLOCK, TX, CFG, JOURNAL, CHAIN>
Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>, EthInterpreter> for FourByteInspector
where
DB: Database,
CTXW: ContextWiring<DB>,
JOURNAL: Journal<Database = DB>,
{
fn call(
&mut self,
_context: &mut PrevContext<DB>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
inputs: &mut CallInputs,
) -> Option<CallOutcome> {
if inputs.input.len() >= 4 {
Expand Down
18 changes: 11 additions & 7 deletions src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ where
W: ContextWiring<DB>,
<DB as DatabaseRef>::Error: std::fmt::Display,
{
fn step(&mut self, interp: &mut Interpreter<EthInterpreter>, context: &mut PrevContext<DB>) {
fn step(
&mut self,
interp: &mut Interpreter<EthInterpreter>,
context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
) {
if self.step_fn.is_none() {
return;
}
Expand Down Expand Up @@ -421,7 +425,7 @@ where
fn step_end(
&mut self,
interp: &mut Interpreter<EthInterpreter>,
context: &mut PrevContext<DB>,
context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
) {
if self.step_fn.is_none() {
return;
Expand Down Expand Up @@ -452,14 +456,14 @@ where
fn log(
&mut self,
_interp: &mut Interpreter<EthInterpreter>,
_context: &mut PrevContext<DB>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
_log: &Log,
) {
}

fn call(
&mut self,
context: &mut PrevContext<DB>,
context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
inputs: &mut CallInputs,
) -> Option<CallOutcome> {
self.register_precompiles(&context.precompiles);
Expand Down Expand Up @@ -500,7 +504,7 @@ where

fn call_end(
&mut self,
_context: &mut PrevContext<DB>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
_inputs: &CallInputs,
mut outcome: CallOutcome,
) -> CallOutcome {
Expand All @@ -522,7 +526,7 @@ where

fn create(
&mut self,
context: &mut PrevContext<DB>,
context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
inputs: &mut CreateInputs,
) -> Option<CreateOutcome> {
self.register_precompiles(&context.precompiles);
Expand Down Expand Up @@ -553,7 +557,7 @@ where

fn create_end(
&mut self,
_context: &mut PrevContext<DB>,
_context: &mut Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>,
_inputs: &CreateInputs,
mut outcome: CreateOutcome,
) -> CreateOutcome {
Expand Down
Loading

0 comments on commit 8fb15a6

Please sign in to comment.