Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1036f20
feat: Restructure Part7 Handler Wire
rakita Oct 15, 2024
d31b6bd
wip
rakita Oct 17, 2024
38016af
wip of frames
rakita Oct 17, 2024
8eddc1e
work on Frame calls
rakita Oct 17, 2024
cb6e37c
Wip Frame and Exec wire
rakita Oct 21, 2024
d9f6ecd
compile handler wires
rakita Oct 22, 2024
ca1af66
fmt
rakita Oct 22, 2024
55ef83d
Hand from Handler replacement
rakita Oct 23, 2024
c853e56
Interpreter traits
rakita Oct 24, 2024
f50f33d
interpreter popn calls
rakita Oct 28, 2024
89273d9
wip Interpreter refactor, all instructions compile
rakita Oct 30, 2024
9eebac0
compiles without precompiles
rakita Nov 1, 2024
e5b0dc6
precompile and instruction table wip
rakita Nov 6, 2024
e33e7c9
precompile run wip
rakita Nov 6, 2024
769a317
simple revm statetest run
rakita Nov 7, 2024
8c5756b
Example of inspector in revme
rakita Nov 7, 2024
5947054
small cleanup for presentation
rakita Nov 15, 2024
9a17050
context interface
rakita Nov 20, 2024
6009e0b
handler and context interface crates
rakita Nov 20, 2024
4e24be4
small cleanup
rakita Nov 20, 2024
32f8978
fmt
rakita Nov 21, 2024
c816a2c
Merge remote-tracking branch 'origin/main' into r7
rakita Nov 21, 2024
b6015e9
Inspector wip
rakita Nov 21, 2024
45b2dc5
rename and wip Inspector
rakita Nov 21, 2024
1a3c69a
fixes
rakita Nov 25, 2024
be64969
fix bugs, mv spec to cfg
rakita Nov 26, 2024
43ed681
fix for tests
rakita Nov 27, 2024
0497419
fix eof bugs
rakita Nov 28, 2024
d148400
no_std compile fix
rakita Nov 28, 2024
d1aadc3
few fixes
rakita Nov 28, 2024
b2999ec
clippy
rakita Nov 28, 2024
a4fa635
cleanup
rakita Nov 28, 2024
f38aae6
remvme bench, builder for context
rakita Nov 28, 2024
3e581b0
inline somethings
rakita Nov 28, 2024
e8c2686
clippy
rakita Nov 28, 2024
db41f9b
example of block traces
rakita Nov 28, 2024
7915381
enable examples
rakita Nov 29, 2024
ef16d8f
op handlers
rakita Dec 3, 2024
ff979e2
Add op precompiles
rakita Dec 4, 2024
7e729a0
some ci fixes
rakita Dec 4, 2024
de4cab3
fix tests
rakita Dec 4, 2024
9ea8680
fix docs
rakita Dec 5, 2024
ab24d36
simplifications, cleanup
rakita Dec 5, 2024
5af8983
enable evm run cmd
rakita Dec 5, 2024
cc8a097
must use on chained fn
rakita Dec 5, 2024
fe00e63
cleanup
rakita Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
precompile run wip
  • Loading branch information
rakita committed Nov 6, 2024
commit e33e7c9489259627aa87b5a4d733da9d5282e46a
40 changes: 29 additions & 11 deletions crates/revm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ use context::{
};
// Exports.
use mainnet::{EthExecution, EthFrame, EthPostExecution, EthPreExecution, EthValidation};
use precompile::PrecompileErrors;
use primitives::Log;
use state::EvmState;
pub use wires::*;

// Includes.

use interpreter::{interpreter::EthInterpreter, Host};
use interpreter::{
interpreter::{EthInstructionProvider, EthInterpreter},
Host,
};
//use register::{EvmHandler, HandleRegisters};
use std::vec::Vec;
use wiring::{
Expand Down Expand Up @@ -66,7 +70,10 @@ where
+ ErrorGetter<Error = ERROR>
+ JournalStateGetter<Journal: JournaledState<FinalOutput = (EvmState, Vec<Log>)>>
+ Host,
ERROR: From<InvalidTransaction> + From<InvalidHeader> + From<JournalStateGetterDBError<CTX>>,
ERROR: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<JournalStateGetterDBError<CTX>>
+ From<PrecompileErrors>,
{
type Validation = <EthHand<CTX, ERROR> as Handler>::Validation;
type PreExecution = <EthHand<CTX, ERROR> as Handler>::PreExecution;
Expand Down Expand Up @@ -100,7 +107,10 @@ where
+ ErrorGetter<Error = ERROR>
+ JournalStateGetter<Journal: JournaledState<FinalOutput = (EvmState, Vec<Log>)>>
+ Host,
ERROR: From<InvalidTransaction> + From<InvalidHeader> + From<JournalStateGetterDBError<CTX>>,
ERROR: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<JournalStateGetterDBError<CTX>>
+ From<PrecompileErrors>,
VAL: ValidationWire,
PREEXEC: PreExecutionWire,
EXEC: ExecutionWire,
Expand Down Expand Up @@ -145,15 +155,25 @@ pub struct EEVM<ERROR, CTX = Context> {

pub type EthContext<DB> = Context<BlockEnv, TxEnv, DB, ()>;

pub type NEW_PRECOMPILE<DB, ERROR> = GEVM<
pub type NEW_PRECOMPILE<DB, ERROR, PRECOMPILE> = GEVM<
ERROR,
EthContext<DB>,
EthHand<
EthContext<DB>,
ERROR,
EthValidation<EthContext<DB>, ERROR>,
EthPreExecution<EthContext<DB>, ERROR>,
EthExecution<EthContext<DB>, ERROR>,
EthExecution<
EthContext<DB>,
ERROR,
EthFrame<
EthContext<DB>,
ERROR,
EthInterpreter<()>,
PRECOMPILE,
EthInstructionProvider<EthInterpreter<()>, EthContext<DB>>,
>,
>,
>,
>;

Expand All @@ -171,7 +191,10 @@ where
Database = <CTX as DatabaseGetter>::Database,
>,
> + Host,
ERROR: From<InvalidTransaction> + From<InvalidHeader> + From<JournalStateGetterDBError<CTX>>,
ERROR: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<JournalStateGetterDBError<CTX>>
+ From<PrecompileErrors>,
{
// TODO
// transact_commit (needs DatabaseCommit requirement)
Expand Down Expand Up @@ -248,11 +271,6 @@ where
// load access list and beneficiary if needed.
pre_exec.load_accounts(ctx)?;

// load precompiles
let precompiles = pre_exec.load_precompiles();
// TODO SET PRECOMPILE
//ctx.evm.set_precompiles(precompiles);

// deduce caller balance with its limit.
pre_exec.deduct_caller(ctx)?;

Expand Down
20 changes: 4 additions & 16 deletions crates/revm/src/handler/mainnet/execution.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
use super::{frame_data::FrameResult, EthFrame};
use crate::handler::{
wires::Frame as FrameTrait, EthPrecompileProvider, ExecutionWire, FrameOrResultGen,
PrecompileProvider,
};
use bytecode::EOF_MAGIC_BYTES;
use context::{
BlockGetter, CfgGetter, ErrorGetter, JournalStateGetter, JournalStateGetterDBError,
TransactionGetter,
};
use core::cell::RefCell;
use interpreter::{
interpreter::{EthInstructionProvider, EthInterpreter},
return_ok, return_revert, CallInputs, CallScheme, CallValue, CreateInputs, CreateScheme,
EOFCreateInputs, EOFCreateKind, Gas, NewFrameAction, SharedMemory,
EOFCreateInputs, EOFCreateKind, Gas, NewFrameAction,
};
use precompile::PrecompileSpecId;
use primitives::TxKind;
use specification::hardfork::SpecId;
use std::{boxed::Box, rc::Rc};
use wiring::{journaled_state::JournaledState, result::InvalidTransaction, Cfg, Transaction};
use std::boxed::Box;
use wiring::{result::InvalidTransaction, Cfg, Transaction};

/// TODO EvmWiringT is temporary, replace it with getter traits.
pub struct EthExecution<
CTX,
ERROR,
FRAME = EthFrame<
CTX,
ERROR,
EthInterpreter<()>,
EthPrecompileProvider<CTX>,
EthPrecompileProvider<CTX, ERROR>,
EthInstructionProvider<EthInterpreter<()>, CTX>,
>,
> {
Expand Down Expand Up @@ -61,14 +57,6 @@ where
gas_limit: u64,
) -> Result<FrameOrResultGen<Self::Frame, <Self::Frame as FrameTrait>::FrameResult>, Self::Error>
{
// TODO do this in frame
// self.precompiles
// .set_spec_id(PrecompileSpecId::from_spec_id(self.spec_id));
// // wamr up precompile address.
// for address in self.precompiles.warm_addresses() {
// context.journal().warm_account(address);
// }

// Make new frame action.
let spec = context.cfg().spec().into();
let tx = context.tx();
Expand Down
171 changes: 84 additions & 87 deletions crates/revm/src/handler/mainnet/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use interpreter::{
InterpreterWire, MemoryGetter, NewFrameAction, NewInterpreter, SharedMemory,
EMPTY_SHARED_MEMORY,
};
use precompile::Precompiles;
use precompile::{PrecompileErrors, Precompiles};
use primitives::{keccak256, Address, Bytes, B256, U256};
use specification::{
constants::CALL_STACK_LIMIT,
Expand Down Expand Up @@ -126,8 +126,8 @@ where
+ BlockGetter
+ JournalStateGetter
+ CfgGetter,
//IW = ,
ERROR: From<JournalStateGetterDBError<CTX>>,
PRECOMPILE: PrecompileProvider<Context = CTX, Error = ERROR>,
ERROR: From<JournalStateGetterDBError<CTX>> + From<PrecompileErrors>,
{
/// Make call frame
#[inline]
Expand Down Expand Up @@ -187,72 +187,83 @@ where
_ => {}
};
// TODO
// if let Some(result) = ctx.call_precompile(&inputs.bytecode_address, &inputs.input, gas)? {
// if result.result.is_ok() {
// self.journaled_state.checkpoint_commit();
// } else {
// self.journaled_state.checkpoint_revert(checkpoint);
// }
// Ok(FrameOrResult::new_call_result(
// result,
// inputs.return_memory_offset.clone(),
// ))
// } else {
let account = ctx.journal().load_account_code(inputs.bytecode_address)?;

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.
if inputs.scheme.is_ext_delegate_call()
&& !bytecode.bytes_slice().starts_with(&EOF_MAGIC_BYTES)
{
return return_result(InstructionResult::InvalidExtDelegateCallTarget);
}
if let Some(result) = precompile.run(
ctx,
&inputs.bytecode_address,
&inputs.input,
inputs.gas_limit,
) {
let result = result?;
if result.result.is_ok() {
ctx.journal().checkpoint_commit();
} else {
ctx.journal().checkpoint_revert(checkpoint);
}
Ok(FrameOrResultGen::Result(FrameResult::Call(CallOutcome {
result: InterpreterResult {
result: result,
gas,
output: Bytes::new(),
},
memory_offset,
})))
} else {
let account = ctx.journal().load_account_code(inputs.bytecode_address)?;

if bytecode.is_empty() {
ctx.journal().checkpoint_commit();
return return_result(InstructionResult::Stop);
}
let code_hash = account.info.code_hash();
let mut bytecode = account.info.code.clone().unwrap_or_default();

if let Bytecode::Eip7702(eip7702_bytecode) = bytecode {
bytecode = ctx
.journal()
.load_account_code(eip7702_bytecode.delegated_address)?
.info
.code
.clone()
.unwrap_or_default();
}
// ExtDelegateCall is not allowed to call non-EOF contracts.
if inputs.scheme.is_ext_delegate_call()
&& !bytecode.bytes_slice().starts_with(&EOF_MAGIC_BYTES)
{
return return_result(InstructionResult::InvalidExtDelegateCallTarget);
}

//let contract =
// Contract::new_with_context(inputs.input.clone(), bytecode, Some(code_hash), inputs);
// Create interpreter and executes call and push new CallStackFrame.
let interpreter_input = InputsImpl {
target_address: inputs.target_address,
caller_address: inputs.caller,
input: inputs.input.clone(),
call_value: inputs.value.get(),
};
if bytecode.is_empty() {
ctx.journal().checkpoint_commit();
return return_result(InstructionResult::Stop);
}

Ok(FrameOrResultGen::Frame(Self::new(
FrameData::Call(CallFrame {
return_memory_range: inputs.return_memory_offset.clone(),
}),
NewInterpreter::new(
memory.clone(),
bytecode,
interpreter_input,
inputs.is_static,
false,
ctx.cfg().spec().into(),
inputs.gas_limit,
),
checkpoint,
precompile,
instructions,
memory,
)))
if let Bytecode::Eip7702(eip7702_bytecode) = bytecode {
bytecode = ctx
.journal()
.load_account_code(eip7702_bytecode.delegated_address)?
.info
.code
.clone()
.unwrap_or_default();
}

//let contract =
// Contract::new_with_context(inputs.input.clone(), bytecode, Some(code_hash), inputs);
// Create interpreter and executes call and push new CallStackFrame.
let interpreter_input = InputsImpl {
target_address: inputs.target_address,
caller_address: inputs.caller,
input: inputs.input.clone(),
call_value: inputs.value.get(),
};

Ok(FrameOrResultGen::Frame(Self::new(
FrameData::Call(CallFrame {
return_memory_range: inputs.return_memory_offset.clone(),
}),
NewInterpreter::new(
memory.clone(),
bytecode,
interpreter_input,
inputs.is_static,
false,
ctx.cfg().spec().into(),
inputs.gas_limit,
),
checkpoint,
precompile,
instructions,
memory,
)))
}
}

/// Make create frame.
Expand Down Expand Up @@ -460,26 +471,6 @@ where
return return_error(InstructionResult::CreateCollision);
};

// let contract = Contract::new(
// input.clone(),
// // fine to clone as it is Bytes.
// Bytecode::Eof(Arc::new(initcode.clone())),
// None,
// created_address,
// None,
// inputs.caller,
// inputs.value,
// );

// let mut interpreter = Interpreter::new(contract, inputs.gas_limit, false);
// // EOF init will enable RETURNCONTRACT opcode.
// interpreter.set_is_eof_init();

// Ok(FrameOrResult::new_eofcreate_frame(
// created_address,
// checkpoint,
// interpreter,
// ))
let bytecode = Bytecode::new_legacy(input).into_analyzed();

let interpreter_input = InputsImpl {
Expand Down Expand Up @@ -540,8 +531,8 @@ where
+ JournalStateGetter
+ CfgGetter
+ Host,
ERROR: From<JournalStateGetterDBError<CTX>>,
PRECOMPILE: PrecompileProvider<Context = CTX>,
ERROR: From<JournalStateGetterDBError<CTX>> + From<PrecompileErrors>,
PRECOMPILE: PrecompileProvider<Context = CTX, Error = ERROR>,
INSTRUCTION: InstructionProvider<WIRE = EthInterpreter<()>, Host = CTX>,
{
type Context = CTX;
Expand All @@ -556,6 +547,12 @@ where
let memory = Rc::new(RefCell::new(SharedMemory::new()));
let precompiles = PRECOMPILE::new(ctx);
let instructions = INSTRUCTION::new(ctx);

// load precompiles addresses as warm.
for address in precompiles.warm_addresses() {
ctx.journal().load_account(address)?;
}

memory.borrow_mut().new_context();
Self::init_with_context(0, frame_action, memory, precompiles, instructions, ctx)
}
Expand Down
5 changes: 0 additions & 5 deletions crates/revm/src/handler/mainnet/pre_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ where
{
type Context = CTX;
type Error = ERROR;
type Precompiles = ();

fn load_precompiles(&self) -> Self::Precompiles {
todo!()
}

fn load_accounts(&self, context: &mut Self::Context) -> Result<(), Self::Error> {
// set journaling state flag.
Expand Down
Loading