Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
7ea084a
eof
rakita Feb 13, 2024
cd523c3
Merge remote-tracking branch 'origin/main' into eof
rakita Feb 14, 2024
237068f
feat(EOF): Header decoder
rakita Feb 14, 2024
fabdc1b
EofBody decode
rakita Feb 15, 2024
4dd7d3a
Merge remote-tracking branch 'origin/main' into eof
rakita Feb 18, 2024
2ff0f28
disable eof deprecated opcodes
rakita Feb 18, 2024
20fcdaf
add eof instructions
rakita Feb 20, 2024
22bf551
temp tests
rakita Feb 20, 2024
318d775
Merge remote-tracking branch 'origin/main' into eof
rakita Feb 22, 2024
33974b3
rjump instructions
rakita Feb 22, 2024
a638385
eof rjump with tests
rakita Feb 23, 2024
2d14e04
Merge remote-tracking branch 'origin/main' into eof
rakita Feb 23, 2024
ad45264
EOF bytecode
rakita Feb 25, 2024
2c29f1b
callf, retf, jumpf
rakita Feb 26, 2024
ecc4467
tests for callf,retf,jumpf
rakita Feb 27, 2024
3979a12
small rename
rakita Feb 27, 2024
a440503
add dataload, dataloadn and datacopy opcodes
rakita Feb 28, 2024
cb3d93a
refactor calls
rakita Feb 29, 2024
1dabca4
blueprint for creates
rakita Mar 1, 2024
788182f
Merge remote-tracking branch 'origin/main' into eof
rakita Mar 1, 2024
4354b6d
eof create inputs
rakita Mar 2, 2024
207ad21
some wip
rakita Mar 4, 2024
dc07460
Merge remote-tracking branch 'origin/main' into eof
rakita Mar 4, 2024
2e48462
add eofcreate structs and exccall flow
rakita Mar 4, 2024
48abbe6
wip eofcreate code flow and handlers
rakita Mar 4, 2024
9d8f612
fix tests
rakita Mar 4, 2024
0fc345a
eof creates
rakita Mar 5, 2024
862d85b
Merge remote-tracking branch 'origin/main' into eof
rakita Mar 7, 2024
fab521a
refactor eofcreate a little
rakita Mar 7, 2024
e5abe46
some work on extcall
rakita Mar 8, 2024
d3dd1a9
Merge remote-tracking branch 'origin/main' into eof
rakita Mar 14, 2024
4aa166a
feat: refactor simplify CallInput, eof extcalls
rakita Mar 15, 2024
449f243
feat: restructure OpCode and add stack input/output num
rakita Mar 18, 2024
183adaf
add flags for stack_io and not_eof
rakita Mar 19, 2024
07c721a
wip eof verification
rakita Mar 19, 2024
42a04c1
Merge remote-tracking branch 'origin/main' into eof
rakita Mar 19, 2024
91d98c3
wip validation
rakita Mar 21, 2024
d28122e
EOF Bytecode validity
rakita Mar 23, 2024
77939ac
insturction and jump validation seems good
rakita Mar 23, 2024
28d1f74
merged eof validate function
rakita Mar 26, 2024
2db230a
EOP test runner, fex fixes
rakita Mar 26, 2024
f219ed6
RETURNDATALOAD, fix call bugs, refactor gas warm/cold calc
rakita Mar 27, 2024
e996fac
Merge remote-tracking branch 'origin/main' into eof
rakita Mar 27, 2024
8a4d9a2
debug session, rjumpv imm fix
rakita Mar 28, 2024
54d3d23
fixing validation bugs, bytecode decoder for EOF in revme
rakita Mar 31, 2024
c1c31ec
pass most of validation tests
rakita Apr 2, 2024
b8f7fad
bounds check moved to decode
rakita Apr 2, 2024
fedbd70
Merge remote-tracking branch 'origin/main' into eof
rakita Apr 2, 2024
605431c
Merge remote-tracking branch 'origin/main' into eof
rakita Apr 3, 2024
1ae9563
Fix merge compilation, fmt
rakita Apr 3, 2024
7b73779
TXCREATE work
rakita Apr 7, 2024
761aa2b
remove training wheels, panic on eof
rakita Apr 7, 2024
85d062b
Merge remote-tracking branch 'origin/main' into eof
rakita Apr 7, 2024
efa7327
test fix and std
rakita Apr 7, 2024
691ad44
std
rakita Apr 7, 2024
8faa75a
fix test
rakita Apr 7, 2024
4af1988
fix valgrind
rakita Apr 7, 2024
c337cd9
fix tests
rakita Apr 7, 2024
a19865f
clippy
rakita Apr 7, 2024
647a8d2
removed checked logic
rakita Apr 7, 2024
98745cc
small change
rakita Apr 7, 2024
65cf05c
no std revm-test
rakita Apr 7, 2024
6294f0f
Merge remote-tracking branch 'origin/main' into eof
rakita Apr 7, 2024
8162f32
check pending TODOs
rakita Apr 7, 2024
63ffb17
Merge remote-tracking branch 'origin/main' into eof
rakita Apr 7, 2024
0222cc0
build check no_std
rakita Apr 7, 2024
eeeb798
doc
rakita Apr 7, 2024
4c60857
chore: move some files. cleanup comments
rakita Apr 9, 2024
55c19ad
Merge remote-tracking branch 'origin/main' into eof
rakita Apr 9, 2024
d24dcbb
fix fmt,clippy and compile error
rakita Apr 9, 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
refactor calls
  • Loading branch information
rakita committed Feb 29, 2024
commit cb3d93a5042c1e71f3816f048af1e1245d0047ce
111 changes: 111 additions & 0 deletions crates/interpreter/src/call_inputs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256};
use core::ops::Range;
use std::boxed::Box;

/// Inputs for a call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CallInputs {
/// The target of the call.
pub contract: Address,
/// The transfer, if any, in this call.
pub transfer: Transfer,
/// The call data of the call.
pub input: Bytes,
/// The gas limit of the call.
pub gas_limit: u64,
/// The context of the call.
pub context: CallContext,
/// Whether this is a static call.
pub is_static: bool,
/// The return memory offset where the output of the call is written.
pub return_memory_offset: Range<usize>,
}

impl CallInputs {
/// Creates new call inputs.
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
let TransactTo::Call(address) = tx_env.transact_to else {
return None;
};

Some(CallInputs {
contract: address,
transfer: Transfer {
source: tx_env.caller,
target: address,
value: tx_env.value,
},
input: tx_env.data.clone(),
gas_limit,
context: CallContext {
caller: tx_env.caller,
address,
code_address: address,
apparent_value: tx_env.value,
scheme: CallScheme::Call,
},
is_static: false,
return_memory_offset: 0..0,
})
}

/// Returns boxed call inputs.
pub fn new_boxed(tx_env: &TxEnv, gas_limit: u64) -> Option<Box<Self>> {
Self::new(tx_env, gas_limit).map(Box::new)
}
}

/// Call schemes.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CallScheme {
/// `CALL`.
Call,
/// `CALLCODE`
CallCode,
/// `DELEGATECALL`
DelegateCall,
/// `STATICCALL`
StaticCall,
}

/// Context of a runtime call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CallContext {
/// Execution address.
pub address: Address,
/// Caller address of the EVM.
pub caller: Address,
/// The address the contract code was loaded from, if any.
pub code_address: Address,
/// Apparent value of the EVM.
pub apparent_value: U256,
/// The scheme used for the call.
pub scheme: CallScheme,
}

impl Default for CallContext {
fn default() -> Self {
CallContext {
address: Address::default(),
caller: Address::default(),
code_address: Address::default(),
apparent_value: U256::default(),
scheme: CallScheme::Call,
}
}
}

/// Transfer from source to target, with given value.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Transfer {
/// The source address.
pub source: Address,
/// The target address.
pub target: Address,
/// The transfer value.
pub value: U256,
}
51 changes: 51 additions & 0 deletions crates/interpreter/src/create_inputs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pub use crate::primitives::CreateScheme;
use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256};
use std::boxed::Box;

/// Inputs for a create call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateInputs {
/// Caller address of the EVM.
pub caller: Address,
/// The create scheme.
pub scheme: CreateScheme,
/// The value to transfer.
pub value: U256,
/// The init code of the contract.
pub init_code: Bytes,
/// The gas limit of the call.
pub gas_limit: u64,
}

impl CreateInputs {
/// Creates new create inputs.
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
let TransactTo::Create(scheme) = tx_env.transact_to else {
return None;
};

Some(CreateInputs {
caller: tx_env.caller,
scheme,
value: tx_env.value,
init_code: tx_env.data.clone(),
gas_limit,
})
}

/// Returns boxed create inputs.
pub fn new_boxed(tx_env: &TxEnv, gas_limit: u64) -> Option<Box<Self>> {
Self::new(tx_env, gas_limit).map(Box::new)
}

/// Returns the address that this create call will create.
pub fn created_address(&self, nonce: u64) -> Address {
match self.scheme {
CreateScheme::Create => self.caller.create(nonce),
CreateScheme::Create2 { salt } => self
.caller
.create2_from_code(salt.to_be_bytes(), &self.init_code),
}
}
}
2 changes: 1 addition & 1 deletion crates/interpreter/src/gas/calc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::constants::*;
use crate::inner_models::SelfDestructResult;
use crate::primitives::{Address, Spec, SpecId::*, U256};
use crate::SelfDestructResult;
use std::vec::Vec;

#[allow(clippy::collapsible_else_if)]
Expand Down
2 changes: 2 additions & 0 deletions crates/interpreter/src/gas/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub const TRANSACTION_ZERO_DATA: u64 = 4;
pub const TRANSACTION_NON_ZERO_DATA_INIT: u64 = 16;
pub const TRANSACTION_NON_ZERO_DATA_FRONTIER: u64 = 68;

pub const EOF_CREATE_GAS: u64 = 32000;

// berlin eip2929 constants
pub const ACCESS_LIST_ADDRESS: u64 = 2400;
pub const ACCESS_LIST_STORAGE_KEY: u64 = 1900;
Expand Down
15 changes: 11 additions & 4 deletions crates/interpreter/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
primitives::{Address, Bytecode, Env, Log, B256, U256},
SelfDestructResult,
};
use crate::primitives::{Address, Bytecode, Env, Log, B256, U256};

mod dummy;
pub use dummy::DummyHost;
Expand Down Expand Up @@ -65,3 +62,13 @@ pub struct SStoreResult {
/// Is storage slot loaded from database
pub is_cold: bool,
}

/// Result of a call that resulted in a self destruct.
#[derive(Default, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SelfDestructResult {
pub had_value: bool,
pub target_exists: bool,
pub is_cold: bool,
pub previously_destroyed: bool,
}
118 changes: 0 additions & 118 deletions crates/interpreter/src/inner_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256};
use core::ops::Range;
use std::boxed::Box;

/// Inputs for a call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CallInputs {
/// The target of the call.
pub contract: Address,
/// The transfer, if any, in this call.
pub transfer: Transfer,
/// The call data of the call.
pub input: Bytes,
/// The gas limit of the call.
pub gas_limit: u64,
/// The context of the call.
pub context: CallContext,
/// Whether this is a static call.
pub is_static: bool,
/// The return memory offset where the output of the call is written.
pub return_memory_offset: Range<usize>,
}

/// Inputs for a create call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -39,40 +19,6 @@ pub struct CreateInputs {
pub gas_limit: u64,
}

impl CallInputs {
/// Creates new call inputs.
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
let TransactTo::Call(address) = tx_env.transact_to else {
return None;
};

Some(CallInputs {
contract: address,
transfer: Transfer {
source: tx_env.caller,
target: address,
value: tx_env.value,
},
input: tx_env.data.clone(),
gas_limit,
context: CallContext {
caller: tx_env.caller,
address,
code_address: address,
apparent_value: tx_env.value,
scheme: CallScheme::Call,
},
is_static: false,
return_memory_offset: 0..0,
})
}

/// Returns boxed call inputs.
pub fn new_boxed(tx_env: &TxEnv, gas_limit: u64) -> Option<Box<Self>> {
Self::new(tx_env, gas_limit).map(Box::new)
}
}

impl CreateInputs {
/// Creates new create inputs.
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
Expand Down Expand Up @@ -104,67 +50,3 @@ impl CreateInputs {
}
}
}

/// Call schemes.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CallScheme {
/// `CALL`.
Call,
/// `CALLCODE`
CallCode,
/// `DELEGATECALL`
DelegateCall,
/// `STATICCALL`
StaticCall,
}

/// Context of a runtime call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CallContext {
/// Execution address.
pub address: Address,
/// Caller address of the EVM.
pub caller: Address,
/// The address the contract code was loaded from, if any.
pub code_address: Address,
/// Apparent value of the EVM.
pub apparent_value: U256,
/// The scheme used for the call.
pub scheme: CallScheme,
}

impl Default for CallContext {
fn default() -> Self {
CallContext {
address: Address::default(),
caller: Address::default(),
code_address: Address::default(),
apparent_value: U256::default(),
scheme: CallScheme::Call,
}
}
}

/// Transfer from source to target, with given value.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Transfer {
/// The source address.
pub source: Address,
/// The target address.
pub target: Address,
/// The transfer value.
pub value: U256,
}

/// Result of a call that resulted in a self destruct.
#[derive(Default, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SelfDestructResult {
pub had_value: bool,
pub target_exists: bool,
pub is_cold: bool,
pub previously_destroyed: bool,
}
25 changes: 15 additions & 10 deletions crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@ mod call_helpers;
pub use call_helpers::{calc_call_gas, get_memory_input_and_out_ranges};

use crate::{
gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST},
gas::{self, EOF_CREATE_GAS},
interpreter::{Interpreter, InterpreterAction},
primitives::{Address, Bytes, Log, LogData, Spec, SpecId::*, B256, U256},
primitives::{Address, Bytes, Spec, SpecId::*, B256, U256},
CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme, Host, InstructionResult,
Transfer, MAX_INITCODE_SIZE,
};
use core::cmp::min;
use revm_primitives::BLOCK_HASH_HISTORY;
use std::{boxed::Box, vec::Vec};
use std::boxed::Box;

pub fn create3<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}
pub fn eofcrate<H: Host>(interpreter: &mut Interpreter, host: &mut H) {
Comment thread
rakita marked this conversation as resolved.
Outdated
error_on_disabled_eof!(interpreter);
gas!(interpreter, EOF_CREATE_GAS);
let initcontainer_index = unsafe { *interpreter.instruction_pointer };
pop!(interpreter, value, salt, data_offset, data_size);

pub fn create4<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}
interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.offset(1) };
}

pub fn txcreate<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}

pub fn return_contract<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}

pub fn call2<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}
pub fn extcall<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}

pub fn delegate_call2<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}
pub fn extdcall<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}

pub fn static_call2<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}
pub fn extscall<H: Host>(interpreter: &mut Interpreter, host: &mut H) {}

pub fn create<const IS_CREATE2: bool, H: Host, SPEC: Spec>(
interpreter: &mut Interpreter,
Expand Down
7 changes: 3 additions & 4 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::{
gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST},
interpreter::{Interpreter, InterpreterAction},
interpreter::Interpreter,
primitives::{Address, Bytes, Log, LogData, Spec, SpecId::*, B256, U256},
CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme, Host, InstructionResult,
SStoreResult, Transfer, MAX_INITCODE_SIZE,
Host, InstructionResult, SStoreResult,
};
use core::cmp::min;
use revm_primitives::BLOCK_HASH_HISTORY;
use std::{boxed::Box, vec::Vec};
use std::vec::Vec;

pub fn balance<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
Expand Down
Loading