Skip to content

Commit

Permalink
Inspector wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Nov 21, 2024
1 parent c816a2c commit b6015e9
Show file tree
Hide file tree
Showing 31 changed files with 331 additions and 186 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ context-interface = { path = "crates/context/interface", package = "revm-context
handler = { path = "crates/handler", package = "revm-handler", version = "1.0.0", default-features = false }
handler-interface = { path = "crates/handler/interface", package = "revm-handler-interface", version = "1.0.0", default-features = false }

# mics
cfg-if = { version = "1.0", default-features = false }
auto_impl = { version = "1.2.0" }
derive-where = { version = "1.2.7", default-features = false }

[workspace.package]
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ pub fn execute_test_suite(
error: Ok(()),
},
inspector: StepPrintInspector::new(),
frame_input_stack: Vec::new(),
},
handler: EthHandler::new(
EthValidation::new(),
Expand Down
6 changes: 6 additions & 0 deletions crates/bytecode/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ impl OpCode {
}
}

/// Returns the opcode as a usize.
#[inline]
pub const fn as_usize(&self) -> usize {
self.0 as usize
}

/// Returns the opcode information.
#[inline]
pub const fn info(&self) -> OpCodeInfo {
Expand Down
5 changes: 1 addition & 4 deletions crates/context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ all = "warn"
[dependencies]
# revm
interpreter.workspace = true
precompile.workspace = true
context-interface.workspace = true
primitives.workspace = true
database-interface.workspace = true
Expand All @@ -34,9 +33,7 @@ bytecode.workspace = true
database = { workspace = true, optional = true }

# misc
derive-where = { version = "1.2.7", default-features = false }
dyn-clone = "1.0"
auto_impl = "1.2.0"
derive-where.workspace = true

# Optional
serde = { version = "1.0", default-features = false, features = [
Expand Down
6 changes: 2 additions & 4 deletions crates/context/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ primitives.workspace = true
database-interface.workspace = true
state.workspace = true
specification.workspace = true
bytecode.workspace = true

# mics
dyn-clone = "1.0"
cfg-if = { version = "1.0", default-features = false }
auto_impl = "1.2.0"
cfg-if.workspace = true
auto_impl.workspace = true

# Optional
serde = { version = "1.0", default-features = false, features = [
Expand Down
8 changes: 4 additions & 4 deletions crates/database/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ rust_2018_idioms = "deny"
all = "warn"

[dependencies]
# revm
state.workspace = true
primitives.workspace = true

auto_impl = "1.2"
# mics
auto_impl.workspace = true

# Optional
serde = { version = "1.0", default-features = false, features = [
Expand All @@ -48,6 +50,4 @@ alloy-sol-types = "0.8"
default = ["std"]
std = ["serde?/std"]
serde = ["dep:serde"]
asyncdb = [
"dep:tokio",
]
asyncdb = ["dep:tokio"]
5 changes: 0 additions & 5 deletions crates/handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ bytecode.workspace = true
database = { workspace = true, optional = true }
handler-interface.workspace = true

# misc
derive-where = { version = "1.2.7", default-features = false }
dyn-clone = "1.0"
auto_impl = "1.2.0"

# Optional
serde = { version = "1.0", default-features = false, features = [
"derive",
Expand Down
10 changes: 5 additions & 5 deletions crates/handler/interface/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub trait Frame: Sized {
type Error;

fn init_first(
cxt: &mut Self::Context,
frame_action: Self::FrameInit,
ctx: &mut Self::Context,
frame_input: Self::FrameInit,
) -> Result<FrameOrResultGen<Self, Self::FrameResult>, Self::Error>;

fn init(
&self,
cxt: &mut Self::Context,
frame_action: Self::FrameInit,
ctx: &mut Self::Context,
frame_input: Self::FrameInit,
) -> Result<FrameOrResultGen<Self, Self::FrameResult>, Self::Error>;

fn run(
Expand All @@ -25,7 +25,7 @@ pub trait Frame: Sized {

fn return_result(
&mut self,
cxt: &mut Self::Context,
ctx: &mut Self::Context,
result: Self::FrameResult,
) -> Result<(), Self::Error>;
}
18 changes: 7 additions & 11 deletions crates/handler/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use handler_interface::{ExecutionHandler, Frame as FrameTrait, FrameOrResultGen}
use interpreter::{
interpreter::{EthInstructionProvider, EthInterpreter},
return_ok, return_revert, CallInputs, CallScheme, CallValue, CreateInputs, CreateScheme,
EOFCreateInputs, EOFCreateKind, Gas, NewFrameAction,
EOFCreateInputs, EOFCreateKind, FrameInput, Gas,
};
use primitives::TxKind;
use specification::hardfork::SpecId;
Expand Down Expand Up @@ -37,12 +37,8 @@ where
+ JournalStateGetter
+ CfgGetter,
ERROR: From<InvalidTransaction> + From<JournalStateGetterDBError<CTX>>,
FRAME: FrameTrait<
Context = CTX,
Error = ERROR,
FrameInit = NewFrameAction,
FrameResult = FrameResult,
>,
FRAME:
FrameTrait<Context = CTX, Error = ERROR, FrameInit = FrameInput, FrameResult = FrameResult>,
{
type Context = CTX;
type Error = ERROR;
Expand All @@ -60,8 +56,8 @@ where
let tx = context.tx();
let input = tx.common_fields().input().clone();

let init_frame: NewFrameAction = match tx.kind() {
TxKind::Call(target_address) => NewFrameAction::Call(Box::new(CallInputs {
let init_frame: FrameInput = match tx.kind() {
TxKind::Call(target_address) => FrameInput::Call(Box::new(CallInputs {
input,
gas_limit,
target_address,
Expand All @@ -76,14 +72,14 @@ where
TxKind::Create => {
// if first byte of data is magic 0xEF00, then it is EOFCreate.
if spec.is_enabled_in(SpecId::PRAGUE_EOF) && input.starts_with(&EOF_MAGIC_BYTES) {
NewFrameAction::EOFCreate(Box::new(EOFCreateInputs::new(
FrameInput::EOFCreate(Box::new(EOFCreateInputs::new(
tx.common_fields().caller(),
tx.common_fields().value(),
gas_limit,
EOFCreateKind::Tx { initdata: input },
)))
} else {
NewFrameAction::Create(Box::new(CreateInputs {
FrameInput::Create(Box::new(CreateInputs {
caller: tx.common_fields().caller(),
scheme: CreateScheme::Create,
value: tx.common_fields().value(),
Expand Down
36 changes: 18 additions & 18 deletions crates/handler/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use interpreter::{
interpreter::{EthInterpreter, InstructionProvider},
interpreter_wiring::{LoopControl, ReturnData, RuntimeFlag},
return_ok, return_revert, CallInputs, CallOutcome, CallValue, CreateInputs, CreateOutcome,
CreateScheme, EOFCreateInputs, EOFCreateKind, Gas, Host, InputsImpl, InstructionResult,
InterpreterAction, InterpreterResult, InterpreterWire, NewFrameAction, NewInterpreter,
CreateScheme, EOFCreateInputs, EOFCreateKind, FrameInput, Gas, Host, InputsImpl,
InstructionResult, InterpreterAction, InterpreterResult, InterpreterWire, NewInterpreter,
SharedMemory,
};
use precompile::PrecompileErrors;
Expand Down Expand Up @@ -72,7 +72,7 @@ pub struct EthFrame<CTX, ERROR, IW: InterpreterWire, PRECOMPILE, INSTRUCTIONS> {
pub interpreter: NewInterpreter<IW>,
/// Precompiles provider.
pub precompiles: PRECOMPILE,
/// Insturction provider.
/// Instruction provider.
pub instructions: INSTRUCTIONS,
// This is worth making as a generic type FrameSharedContext.
pub memory: Rc<RefCell<SharedMemory>>,
Expand Down Expand Up @@ -191,7 +191,8 @@ where
} else {
let account = ctx.journal().load_account_code(inputs.bytecode_address)?;

let code_hash = account.info.code_hash();
// TODO Request from foundry to get bytecode hash.
let _code_hash = account.info.code_hash();
let mut bytecode = account.info.code.clone().unwrap_or_default();

// ExtDelegateCall is not allowed to call non-EOF contracts.
Expand Down Expand Up @@ -301,12 +302,13 @@ where
}

// Create address
let mut init_code_hash = B256::ZERO;
// TODO incorporating code hash inside interpreter. It was a request by foundry.
let mut _init_code_hash = B256::ZERO;
let created_address = match inputs.scheme {
CreateScheme::Create => inputs.caller.create(old_nonce),
CreateScheme::Create2 { salt } => {
init_code_hash = keccak256(&inputs.init_code);
inputs.caller.create2(salt.to_be_bytes(), init_code_hash)
_init_code_hash = keccak256(&inputs.init_code);
inputs.caller.create2(salt.to_be_bytes(), _init_code_hash)
}
};

Expand Down Expand Up @@ -452,20 +454,18 @@ where
return return_error(InstructionResult::CreateCollision);
};

let bytecode = Bytecode::new_legacy(input).into_analyzed();

let interpreter_input = InputsImpl {
target_address: created_address,
caller_address: inputs.caller,
input: Bytes::new(),
input,
call_value: inputs.value,
};

Ok(FrameOrResultGen::Frame(Self::new(
FrameData::Create(CreateFrame { created_address }),
NewInterpreter::new(
memory.clone(),
bytecode,
Bytecode::Eof(Arc::new(initcode)),
interpreter_input,
false,
false,
Expand All @@ -481,20 +481,20 @@ where

pub fn init_with_context(
depth: usize,
frame_init: NewFrameAction,
frame_init: FrameInput,
memory: Rc<RefCell<SharedMemory>>,
precompile: PRECOMPILE,
instructions: INSTRUCTION,
ctx: &mut CTX,
) -> Result<FrameOrResultGen<Self, FrameResult>, ERROR> {
match frame_init {
NewFrameAction::Call(inputs) => {
FrameInput::Call(inputs) => {
Self::make_call_frame(ctx, depth, memory, &inputs, precompile, instructions)
}
NewFrameAction::Create(inputs) => {
FrameInput::Create(inputs) => {
Self::make_create_frame(ctx, depth, memory, &inputs, precompile, instructions)
}
NewFrameAction::EOFCreate(inputs) => {
FrameInput::EOFCreate(inputs) => {
Self::make_eofcreate_frame(ctx, depth, memory, &inputs, precompile, instructions)
}
}
Expand All @@ -516,12 +516,12 @@ where
{
type Context = CTX;
type Error = ERROR;
type FrameInit = NewFrameAction;
type FrameInit = FrameInput;
type FrameResult = FrameResult;

fn init_first(
ctx: &mut Self::Context,
frame_action: Self::FrameInit,
frame_input: Self::FrameInit,
) -> Result<FrameOrResultGen<Self, Self::FrameResult>, Self::Error> {
let memory = Rc::new(RefCell::new(SharedMemory::new()));
let precompiles = PRECOMPILE::new(ctx);
Expand All @@ -533,7 +533,7 @@ where
}

memory.borrow_mut().new_context();
Self::init_with_context(0, frame_action, memory, precompiles, instructions, ctx)
Self::init_with_context(0, frame_input, memory, precompiles, instructions, ctx)
}

fn init(
Expand Down
3 changes: 1 addition & 2 deletions crates/handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ use context_interface::{
TransactionGetter,
};
use handler_interface::{
ExecutionHandler, Frame, FrameOrResultGen, Handler, PostExecutionHandler, PreExecutionHandler,
ValidationHandler,
ExecutionHandler, Handler, PostExecutionHandler, PreExecutionHandler, ValidationHandler,
};
use interpreter::Host;

Expand Down
1 change: 0 additions & 1 deletion crates/handler/src/precompile_provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use context_interface::{Cfg, CfgGetter};
use handler_interface::PrecompileProvider;
use interpreter::Host;
use interpreter::{Gas, InstructionResult, InterpreterResult};
use precompile::PrecompileErrors;
use precompile::{PrecompileSpecId, Precompiles};
Expand Down
4 changes: 2 additions & 2 deletions crates/inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ all = "warn"
revm.workspace = true

# mics
auto_impl = { version = "1.2", default-features = false }
derive-where = { version = "1.2.7", default-features = false }
auto_impl.workspace = true
derive-where.workspace = true

# Optional
serde = { version = "1.0", default-features = false, features = [
Expand Down
Loading

0 comments on commit b6015e9

Please sign in to comment.