Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move origin and gas price into transaction context #210

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 35 additions & 32 deletions interpreter/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod misc;
mod system;

use crate::{
CallCreateTrap, ExitException, ExitResult, ExitSucceed, Machine, Opcode, RuntimeBackend,
CallCreateTrap, ExitException, ExitResult, ExitSucceed, Machine, Opcode, RuntimeHandle,
RuntimeState,
};
use core::marker::PhantomData;
Expand All @@ -19,6 +19,9 @@ pub type Efn<S, H, Tr> = fn(&mut Machine<S>, &mut H, Opcode, usize) -> Control<T
/// The evaluation table for the EVM.
pub struct Etable<S, H, Tr, F = Efn<S, H, Tr>>([F; 256], PhantomData<(S, H, Tr)>);

unsafe impl<S, H, Tr, F: Send> Send for Etable<S, H, Tr, F> {}
unsafe impl<S, H, Tr, F: Sync> Sync for Etable<S, H, Tr, F> {}

impl<S, H, Tr, F> Deref for Etable<S, H, Tr, F> {
type Target = [F; 256];

Expand Down Expand Up @@ -179,7 +182,7 @@ impl<S, H, Tr> Etable<S, H, Tr> {
}
}

impl<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr: CallCreateTrap> Etable<S, H, Tr> {
impl<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr: CallCreateTrap> Etable<S, H, Tr> {
/// Runtime Etable.
pub const fn runtime() -> Etable<S, H, Tr> {
let mut table = Self::core();
Expand Down Expand Up @@ -1217,7 +1220,7 @@ fn eval_unknown<S, H, Tr>(
Control::Exit(ExitException::InvalidOpcode(opcode).into())
}

fn eval_sha3<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_sha3<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
_handle: &mut H,
_opcode: Opcode,
Expand All @@ -1226,7 +1229,7 @@ fn eval_sha3<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::sha3(machine)
}

fn eval_address<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_address<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
_handle: &mut H,
_opcode: Opcode,
Expand All @@ -1235,7 +1238,7 @@ fn eval_address<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::address(machine)
}

fn eval_balance<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_balance<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1244,7 +1247,7 @@ fn eval_balance<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::balance(machine, handle)
}

fn eval_selfbalance<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_selfbalance<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1253,7 +1256,7 @@ fn eval_selfbalance<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::selfbalance(machine, handle)
}

fn eval_origin<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_origin<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1262,7 +1265,7 @@ fn eval_origin<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::origin(machine, handle)
}

fn eval_caller<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_caller<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
_handle: &mut H,
_opcode: Opcode,
Expand All @@ -1271,7 +1274,7 @@ fn eval_caller<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::caller(machine)
}

fn eval_callvalue<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_callvalue<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
_handle: &mut H,
_opcode: Opcode,
Expand All @@ -1280,7 +1283,7 @@ fn eval_callvalue<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::callvalue(machine)
}

fn eval_gasprice<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_gasprice<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1289,7 +1292,7 @@ fn eval_gasprice<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::gasprice(machine, handle)
}

fn eval_extcodesize<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_extcodesize<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1298,7 +1301,7 @@ fn eval_extcodesize<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::extcodesize(machine, handle)
}

fn eval_extcodehash<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_extcodehash<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1307,7 +1310,7 @@ fn eval_extcodehash<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::extcodehash(machine, handle)
}

fn eval_extcodecopy<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_extcodecopy<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1316,7 +1319,7 @@ fn eval_extcodecopy<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::extcodecopy(machine, handle)
}

fn eval_returndatasize<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_returndatasize<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
_handle: &mut H,
_opcode: Opcode,
Expand All @@ -1325,7 +1328,7 @@ fn eval_returndatasize<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::returndatasize(machine)
}

fn eval_returndatacopy<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_returndatacopy<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
_handle: &mut H,
_opcode: Opcode,
Expand All @@ -1334,7 +1337,7 @@ fn eval_returndatacopy<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::returndatacopy(machine)
}

fn eval_blockhash<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_blockhash<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1343,7 +1346,7 @@ fn eval_blockhash<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::blockhash(machine, handle)
}

fn eval_coinbase<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_coinbase<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1352,7 +1355,7 @@ fn eval_coinbase<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::coinbase(machine, handle)
}

fn eval_timestamp<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_timestamp<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1361,7 +1364,7 @@ fn eval_timestamp<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::timestamp(machine, handle)
}

fn eval_number<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_number<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1370,7 +1373,7 @@ fn eval_number<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::number(machine, handle)
}

fn eval_difficulty<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_difficulty<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1379,7 +1382,7 @@ fn eval_difficulty<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::prevrandao(machine, handle)
}

fn eval_gaslimit<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_gaslimit<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1388,7 +1391,7 @@ fn eval_gaslimit<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::gaslimit(machine, handle)
}

fn eval_sload<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_sload<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1397,7 +1400,7 @@ fn eval_sload<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::sload(machine, handle)
}

fn eval_sstore<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_sstore<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1406,7 +1409,7 @@ fn eval_sstore<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::sstore(machine, handle)
}

fn eval_gas<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_gas<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1415,7 +1418,7 @@ fn eval_gas<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::gas(machine, handle)
}

fn eval_log0<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_log0<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1424,7 +1427,7 @@ fn eval_log0<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::log(machine, 0, handle)
}

fn eval_log1<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_log1<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1433,7 +1436,7 @@ fn eval_log1<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::log(machine, 1, handle)
}

fn eval_log2<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_log2<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1442,7 +1445,7 @@ fn eval_log2<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::log(machine, 2, handle)
}

fn eval_log3<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_log3<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1451,7 +1454,7 @@ fn eval_log3<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::log(machine, 3, handle)
}

fn eval_log4<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_log4<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1460,7 +1463,7 @@ fn eval_log4<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::log(machine, 4, handle)
}

fn eval_suicide<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_suicide<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1469,7 +1472,7 @@ fn eval_suicide<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::suicide(machine, handle)
}

fn eval_chainid<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_chainid<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand All @@ -1478,7 +1481,7 @@ fn eval_chainid<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
self::system::chainid(machine, handle)
}

fn eval_basefee<S: AsRef<RuntimeState>, H: RuntimeBackend, Tr>(
fn eval_basefee<S: AsRef<RuntimeState>, H: RuntimeHandle, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
Expand Down
Loading
Loading