From f92ec8578d92047ce0bed09c5bbb485f64371640 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Tue, 29 Aug 2023 19:38:50 +0800 Subject: [PATCH 1/2] remove all dyn for opcode --- crates/interpreter/src/instructions.rs | 52 ++++++++--------- crates/interpreter/src/instructions/host.rs | 56 +++++++++---------- .../interpreter/src/instructions/host_env.rs | 16 +++--- crates/interpreter/src/instructions/system.rs | 22 ++++---- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/crates/interpreter/src/instructions.rs b/crates/interpreter/src/instructions.rs index 7eee8cf455..f0748f2121 100644 --- a/crates/interpreter/src/instructions.rs +++ b/crates/interpreter/src/instructions.rs @@ -58,8 +58,8 @@ pub fn eval(opcode: u8, interp: &mut Interpreter, host: &mut H opcode::SAR => bitwise::sar::(interp, host), opcode::KECCAK256 => system::calculate_keccak256(interp, host), opcode::ADDRESS => system::address(interp, host), - opcode::BALANCE => host::balance::(interp, host), - opcode::SELFBALANCE => host::selfbalance::(interp, host), + opcode::BALANCE => host::balance::(interp, host), + opcode::SELFBALANCE => host::selfbalance::(interp, host), opcode::CODESIZE => system::codesize(interp, host), opcode::CODECOPY => system::codecopy(interp, host), opcode::CALLDATALOAD => system::calldataload(interp, host), @@ -144,40 +144,40 @@ pub fn eval(opcode: u8, interp: &mut Interpreter, host: &mut H opcode::RETURN => control::ret(interp, host), opcode::REVERT => control::revert::(interp, host), opcode::INVALID => return_invalid(interp, host), - opcode::BASEFEE => host_env::basefee::(interp, host), - opcode::ORIGIN => host_env::origin(interp, host), - opcode::CALLER => system::caller(interp, host), + opcode::BASEFEE => host_env::basefee::(interp, host), + opcode::ORIGIN => host_env::origin::(interp, host), + opcode::CALLER => system::caller::(interp, host), opcode::CALLVALUE => system::callvalue(interp, host), opcode::GASPRICE => host_env::gasprice(interp, host), - opcode::EXTCODESIZE => host::extcodesize::(interp, host), - opcode::EXTCODEHASH => host::extcodehash::(interp, host), - opcode::EXTCODECOPY => host::extcodecopy::(interp, host), - opcode::RETURNDATASIZE => system::returndatasize::(interp, host), - opcode::RETURNDATACOPY => system::returndatacopy::(interp, host), - opcode::BLOCKHASH => host::blockhash(interp, host), + opcode::EXTCODESIZE => host::extcodesize::(interp, host), + opcode::EXTCODEHASH => host::extcodehash::(interp, host), + opcode::EXTCODECOPY => host::extcodecopy::(interp, host), + opcode::RETURNDATASIZE => system::returndatasize::(interp, host), + opcode::RETURNDATACOPY => system::returndatacopy::(interp, host), + opcode::BLOCKHASH => host::blockhash::(interp, host), opcode::COINBASE => host_env::coinbase(interp, host), opcode::TIMESTAMP => host_env::timestamp(interp, host), opcode::NUMBER => host_env::number(interp, host), opcode::DIFFICULTY => host_env::difficulty::(interp, host), opcode::GASLIMIT => host_env::gaslimit(interp, host), - opcode::SLOAD => host::sload::(interp, host), - opcode::SSTORE => host::sstore::(interp, host), + opcode::SLOAD => host::sload::(interp, host), + opcode::SSTORE => host::sstore::(interp, host), opcode::TSTORE => host::tstore::(interp, host), opcode::TLOAD => host::tload::(interp, host), opcode::GAS => system::gas(interp, host), - opcode::LOG0 => host::log::<0>(interp, host), - opcode::LOG1 => host::log::<1>(interp, host), - opcode::LOG2 => host::log::<2>(interp, host), - opcode::LOG3 => host::log::<3>(interp, host), - opcode::LOG4 => host::log::<4>(interp, host), - opcode::SELFDESTRUCT => host::selfdestruct::(interp, host), - opcode::CREATE => host::create::(interp, host), //check - opcode::CREATE2 => host::create::(interp, host), //check - opcode::CALL => host::call::(interp, host), //check - opcode::CALLCODE => host::call_code::(interp, host), //check - opcode::DELEGATECALL => host::delegate_call::(interp, host), //check - opcode::STATICCALL => host::static_call::(interp, host), //check - opcode::CHAINID => host_env::chainid::(interp, host), + opcode::LOG0 => host::log::(interp, host), + opcode::LOG1 => host::log::(interp, host), + opcode::LOG2 => host::log::(interp, host), + opcode::LOG3 => host::log::(interp, host), + opcode::LOG4 => host::log::(interp, host), + opcode::SELFDESTRUCT => host::selfdestruct::(interp, host), + opcode::CREATE => host::create::(interp, host), //check + opcode::CREATE2 => host::create::(interp, host), //check + opcode::CALL => host::call::(interp, host), //check + opcode::CALLCODE => host::call_code::(interp, host), //check + opcode::DELEGATECALL => host::delegate_call::(interp, host), //check + opcode::STATICCALL => host::static_call::(interp, host), //check + opcode::CHAINID => host_env::chainid::(interp, host), opcode::MCOPY => memory::mcopy::(interp, host), _ => return_not_found(interp, host), } diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 95d549d633..58f028d55c 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -11,7 +11,7 @@ use crate::{ use core::cmp::min; use revm_primitives::BLOCK_HASH_HISTORY; -pub fn balance(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn balance(interpreter: &mut Interpreter, host: &mut H) { pop_address!(interpreter, address); let Some((balance, is_cold)) = host.balance(address) else { interpreter.instruction_result = InstructionResult::FatalExternalError; @@ -31,7 +31,7 @@ pub fn balance(interpreter: &mut Interpreter, host: &mut dyn Host) { push!(interpreter, balance); } -pub fn selfbalance(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn selfbalance(interpreter: &mut Interpreter, host: &mut H) { // EIP-1884: Repricing for trie-size-dependent opcodes check!(interpreter, SPEC::enabled(ISTANBUL)); gas!(interpreter, gas::LOW); @@ -42,7 +42,7 @@ pub fn selfbalance(interpreter: &mut Interpreter, host: &mut dyn Hos push!(interpreter, balance); } -pub fn extcodesize(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn extcodesize(interpreter: &mut Interpreter, host: &mut H) { pop_address!(interpreter, address); let Some((code, is_cold)) = host.code(address) else { interpreter.instruction_result = InstructionResult::FatalExternalError; @@ -66,7 +66,7 @@ pub fn extcodesize(interpreter: &mut Interpreter, host: &mut dyn Hos push!(interpreter, U256::from(code.len())); } -pub fn extcodehash(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn extcodehash(interpreter: &mut Interpreter, host: &mut H) { check!(interpreter, SPEC::enabled(CONSTANTINOPLE)); // EIP-1052: EXTCODEHASH opcode pop_address!(interpreter, address); let Some((code_hash, is_cold)) = host.code_hash(address) else { @@ -90,7 +90,7 @@ pub fn extcodehash(interpreter: &mut Interpreter, host: &mut dyn Hos push_b256!(interpreter, code_hash); } -pub fn extcodecopy(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn extcodecopy(interpreter: &mut Interpreter, host: &mut H) { pop_address!(interpreter, address); pop!(interpreter, memory_offset, code_offset, len_u256); @@ -121,7 +121,7 @@ pub fn extcodecopy(interpreter: &mut Interpreter, host: &mut dyn Hos .set_data(memory_offset, code_offset, len, code.bytes()); } -pub fn blockhash(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BLOCKHASH); pop_top!(interpreter, number); @@ -140,7 +140,7 @@ pub fn blockhash(interpreter: &mut Interpreter, host: &mut dyn Host) { *number = U256::ZERO; } -pub fn sload(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn sload(interpreter: &mut Interpreter, host: &mut H) { pop!(interpreter, index); let Some((value, is_cold)) = host.sload(interpreter.contract.address, index) else { @@ -151,7 +151,7 @@ pub fn sload(interpreter: &mut Interpreter, host: &mut dyn Host) { push!(interpreter, value); } -pub fn sstore(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn sstore(interpreter: &mut Interpreter, host: &mut H) { check_staticcall!(interpreter); pop!(interpreter, index, value); @@ -191,7 +191,7 @@ pub fn tload(interpreter: &mut Interpreter, host: &mut H) { *index = host.tload(interpreter.contract.address, *index); } -pub fn log(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn log(interpreter: &mut Interpreter, host: &mut H) { check_staticcall!(interpreter); pop!(interpreter, offset, len); @@ -221,7 +221,7 @@ pub fn log(interpreter: &mut Interpreter, host: &mut dyn Host) { host.log(interpreter.contract.address, topics, data); } -pub fn selfdestruct(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn selfdestruct(interpreter: &mut Interpreter, host: &mut H) { check_staticcall!(interpreter); pop_address!(interpreter, target); @@ -239,9 +239,9 @@ pub fn selfdestruct(interpreter: &mut Interpreter, host: &mut dyn Ho interpreter.instruction_result = InstructionResult::SelfDestruct; } -pub fn prepare_create_inputs( +pub fn prepare_create_inputs( interpreter: &mut Interpreter, - host: &mut dyn Host, + host: &mut H, create_inputs: &mut Option>, ) { check_staticcall!(interpreter); @@ -309,12 +309,12 @@ pub fn prepare_create_inputs( })); } -pub fn create( +pub fn create( interpreter: &mut Interpreter, - host: &mut dyn Host, + host: &mut H, ) { let mut create_input: Option> = None; - prepare_create_inputs::(interpreter, host, &mut create_input); + prepare_create_inputs::(interpreter, host, &mut create_input); let Some(mut create_input) = create_input else { return; @@ -352,26 +352,26 @@ pub fn create( } } -pub fn call(interpreter: &mut Interpreter, host: &mut dyn Host) { - call_inner::(interpreter, CallScheme::Call, host); +pub fn call(interpreter: &mut Interpreter, host: &mut H) { + call_inner::(interpreter, CallScheme::Call, host); } -pub fn call_code(interpreter: &mut Interpreter, host: &mut dyn Host) { - call_inner::(interpreter, CallScheme::CallCode, host); +pub fn call_code(interpreter: &mut Interpreter, host: &mut H) { + call_inner::(interpreter, CallScheme::CallCode, host); } -pub fn delegate_call(interpreter: &mut Interpreter, host: &mut dyn Host) { - call_inner::(interpreter, CallScheme::DelegateCall, host); +pub fn delegate_call(interpreter: &mut Interpreter, host: &mut H) { + call_inner::(interpreter, CallScheme::DelegateCall, host); } -pub fn static_call(interpreter: &mut Interpreter, host: &mut dyn Host) { - call_inner::(interpreter, CallScheme::StaticCall, host); +pub fn static_call(interpreter: &mut Interpreter, host: &mut H) { + call_inner::(interpreter, CallScheme::StaticCall, host); } -fn prepare_call_inputs( +fn prepare_call_inputs( interpreter: &mut Interpreter, scheme: CallScheme, - host: &mut dyn Host, + host: &mut H, result_len: &mut usize, result_offset: &mut usize, result_call_inputs: &mut Option>, @@ -511,10 +511,10 @@ fn prepare_call_inputs( })); } -pub fn call_inner( +pub fn call_inner( interpreter: &mut Interpreter, scheme: CallScheme, - host: &mut dyn Host, + host: &mut H, ) { match scheme { CallScheme::DelegateCall => check!(interpreter, SPEC::enabled(HOMESTEAD)), // EIP-7: DELEGATECALL @@ -526,7 +526,7 @@ pub fn call_inner( let mut out_offset: usize = 0; let mut out_len: usize = 0; let mut call_input: Option> = None; - prepare_call_inputs::( + prepare_call_inputs::( interpreter, scheme, host, diff --git a/crates/interpreter/src/instructions/host_env.rs b/crates/interpreter/src/instructions/host_env.rs index e3d7d5fc6a..0e1a8a562f 100644 --- a/crates/interpreter/src/instructions/host_env.rs +++ b/crates/interpreter/src/instructions/host_env.rs @@ -2,24 +2,24 @@ use crate::{ gas, interpreter::Interpreter, primitives::Spec, primitives::SpecId::*, Host, InstructionResult, }; -pub fn chainid(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn chainid(interpreter: &mut Interpreter, host: &mut H) { // EIP-1344: ChainID opcode check!(interpreter, SPEC::enabled(ISTANBUL)); gas!(interpreter, gas::BASE); push!(interpreter, host.env().cfg.chain_id); } -pub fn coinbase(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn coinbase(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, host.env().block.coinbase.into()); } -pub fn timestamp(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn timestamp(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, host.env().block.timestamp); } -pub fn number(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn number(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, host.env().block.number); } @@ -33,24 +33,24 @@ pub fn difficulty(interpreter: &mut Interpreter, host: &mut } } -pub fn gaslimit(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn gaslimit(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, host.env().block.gas_limit); } -pub fn gasprice(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn gasprice(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, host.env().effective_gas_price()); } -pub fn basefee(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn basefee(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); // EIP-3198: BASEFEE opcode check!(interpreter, SPEC::enabled(LONDON)); push!(interpreter, host.env().block.basefee); } -pub fn origin(interpreter: &mut Interpreter, host: &mut dyn Host) { +pub fn origin(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, host.env().tx.caller.into()); } diff --git a/crates/interpreter/src/instructions/system.rs b/crates/interpreter/src/instructions/system.rs index a40a6c6cf5..9ee6a52696 100644 --- a/crates/interpreter/src/instructions/system.rs +++ b/crates/interpreter/src/instructions/system.rs @@ -21,22 +21,22 @@ pub fn calculate_keccak256(interpreter: &mut Interpreter, _host: &mut dyn Host) push_b256!(interpreter, hash); } -pub fn address(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn address(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, B256::from(interpreter.contract.address)); } -pub fn caller(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn caller(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, B256::from(interpreter.contract.caller)); } -pub fn codesize(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn codesize(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, U256::from(interpreter.contract.bytecode.len())); } -pub fn codecopy(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn codecopy(interpreter: &mut Interpreter, _host: &mut H) { pop!(interpreter, memory_offset, code_offset, len); let len = as_usize_or_fail!(interpreter, len, InstructionResult::InvalidOperandOOG); gas_or_fail!(interpreter, gas::verylowcopy_cost(len as u64)); @@ -60,7 +60,7 @@ pub fn codecopy(interpreter: &mut Interpreter, _host: &mut dyn Host) { ); } -pub fn calldataload(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn calldataload(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index); let index = as_usize_saturated!(index); @@ -77,17 +77,17 @@ pub fn calldataload(interpreter: &mut Interpreter, _host: &mut dyn Host) { push_b256!(interpreter, load); } -pub fn calldatasize(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn calldatasize(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, U256::from(interpreter.contract.input.len())); } -pub fn callvalue(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn callvalue(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, interpreter.contract.value); } -pub fn calldatacopy(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn calldatacopy(interpreter: &mut Interpreter, _host: &mut H) { pop!(interpreter, memory_offset, data_offset, len); let len = as_usize_or_fail!(interpreter, len, InstructionResult::InvalidOperandOOG); gas_or_fail!(interpreter, gas::verylowcopy_cost(len as u64)); @@ -108,7 +108,7 @@ pub fn calldatacopy(interpreter: &mut Interpreter, _host: &mut dyn Host) { .set_data(memory_offset, data_offset, len, &interpreter.contract.input); } -pub fn returndatasize(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn returndatasize(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); // EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY check!(interpreter, SPEC::enabled(BYZANTIUM)); @@ -118,7 +118,7 @@ pub fn returndatasize(interpreter: &mut Interpreter, _host: &mut dyn ); } -pub fn returndatacopy(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn returndatacopy(interpreter: &mut Interpreter, _host: &mut H) { // EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY check!(interpreter, SPEC::enabled(BYZANTIUM)); pop!(interpreter, memory_offset, offset, len); @@ -144,7 +144,7 @@ pub fn returndatacopy(interpreter: &mut Interpreter, _host: &mut dyn } } -pub fn gas(interpreter: &mut Interpreter, _host: &mut dyn Host) { +pub fn gas(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, U256::from(interpreter.gas.remaining())); } From 0f7d39248d77eeebe1c215579bd91d1e84eaec2c Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Tue, 29 Aug 2023 19:38:59 +0800 Subject: [PATCH 2/2] fmt --- crates/interpreter/src/instructions.rs | 2 +- crates/interpreter/src/instructions/host_env.rs | 2 +- crates/interpreter/src/instructions/system.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/interpreter/src/instructions.rs b/crates/interpreter/src/instructions.rs index f0748f2121..7ab1295fd9 100644 --- a/crates/interpreter/src/instructions.rs +++ b/crates/interpreter/src/instructions.rs @@ -144,7 +144,7 @@ pub fn eval(opcode: u8, interp: &mut Interpreter, host: &mut H opcode::RETURN => control::ret(interp, host), opcode::REVERT => control::revert::(interp, host), opcode::INVALID => return_invalid(interp, host), - opcode::BASEFEE => host_env::basefee::(interp, host), + opcode::BASEFEE => host_env::basefee::(interp, host), opcode::ORIGIN => host_env::origin::(interp, host), opcode::CALLER => system::caller::(interp, host), opcode::CALLVALUE => system::callvalue(interp, host), diff --git a/crates/interpreter/src/instructions/host_env.rs b/crates/interpreter/src/instructions/host_env.rs index 0e1a8a562f..3818fb7085 100644 --- a/crates/interpreter/src/instructions/host_env.rs +++ b/crates/interpreter/src/instructions/host_env.rs @@ -43,7 +43,7 @@ pub fn gasprice(interpreter: &mut Interpreter, host: &mut H) { push!(interpreter, host.env().effective_gas_price()); } -pub fn basefee(interpreter: &mut Interpreter, host: &mut H) { +pub fn basefee(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BASE); // EIP-3198: BASEFEE opcode check!(interpreter, SPEC::enabled(LONDON)); diff --git a/crates/interpreter/src/instructions/system.rs b/crates/interpreter/src/instructions/system.rs index 9ee6a52696..36f77935b7 100644 --- a/crates/interpreter/src/instructions/system.rs +++ b/crates/interpreter/src/instructions/system.rs @@ -118,7 +118,7 @@ pub fn returndatasize(interpreter: &mut Interpreter, _host: ); } -pub fn returndatacopy(interpreter: &mut Interpreter, _host: &mut H) { +pub fn returndatacopy(interpreter: &mut Interpreter, _host: &mut H) { // EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY check!(interpreter, SPEC::enabled(BYZANTIUM)); pop!(interpreter, memory_offset, offset, len); @@ -144,7 +144,7 @@ pub fn returndatacopy(interpreter: &mut Interpreter, _host: } } -pub fn gas(interpreter: &mut Interpreter, _host: &mut H) { +pub fn gas(interpreter: &mut Interpreter, _host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, U256::from(interpreter.gas.remaining())); }