diff --git a/bins/revme/src/cli_env.rs b/bins/revme/src/cli_env.rs index 9ab82dc3d3..45cb7261c1 100644 --- a/bins/revme/src/cli_env.rs +++ b/bins/revme/src/cli_env.rs @@ -1,7 +1,7 @@ use revm::primitives::{Address, Bytes, Env, TransactTo, U256}; use structopt::StructOpt; -#[derive(StructOpt, Clone, Debug)] +#[derive(StructOpt, Clone, Debug, PartialEq, Eq)] pub struct CliEnv { #[structopt(flatten)] block: CliEnvBlock, @@ -51,7 +51,7 @@ impl From for Env { } } -#[derive(StructOpt, Clone, Debug)] +#[derive(StructOpt, Clone, Debug, PartialEq, Eq)] pub struct CliEnvBlock { #[structopt(long = "env.block.gas_limit")] pub block_gas_limit: Option, @@ -71,7 +71,7 @@ pub struct CliEnvBlock { pub basefee: Option, } -#[derive(StructOpt, Clone, Debug)] +#[derive(StructOpt, Clone, Debug, PartialEq, Eq)] pub struct CliEnvTx { /// Caller or Author or tx signer #[structopt(long = "env.tx.caller")] diff --git a/bins/revme/src/statetest/merkle_trie.rs b/bins/revme/src/statetest/merkle_trie.rs index cda0bfd2e1..1a8b3ec2b2 100644 --- a/bins/revme/src/statetest/merkle_trie.rs +++ b/bins/revme/src/statetest/merkle_trie.rs @@ -59,7 +59,7 @@ where sec_trie_root::(input) } -#[derive(Default, Debug, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] pub struct KeccakHasher; impl Hasher for KeccakHasher { diff --git a/bins/revme/src/statetest/models/spec.rs b/bins/revme/src/statetest/models/spec.rs index 5a5561c27f..53c134e479 100644 --- a/bins/revme/src/statetest/models/spec.rs +++ b/bins/revme/src/statetest/models/spec.rs @@ -1,7 +1,7 @@ use revm::primitives::SpecId; use serde::Deserialize; -#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Ord, Deserialize)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize, Hash)] pub enum SpecName { Frontier, FrontierToHomesteadAt5, diff --git a/crates/interpreter/src/gas.rs b/crates/interpreter/src/gas.rs index 350c1ecef1..c95edf9c6b 100644 --- a/crates/interpreter/src/gas.rs +++ b/crates/interpreter/src/gas.rs @@ -7,7 +7,7 @@ pub use calc::*; pub use constants::*; /// Represents the state of gas during execution. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct Gas { /// The initial gas limit. limit: u64, diff --git a/crates/interpreter/src/host.rs b/crates/interpreter/src/host.rs index d9a936a8d3..637487f4ff 100644 --- a/crates/interpreter/src/host.rs +++ b/crates/interpreter/src/host.rs @@ -12,12 +12,12 @@ mod dummy; /// EVM context host. pub trait Host { /// Called before the interpreter executes an instruction. - fn step(&mut self, interpreter: &mut Interpreter) -> InstructionResult; + fn step(&mut self, interpreter: &mut Interpreter<'_>) -> InstructionResult; /// Called after the interpreter executes an instruction. fn step_end( &mut self, - interpreter: &mut Interpreter, + interpreter: &mut Interpreter<'_>, ret: InstructionResult, ) -> InstructionResult; diff --git a/crates/interpreter/src/host/dummy.rs b/crates/interpreter/src/host/dummy.rs index cde587c760..dcf2023fe3 100644 --- a/crates/interpreter/src/host/dummy.rs +++ b/crates/interpreter/src/host/dummy.rs @@ -7,6 +7,7 @@ use crate::{ use alloc::vec::Vec; /// A dummy [Host] implementation. +#[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct DummyHost { pub env: Env, pub storage: HashMap, @@ -20,9 +21,7 @@ impl DummyHost { pub fn new(env: Env) -> Self { Self { env, - storage: HashMap::new(), - transient_storage: Default::default(), - log: Vec::new(), + ..Default::default() } } @@ -36,14 +35,14 @@ impl DummyHost { impl Host for DummyHost { #[inline] - fn step(&mut self, _interp: &mut Interpreter) -> InstructionResult { + fn step(&mut self, _interp: &mut Interpreter<'_>) -> InstructionResult { InstructionResult::Continue } #[inline] fn step_end( &mut self, - _interp: &mut Interpreter, + _interp: &mut Interpreter<'_>, _ret: InstructionResult, ) -> InstructionResult { InstructionResult::Continue diff --git a/crates/interpreter/src/inner_models.rs b/crates/interpreter/src/inner_models.rs index c637ec6017..97758ba79a 100644 --- a/crates/interpreter/src/inner_models.rs +++ b/crates/interpreter/src/inner_models.rs @@ -2,6 +2,7 @@ pub use crate::primitives::CreateScheme; use crate::primitives::{Address, Bytes, U256}; /// 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. @@ -19,6 +20,7 @@ pub struct CallInputs { } /// 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. @@ -34,7 +36,7 @@ pub struct CreateInputs { } /// Call schemes. -#[derive(Clone, Copy, Eq, PartialEq, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum CallScheme { /// `CALL` @@ -48,7 +50,7 @@ pub enum CallScheme { } /// Context of a runtime call. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct CallContext { /// Execution address. @@ -76,7 +78,7 @@ impl Default for CallContext { } /// Transfer from source to target, with given value. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Transfer { /// The source address. @@ -88,7 +90,7 @@ pub struct Transfer { } /// Result of a call that resulted in a self destruct. -#[derive(Default)] +#[derive(Default, Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SelfDestructResult { pub had_value: bool, diff --git a/crates/interpreter/src/instruction_result.rs b/crates/interpreter/src/instruction_result.rs index 6644a58e81..4214dc7288 100644 --- a/crates/interpreter/src/instruction_result.rs +++ b/crates/interpreter/src/instruction_result.rs @@ -1,7 +1,7 @@ use crate::primitives::{Eval, Halt}; #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum InstructionResult { // success codes @@ -89,7 +89,7 @@ impl InstructionResult { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum SuccessOrHalt { Success(Eval), Revert, diff --git a/crates/interpreter/src/instructions/arithmetic.rs b/crates/interpreter/src/instructions/arithmetic.rs index e0700ee3f3..ab82b9a114 100644 --- a/crates/interpreter/src/instructions/arithmetic.rs +++ b/crates/interpreter/src/instructions/arithmetic.rs @@ -5,25 +5,25 @@ use crate::{ Host, InstructionResult, Interpreter, }; -pub fn wrapped_add(interpreter: &mut Interpreter, _host: &mut H) { +pub fn wrapped_add(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = op1.wrapping_add(*op2); } -pub fn wrapping_mul(interpreter: &mut Interpreter, _host: &mut H) { +pub fn wrapping_mul(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); *op2 = op1.wrapping_mul(*op2); } -pub fn wrapping_sub(interpreter: &mut Interpreter, _host: &mut H) { +pub fn wrapping_sub(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = op1.wrapping_sub(*op2); } -pub fn div(interpreter: &mut Interpreter, _host: &mut H) { +pub fn div(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); if *op2 != U256::ZERO { @@ -31,13 +31,13 @@ pub fn div(interpreter: &mut Interpreter, _host: &mut H) { } } -pub fn sdiv(interpreter: &mut Interpreter, _host: &mut H) { +pub fn sdiv(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); *op2 = i256_div(op1, *op2); } -pub fn rem(interpreter: &mut Interpreter, _host: &mut H) { +pub fn rem(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); if *op2 != U256::ZERO { @@ -45,7 +45,7 @@ pub fn rem(interpreter: &mut Interpreter, _host: &mut H) { } } -pub fn smod(interpreter: &mut Interpreter, _host: &mut H) { +pub fn smod(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); if *op2 != U256::ZERO { @@ -53,19 +53,19 @@ pub fn smod(interpreter: &mut Interpreter, _host: &mut H) { } } -pub fn addmod(interpreter: &mut Interpreter, _host: &mut H) { +pub fn addmod(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::MID); pop_top!(interpreter, op1, op2, op3); *op3 = op1.add_mod(op2, *op3) } -pub fn mulmod(interpreter: &mut Interpreter, _host: &mut H) { +pub fn mulmod(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::MID); pop_top!(interpreter, op1, op2, op3); *op3 = op1.mul_mod(op2, *op3) } -pub fn exp(interpreter: &mut Interpreter, _host: &mut H) { +pub fn exp(interpreter: &mut Interpreter<'_>, _host: &mut H) { pop_top!(interpreter, op1, op2); gas_or_fail!(interpreter, gas::exp_cost::(*op2)); *op2 = op1.pow(*op2); @@ -86,7 +86,7 @@ pub fn exp(interpreter: &mut Interpreter, _host: &mut H) { /// `y | !mask` where `|` is the bitwise `OR` and `!` is bitwise negation. Similarly, if /// `b == 0` then the yellow paper says the output should start with all zeros, then end with /// bits from `b`; this is equal to `y & mask` where `&` is bitwise `AND`. -pub fn signextend(interpreter: &mut Interpreter, _host: &mut H) { +pub fn signextend(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::LOW); pop_top!(interpreter, op1, op2); if op1 < U256::from(32) { diff --git a/crates/interpreter/src/instructions/bitwise.rs b/crates/interpreter/src/instructions/bitwise.rs index d9fffbfe3e..d8abe677bf 100644 --- a/crates/interpreter/src/instructions/bitwise.rs +++ b/crates/interpreter/src/instructions/bitwise.rs @@ -6,67 +6,67 @@ use crate::{ }; use core::cmp::Ordering; -pub fn lt(interpreter: &mut Interpreter, _host: &mut H) { +pub fn lt(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = U256::from(op1 < *op2); } -pub fn gt(interpreter: &mut Interpreter, _host: &mut H) { +pub fn gt(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = U256::from(op1 > *op2); } -pub fn slt(interpreter: &mut Interpreter, _host: &mut H) { +pub fn slt(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = U256::from(i256_cmp(&op1, op2) == Ordering::Less); } -pub fn sgt(interpreter: &mut Interpreter, _host: &mut H) { +pub fn sgt(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = U256::from(i256_cmp(&op1, op2) == Ordering::Greater); } -pub fn eq(interpreter: &mut Interpreter, _host: &mut H) { +pub fn eq(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = U256::from(op1 == *op2); } -pub fn iszero(interpreter: &mut Interpreter, _host: &mut H) { +pub fn iszero(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1); *op1 = U256::from(*op1 == U256::ZERO); } -pub fn bitand(interpreter: &mut Interpreter, _host: &mut H) { +pub fn bitand(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = op1 & *op2; } -pub fn bitor(interpreter: &mut Interpreter, _host: &mut H) { +pub fn bitor(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = op1 | *op2; } -pub fn bitxor(interpreter: &mut Interpreter, _host: &mut H) { +pub fn bitxor(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); *op2 = op1 ^ *op2; } -pub fn not(interpreter: &mut Interpreter, _host: &mut H) { +pub fn not(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1); *op1 = !*op1; } -pub fn byte(interpreter: &mut Interpreter, _host: &mut H) { +pub fn byte(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); @@ -80,7 +80,7 @@ pub fn byte(interpreter: &mut Interpreter, _host: &mut H) { } /// EIP-145: Bitwise shifting instructions in EVM -pub fn shl(interpreter: &mut Interpreter, _host: &mut H) { +pub fn shl(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, CONSTANTINOPLE); gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); @@ -88,7 +88,7 @@ pub fn shl(interpreter: &mut Interpreter, _host: &mut H) { } /// EIP-145: Bitwise shifting instructions in EVM -pub fn shr(interpreter: &mut Interpreter, _host: &mut H) { +pub fn shr(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, CONSTANTINOPLE); gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); @@ -96,7 +96,7 @@ pub fn shr(interpreter: &mut Interpreter, _host: &mut H) { } /// EIP-145: Bitwise shifting instructions in EVM -pub fn sar(interpreter: &mut Interpreter, _host: &mut H) { +pub fn sar(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, CONSTANTINOPLE); gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, op1, op2); diff --git a/crates/interpreter/src/instructions/control.rs b/crates/interpreter/src/instructions/control.rs index ed5a3086cb..beb2f2c8ce 100644 --- a/crates/interpreter/src/instructions/control.rs +++ b/crates/interpreter/src/instructions/control.rs @@ -4,7 +4,7 @@ use crate::{ Host, InstructionResult, Interpreter, }; -pub fn jump(interpreter: &mut Interpreter, _host: &mut H) { +pub fn jump(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::MID); pop!(interpreter, dest); let dest = as_usize_or_fail!(interpreter, dest, InstructionResult::InvalidJump); @@ -18,7 +18,7 @@ pub fn jump(interpreter: &mut Interpreter, _host: &mut H) { } } -pub fn jumpi(interpreter: &mut Interpreter, _host: &mut H) { +pub fn jumpi(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::HIGH); pop!(interpreter, dest, value); if value != U256::ZERO { @@ -34,18 +34,18 @@ pub fn jumpi(interpreter: &mut Interpreter, _host: &mut H) { } } -pub fn jumpdest(interpreter: &mut Interpreter, _host: &mut H) { +pub fn jumpdest(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::JUMPDEST); } -pub fn pc(interpreter: &mut Interpreter, _host: &mut H) { +pub fn pc(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::BASE); // - 1 because we have already advanced the instruction pointer in `Interpreter::step` push!(interpreter, U256::from(interpreter.program_counter() - 1)); } #[inline(always)] -fn return_inner(interpreter: &mut Interpreter, result: InstructionResult) { +fn return_inner(interpreter: &mut Interpreter<'_>, result: InstructionResult) { // zero gas cost // gas!(interpreter, gas::ZERO); pop!(interpreter, offset, len); @@ -60,24 +60,24 @@ fn return_inner(interpreter: &mut Interpreter, result: InstructionResult) { interpreter.instruction_result = result; } -pub fn ret(interpreter: &mut Interpreter, _host: &mut H) { +pub fn ret(interpreter: &mut Interpreter<'_>, _host: &mut H) { return_inner(interpreter, InstructionResult::Return) } /// EIP-140: REVERT instruction -pub fn revert(interpreter: &mut Interpreter, _host: &mut H) { +pub fn revert(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, BYZANTIUM); return_inner(interpreter, InstructionResult::Revert) } -pub fn stop(interpreter: &mut Interpreter, _host: &mut H) { +pub fn stop(interpreter: &mut Interpreter<'_>, _host: &mut H) { interpreter.instruction_result = InstructionResult::Stop; } -pub fn invalid(interpreter: &mut Interpreter, _host: &mut H) { +pub fn invalid(interpreter: &mut Interpreter<'_>, _host: &mut H) { interpreter.instruction_result = InstructionResult::InvalidFEOpcode; } -pub fn not_found(interpreter: &mut Interpreter, _host: &mut H) { +pub fn not_found(interpreter: &mut Interpreter<'_>, _host: &mut H) { interpreter.instruction_result = InstructionResult::OpcodeNotFound; } diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 928c6b5000..d12dc6aa26 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -10,7 +10,7 @@ use alloc::{boxed::Box, vec::Vec}; use core::cmp::min; use revm_primitives::BLOCK_HASH_HISTORY; -pub fn balance(interpreter: &mut Interpreter, host: &mut H) { +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 H) } /// EIP-1884: Repricing for trie-size-dependent opcodes -pub fn selfbalance(interpreter: &mut Interpreter, host: &mut H) { +pub fn selfbalance(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, ISTANBUL); gas!(interpreter, gas::LOW); let Some((balance, _)) = host.balance(interpreter.contract.address) else { @@ -41,7 +41,7 @@ pub fn selfbalance(interpreter: &mut Interpreter, host: &mu push!(interpreter, balance); } -pub fn extcodesize(interpreter: &mut Interpreter, host: &mut H) { +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: &mu } /// EIP-1052: EXTCODEHASH opcode -pub fn extcodehash(interpreter: &mut Interpreter, host: &mut H) { +pub fn extcodehash(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, CONSTANTINOPLE); 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: &mu push_b256!(interpreter, code_hash); } -pub fn extcodecopy(interpreter: &mut Interpreter, host: &mut H) { +pub fn extcodecopy(interpreter: &mut Interpreter<'_>, host: &mut H) { pop_address!(interpreter, address); pop!(interpreter, memory_offset, code_offset, len_u256); @@ -117,7 +117,7 @@ pub fn extcodecopy(interpreter: &mut Interpreter, host: &mu .set_data(memory_offset, code_offset, len, code.bytes()); } -pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { +pub fn blockhash(interpreter: &mut Interpreter<'_>, host: &mut H) { gas!(interpreter, gas::BLOCKHASH); pop_top!(interpreter, number); @@ -136,7 +136,7 @@ pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { *number = U256::ZERO; } -pub fn sload(interpreter: &mut Interpreter, host: &mut H) { +pub fn sload(interpreter: &mut Interpreter<'_>, host: &mut H) { pop!(interpreter, index); let Some((value, is_cold)) = host.sload(interpreter.contract.address, index) else { @@ -147,7 +147,7 @@ pub fn sload(interpreter: &mut Interpreter, host: &mut H) { push!(interpreter, value); } -pub fn sstore(interpreter: &mut Interpreter, host: &mut H) { +pub fn sstore(interpreter: &mut Interpreter<'_>, host: &mut H) { check_staticcall!(interpreter); pop!(interpreter, index, value); @@ -166,7 +166,7 @@ pub fn sstore(interpreter: &mut Interpreter, host: &mut H) /// EIP-1153: Transient storage opcodes /// Store value to transient storage -pub fn tstore(interpreter: &mut Interpreter, host: &mut H) { +pub fn tstore(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, CANCUN); check_staticcall!(interpreter); gas!(interpreter, gas::WARM_STORAGE_READ_COST); @@ -178,7 +178,7 @@ pub fn tstore(interpreter: &mut Interpreter, host: &mut H) /// EIP-1153: Transient storage opcodes /// Load value from transient storage -pub fn tload(interpreter: &mut Interpreter, host: &mut H) { +pub fn tload(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, CANCUN); gas!(interpreter, gas::WARM_STORAGE_READ_COST); @@ -187,7 +187,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 H) { +pub fn log(interpreter: &mut Interpreter<'_>, host: &mut H) { check_staticcall!(interpreter); pop!(interpreter, offset, len); @@ -217,7 +217,7 @@ pub fn log(interpreter: &mut Interpreter, host: &mut H) host.log(interpreter.contract.address, topics, data); } -pub fn selfdestruct(interpreter: &mut Interpreter, host: &mut H) { +pub fn selfdestruct(interpreter: &mut Interpreter<'_>, host: &mut H) { check_staticcall!(interpreter); pop_address!(interpreter, target); @@ -237,7 +237,7 @@ pub fn selfdestruct(interpreter: &mut Interpreter, host: &m #[inline(never)] pub fn prepare_create_inputs( - interpreter: &mut Interpreter, + interpreter: &mut Interpreter<'_>, host: &mut H, create_inputs: &mut Option>, ) { @@ -305,7 +305,7 @@ pub fn prepare_create_inputs( } pub fn create( - interpreter: &mut Interpreter, + interpreter: &mut Interpreter<'_>, host: &mut H, ) { let mut create_input: Option> = None; @@ -350,25 +350,25 @@ pub fn create( } } -pub fn call(interpreter: &mut Interpreter, host: &mut H) { +pub fn call(interpreter: &mut Interpreter<'_>, host: &mut H) { call_inner::(CallScheme::Call, interpreter, host); } -pub fn call_code(interpreter: &mut Interpreter, host: &mut H) { +pub fn call_code(interpreter: &mut Interpreter<'_>, host: &mut H) { call_inner::(CallScheme::CallCode, interpreter, host); } -pub fn delegate_call(interpreter: &mut Interpreter, host: &mut H) { +pub fn delegate_call(interpreter: &mut Interpreter<'_>, host: &mut H) { call_inner::(CallScheme::DelegateCall, interpreter, host); } -pub fn static_call(interpreter: &mut Interpreter, host: &mut H) { +pub fn static_call(interpreter: &mut Interpreter<'_>, host: &mut H) { call_inner::(CallScheme::StaticCall, interpreter, host); } #[inline(never)] fn prepare_call_inputs( - interpreter: &mut Interpreter, + interpreter: &mut Interpreter<'_>, scheme: CallScheme, host: &mut H, result_len: &mut usize, @@ -507,7 +507,7 @@ fn prepare_call_inputs( pub fn call_inner( scheme: CallScheme, - interpreter: &mut Interpreter, + interpreter: &mut Interpreter<'_>, host: &mut H, ) { match scheme { diff --git a/crates/interpreter/src/instructions/host_env.rs b/crates/interpreter/src/instructions/host_env.rs index cce993bac6..6f964e0ccc 100644 --- a/crates/interpreter/src/instructions/host_env.rs +++ b/crates/interpreter/src/instructions/host_env.rs @@ -5,28 +5,28 @@ use crate::{ }; /// EIP-1344: ChainID opcode -pub fn chainid(interpreter: &mut Interpreter, host: &mut H) { +pub fn chainid(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, ISTANBUL); gas!(interpreter, gas::BASE); push!(interpreter, U256::from(host.env().cfg.chain_id)); } -pub fn coinbase(interpreter: &mut Interpreter, host: &mut H) { +pub fn coinbase(interpreter: &mut Interpreter<'_>, host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, host.env().block.coinbase.into_word()); } -pub fn timestamp(interpreter: &mut Interpreter, host: &mut H) { +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 H) { +pub fn number(interpreter: &mut Interpreter<'_>, host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, host.env().block.number); } -pub fn difficulty(interpreter: &mut Interpreter, host: &mut H) { +pub fn difficulty(interpreter: &mut Interpreter<'_>, host: &mut H) { gas!(interpreter, gas::BASE); if SPEC::enabled(MERGE) { push_b256!(interpreter, host.env().block.prevrandao.unwrap()); @@ -35,30 +35,30 @@ pub fn difficulty(interpreter: &mut Interpreter, host: &mut } } -pub fn gaslimit(interpreter: &mut Interpreter, host: &mut H) { +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 H) { +pub fn gasprice(interpreter: &mut Interpreter<'_>, host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, host.env().effective_gas_price()); } /// EIP-3198: BASEFEE opcode -pub fn basefee(interpreter: &mut Interpreter, host: &mut H) { +pub fn basefee(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, LONDON); gas!(interpreter, gas::BASE); push!(interpreter, host.env().block.basefee); } -pub fn origin(interpreter: &mut Interpreter, host: &mut H) { +pub fn origin(interpreter: &mut Interpreter<'_>, host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, host.env().tx.caller.into_word()); } // EIP-4844: Shard Blob Transactions -pub fn blob_hash(interpreter: &mut Interpreter, host: &mut H) { +pub fn blob_hash(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, CANCUN); gas!(interpreter, gas::VERYLOW); pop_top!(interpreter, index); @@ -70,7 +70,7 @@ pub fn blob_hash(interpreter: &mut Interpreter, host: &mut } /// EIP-7516: BLOBBASEFEE opcode -pub fn blob_basefee(interpreter: &mut Interpreter, host: &mut H) { +pub fn blob_basefee(interpreter: &mut Interpreter<'_>, host: &mut H) { check!(interpreter, CANCUN); gas!(interpreter, gas::BASE); push!( diff --git a/crates/interpreter/src/instructions/i256.rs b/crates/interpreter/src/instructions/i256.rs index 5b7d21de88..6f217b9911 100644 --- a/crates/interpreter/src/instructions/i256.rs +++ b/crates/interpreter/src/instructions/i256.rs @@ -1,7 +1,7 @@ use crate::primitives::U256; use core::cmp::Ordering; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(i8)] pub enum Sign { // same as `cmp::Ordering` diff --git a/crates/interpreter/src/instructions/memory.rs b/crates/interpreter/src/instructions/memory.rs index b3ae69cacb..8fb321855c 100644 --- a/crates/interpreter/src/instructions/memory.rs +++ b/crates/interpreter/src/instructions/memory.rs @@ -5,7 +5,7 @@ use crate::{ }; use core::cmp::max; -pub fn mload(interpreter: &mut Interpreter, _host: &mut H) { +pub fn mload(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index); let index = as_usize_or_fail!(interpreter, index); @@ -22,7 +22,7 @@ pub fn mload(interpreter: &mut Interpreter, _host: &mut H) { ); } -pub fn mstore(interpreter: &mut Interpreter, _host: &mut H) { +pub fn mstore(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index, value); let index = as_usize_or_fail!(interpreter, index); @@ -30,7 +30,7 @@ pub fn mstore(interpreter: &mut Interpreter, _host: &mut H) { interpreter.shared_memory.set_u256(index, value); } -pub fn mstore8(interpreter: &mut Interpreter, _host: &mut H) { +pub fn mstore8(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index, value); let index = as_usize_or_fail!(interpreter, index); @@ -38,13 +38,13 @@ pub fn mstore8(interpreter: &mut Interpreter, _host: &mut H) { interpreter.shared_memory.set_byte(index, value.byte(0)) } -pub fn msize(interpreter: &mut Interpreter, _host: &mut H) { +pub fn msize(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::BASE); push!(interpreter, U256::from(interpreter.shared_memory.len())); } // EIP-5656: MCOPY - Memory copying instruction -pub fn mcopy(interpreter: &mut Interpreter, _host: &mut H) { +pub fn mcopy(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, CANCUN); pop!(interpreter, dst, src, len); diff --git a/crates/interpreter/src/instructions/opcode.rs b/crates/interpreter/src/instructions/opcode.rs index 61ef794b51..aaf36bd8cd 100644 --- a/crates/interpreter/src/instructions/opcode.rs +++ b/crates/interpreter/src/instructions/opcode.rs @@ -9,7 +9,7 @@ use crate::{ use core::fmt; /// EVM opcode function signature. -pub type Instruction = fn(&mut Interpreter, &mut H); +pub type Instruction = fn(&mut Interpreter<'_>, &mut H); macro_rules! opcodes { ($($val:literal => $name:ident => $f:expr),* $(,)?) => { @@ -58,7 +58,7 @@ macro_rules! opcodes { /// Evaluates the opcode in the given context. #[inline(always)] - pub fn eval(opcode: u8, interpreter: &mut Interpreter, host: &mut H) { + pub fn eval(opcode: u8, interpreter: &mut Interpreter<'_>, host: &mut H) { // See https://github.com/bluealloy/revm/issues/310#issuecomment-1664381513 // for previous efforts on optimizing this function. let f: Instruction = match opcode { diff --git a/crates/interpreter/src/instructions/stack.rs b/crates/interpreter/src/instructions/stack.rs index 5387d7001d..29b8c6f740 100644 --- a/crates/interpreter/src/instructions/stack.rs +++ b/crates/interpreter/src/instructions/stack.rs @@ -4,7 +4,7 @@ use crate::{ Host, InstructionResult, Interpreter, }; -pub fn pop(interpreter: &mut Interpreter, _host: &mut H) { +pub fn pop(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::BASE); if let Err(result) = interpreter.stack.pop() { interpreter.instruction_result = result; @@ -14,7 +14,7 @@ pub fn pop(interpreter: &mut Interpreter, _host: &mut H) { /// EIP-3855: PUSH0 instruction /// /// Introduce a new instruction which pushes the constant value 0 onto the stack. -pub fn push0(interpreter: &mut Interpreter, _host: &mut H) { +pub fn push0(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, SHANGHAI); gas!(interpreter, gas::BASE); if let Err(result) = interpreter.stack.push(U256::ZERO) { @@ -22,7 +22,7 @@ pub fn push0(interpreter: &mut Interpreter, _host: &mut H) } } -pub fn push(interpreter: &mut Interpreter, _host: &mut H) { +pub fn push(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); let start = interpreter.instruction_pointer; // Safety: In Analysis we appended needed bytes for bytecode so that we are safe to just add without @@ -37,14 +37,14 @@ pub fn push(interpreter: &mut Interpreter, _host: &mut interpreter.instruction_pointer = unsafe { start.add(N) }; } -pub fn dup(interpreter: &mut Interpreter, _host: &mut H) { +pub fn dup(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); if let Err(result) = interpreter.stack.dup::() { interpreter.instruction_result = result; } } -pub fn swap(interpreter: &mut Interpreter, _host: &mut H) { +pub fn swap(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); if let Err(result) = interpreter.stack.swap::() { interpreter.instruction_result = result; diff --git a/crates/interpreter/src/instructions/system.rs b/crates/interpreter/src/instructions/system.rs index 9ae285bb1e..887a640489 100644 --- a/crates/interpreter/src/instructions/system.rs +++ b/crates/interpreter/src/instructions/system.rs @@ -4,7 +4,7 @@ use crate::{ Host, InstructionResult, Interpreter, }; -pub fn keccak256(interpreter: &mut Interpreter, _host: &mut H) { +pub fn keccak256(interpreter: &mut Interpreter<'_>, _host: &mut H) { pop!(interpreter, from, len); let len = as_usize_or_fail!(interpreter, len); gas_or_fail!(interpreter, gas::keccak256_cost(len as u64)); @@ -19,22 +19,22 @@ pub fn keccak256(interpreter: &mut Interpreter, _host: &mut H) { push_b256!(interpreter, hash); } -pub fn address(interpreter: &mut Interpreter, _host: &mut H) { +pub fn address(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, interpreter.contract.address.into_word()); } -pub fn caller(interpreter: &mut Interpreter, _host: &mut H) { +pub fn caller(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::BASE); push_b256!(interpreter, interpreter.contract.caller.into_word()); } -pub fn codesize(interpreter: &mut Interpreter, _host: &mut H) { +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 H) { +pub fn codecopy(interpreter: &mut Interpreter<'_>, _host: &mut H) { pop!(interpreter, memory_offset, code_offset, len); let len = as_usize_or_fail!(interpreter, len); gas_or_fail!(interpreter, gas::verylowcopy_cost(len as u64)); @@ -54,7 +54,7 @@ pub fn codecopy(interpreter: &mut Interpreter, _host: &mut H) { ); } -pub fn calldataload(interpreter: &mut Interpreter, _host: &mut H) { +pub fn calldataload(interpreter: &mut Interpreter<'_>, _host: &mut H) { gas!(interpreter, gas::VERYLOW); pop!(interpreter, index); let index = as_usize_saturated!(index); @@ -70,17 +70,17 @@ pub fn calldataload(interpreter: &mut Interpreter, _host: &mut H) { push_b256!(interpreter, load); } -pub fn calldatasize(interpreter: &mut Interpreter, _host: &mut H) { +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 H) { +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 H) { +pub fn calldatacopy(interpreter: &mut Interpreter<'_>, _host: &mut H) { pop!(interpreter, memory_offset, data_offset, len); let len = as_usize_or_fail!(interpreter, len); gas_or_fail!(interpreter, gas::verylowcopy_cost(len as u64)); @@ -101,7 +101,7 @@ pub fn calldatacopy(interpreter: &mut Interpreter, _host: &mut H) { } /// EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY -pub fn returndatasize(interpreter: &mut Interpreter, _host: &mut H) { +pub fn returndatasize(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, BYZANTIUM); gas!(interpreter, gas::BASE); push!( @@ -111,7 +111,7 @@ pub fn returndatasize(interpreter: &mut Interpreter, _host: } /// EIP-211: New opcodes: RETURNDATASIZE and RETURNDATACOPY -pub fn returndatacopy(interpreter: &mut Interpreter, _host: &mut H) { +pub fn returndatacopy(interpreter: &mut Interpreter<'_>, _host: &mut H) { check!(interpreter, BYZANTIUM); pop!(interpreter, memory_offset, offset, len); let len = as_usize_or_fail!(interpreter, len); @@ -132,7 +132,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())); } diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index b64b111a4d..57495391ce 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -3,13 +3,13 @@ mod contract; mod shared_memory; mod stack; -use crate::primitives::{Bytes, Spec}; -use crate::{alloc::boxed::Box, opcode::eval, Gas, Host, InstructionResult}; - pub use analysis::BytecodeLocked; pub use contract::Contract; pub use shared_memory::{next_multiple_of_32, SharedMemory}; -pub use stack::Stack; +pub use stack::{Stack, STACK_LIMIT}; + +use crate::primitives::{Bytes, Spec}; +use crate::{alloc::boxed::Box, opcode::eval, Gas, Host, InstructionResult}; /// EIP-170: Contract code size limit /// diff --git a/crates/interpreter/src/interpreter/shared_memory.rs b/crates/interpreter/src/interpreter/shared_memory.rs index 2b3fbafe51..389194e797 100644 --- a/crates/interpreter/src/interpreter/shared_memory.rs +++ b/crates/interpreter/src/interpreter/shared_memory.rs @@ -11,6 +11,8 @@ use core::{ /// a `Vec` for internal representation. /// A [SharedMemory] instance should always be obtained using /// the `new` static method to ensure memory safety. +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SharedMemory { /// Shared buffer data: Vec, diff --git a/crates/interpreter/src/interpreter/stack.rs b/crates/interpreter/src/interpreter/stack.rs index d79f6c9e1c..8848181f00 100644 --- a/crates/interpreter/src/interpreter/stack.rs +++ b/crates/interpreter/src/interpreter/stack.rs @@ -9,7 +9,7 @@ use core::fmt; pub const STACK_LIMIT: usize = 1024; /// EVM stack. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Stack { data: Vec, diff --git a/crates/interpreter/src/lib.rs b/crates/interpreter/src/lib.rs index 96a8341af6..5ec60baa55 100644 --- a/crates/interpreter/src/lib.rs +++ b/crates/interpreter/src/lib.rs @@ -1,9 +1,10 @@ //! # revm-interpreter //! //! REVM Interpreter. - +#![warn(unreachable_pub, unused_crate_dependencies)] +#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] -#![warn(unused_crate_dependencies)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] extern crate alloc; @@ -26,8 +27,8 @@ pub use inner_models::*; pub use instruction_result::*; pub use instructions::{opcode, Instruction, OpCode, OPCODE_JUMPMAP}; pub use interpreter::{ - analysis, BytecodeLocked, Contract, Interpreter, SharedMemory, Stack, MAX_CODE_SIZE, - MAX_INITCODE_SIZE, + analysis, next_multiple_of_32, BytecodeLocked, Contract, Interpreter, SharedMemory, Stack, + MAX_CODE_SIZE, MAX_INITCODE_SIZE, STACK_LIMIT, }; #[doc(hidden)] pub use revm_primitives as primitives; diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 4fdef0595b..6ab2385f3a 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -1,9 +1,10 @@ //! # revm-precompile //! //! Implementations of EVM precompiled contracts. - -#![cfg_attr(not(feature = "std"), no_std)] #![warn(unused_crate_dependencies)] +#![deny(unused_must_use, rust_2018_idioms)] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #[macro_use] extern crate alloc; @@ -34,14 +35,14 @@ pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 { (len as u64 + 32 - 1) / 32 * word + base } -#[derive(Debug)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct PrecompileOutput { pub cost: u64, pub output: Vec, pub logs: Vec, } -#[derive(Debug, Default)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct Log { pub address: Address, pub topics: Vec, @@ -57,8 +58,7 @@ impl PrecompileOutput { } } } - -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Precompiles { pub fun: HashMap, } @@ -69,7 +69,7 @@ impl Default for Precompiles { } } -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq, Hash)] pub enum Precompile { Standard(StandardPrecompileFn), Env(EnvPrecompileFn), @@ -84,6 +84,7 @@ impl fmt::Debug for Precompile { } } +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct PrecompileAddress(Address, Precompile); impl From for (Address, Precompile) { @@ -92,7 +93,7 @@ impl From for (Address, Precompile) { } } -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)] pub enum SpecId { HOMESTEAD, BYZANTIUM, diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index d09fffe3ca..c535df8c34 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -5,7 +5,7 @@ use bitvec::vec::BitVec; use core::fmt::Debug; /// A map of valid `jump` destinations. -#[derive(Clone, Eq, PartialEq, Default)] +#[derive(Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct JumpMap(pub Arc>); @@ -38,7 +38,7 @@ impl JumpMap { } /// State of the [`Bytecode`] analysis. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum BytecodeState { /// No analysis has been performed. @@ -49,7 +49,7 @@ pub enum BytecodeState { Analysed { len: usize, jump_map: JumpMap }, } -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Bytecode { pub bytecode: Bytes, diff --git a/crates/primitives/src/db.rs b/crates/primitives/src/db.rs index b0c667306c..fc7906ffce 100644 --- a/crates/primitives/src/db.rs +++ b/crates/primitives/src/db.rs @@ -60,6 +60,7 @@ pub trait DatabaseRef { } /// Wraps a [`DatabaseRef`] to provide a [`Database`] implementation. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct WrapDatabaseRef(pub T); impl Database for WrapDatabaseRef { diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index e81dddc285..e93c571630 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -6,7 +6,7 @@ use crate::{ use core::cmp::{min, Ordering}; /// EVM environment configuration. -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Env { /// Configuration of the EVM itself. @@ -238,7 +238,7 @@ impl Env { } /// EVM configuration. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[non_exhaustive] pub struct CfgEnv { @@ -385,7 +385,7 @@ impl Default for CfgEnv { } /// The block environment. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BlockEnv { /// The number of ancestor blocks of this block (block height). @@ -472,7 +472,7 @@ impl Default for BlockEnv { } /// The transaction environment. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TxEnv { /// Caller aka Author aka transaction signer. @@ -567,7 +567,7 @@ impl Default for TxEnv { /// Incorporated as part of the Cancun upgrade via [EIP-4844]. /// /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BlobExcessGasAndPrice { /// The excess blob gas of the block. @@ -589,7 +589,7 @@ impl BlobExcessGasAndPrice { /// Additional [TxEnv] fields for optimism. #[cfg(feature = "optimism")] -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct OptimismFields { /// The source hash is used to make sure that deposit transactions do @@ -622,7 +622,7 @@ pub struct OptimismFields { } /// Transaction destination. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum TransactTo { /// Simple call to an address. @@ -664,7 +664,7 @@ impl TransactTo { } /// Create scheme. -#[derive(Clone, Copy, Eq, PartialEq, Debug)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum CreateScheme { /// Legacy create scheme of `CREATE`. @@ -677,7 +677,7 @@ pub enum CreateScheme { } /// What bytecode analysis to perform. -#[derive(Clone, Default, Debug, Eq, PartialEq)] +#[derive(Clone, Default, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum AnalysisKind { /// Do not perform bytecode analysis. diff --git a/crates/primitives/src/kzg/env_settings.rs b/crates/primitives/src/kzg/env_settings.rs index ecf760c0a2..9b41f02908 100644 --- a/crates/primitives/src/kzg/env_settings.rs +++ b/crates/primitives/src/kzg/env_settings.rs @@ -3,11 +3,12 @@ use super::{ KzgSettings, }; use alloc::{boxed::Box, sync::Arc}; +use core::hash::{Hash, Hasher}; use once_cell::race::OnceBox; /// KZG Settings that allow us to specify a custom trusted setup. /// or use hardcoded default settings. -#[derive(Debug, Clone, Default, Eq, PartialEq)] +#[derive(Debug, Clone, Default, Eq)] pub enum EnvKzgSettings { /// Default mainnet trusted setup #[default] @@ -16,6 +17,27 @@ pub enum EnvKzgSettings { Custom(Arc), } +// Implement PartialEq and Hash manually because `c_kzg::KzgSettings` does not implement them +impl PartialEq for EnvKzgSettings { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::Default, Self::Default) => true, + (Self::Custom(a), Self::Custom(b)) => Arc::ptr_eq(a, b), + _ => false, + } + } +} + +impl Hash for EnvKzgSettings { + fn hash(&self, state: &mut H) { + core::mem::discriminant(self).hash(state); + match self { + Self::Default => {} + Self::Custom(settings) => Arc::as_ptr(settings).hash(state), + } + } +} + impl EnvKzgSettings { /// Return set KZG settings. /// diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 1da9c0ba9f..d84225bbbc 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -1,9 +1,10 @@ //! # revm-primitives //! //! EVM primitive types. - +#![warn(unreachable_pub, unused_crate_dependencies)] +#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] -#![warn(unused_crate_dependencies)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] extern crate alloc; diff --git a/crates/primitives/src/log.rs b/crates/primitives/src/log.rs index 578f0b243f..d359fbe3af 100644 --- a/crates/primitives/src/log.rs +++ b/crates/primitives/src/log.rs @@ -2,7 +2,7 @@ use crate::{Address, Bytes, B256}; use alloc::vec::Vec; use alloy_rlp::{RlpDecodable, RlpEncodable}; -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpDecodable, RlpEncodable)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, RlpDecodable, RlpEncodable)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Log { pub address: Address, diff --git a/crates/primitives/src/precompile.rs b/crates/primitives/src/precompile.rs index 0a1733ea88..633de0077a 100644 --- a/crates/primitives/src/precompile.rs +++ b/crates/primitives/src/precompile.rs @@ -10,7 +10,7 @@ pub type PrecompileResult = Result<(u64, Vec), PrecompileError>; pub type StandardPrecompileFn = fn(&[u8], u64) -> PrecompileResult; pub type EnvPrecompileFn = fn(&[u8], u64, env: &Env) -> PrecompileResult; -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum PrecompileError { /// out of gas is the main error. Other are just here for completeness OutOfGas, @@ -38,7 +38,7 @@ pub enum PrecompileError { impl std::error::Error for PrecompileError {} impl fmt::Display for PrecompileError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { PrecompileError::OutOfGas => write!(f, "out of gas"), PrecompileError::Blake2WrongLength => write!(f, "wrong input length for blake2"), diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 9e237b8386..ccdb48a7f7 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -18,7 +18,7 @@ pub struct ResultAndState { } /// Result of a transaction execution. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ExecutionResult { /// Returned successfully @@ -95,7 +95,7 @@ impl ExecutionResult { } /// Output of a transaction execution. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Output { Call(Bytes), @@ -120,8 +120,8 @@ impl Output { } } -/// EVM error. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +/// Main EVM error. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum EVMError { /// Transaction validation error. @@ -152,7 +152,7 @@ impl From for EVMError { } /// Transaction validation error. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum InvalidTransaction { /// When using the EIP-1559 fee model introduced in the London upgrade, transactions specify two primary fee fields: @@ -221,7 +221,7 @@ pub enum InvalidTransaction { impl std::error::Error for InvalidTransaction {} impl fmt::Display for InvalidTransaction { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { InvalidTransaction::PriorityFeeGreaterThanMaxFee => { write!(f, "Priority fee is greater than max fee") @@ -291,7 +291,7 @@ impl From for EVMError { } /// Errors related to misconfiguration of a [`BlockEnv`]. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum InvalidHeader { /// `prevrandao` is not set for Merge and above. @@ -304,7 +304,7 @@ pub enum InvalidHeader { impl std::error::Error for InvalidHeader {} impl fmt::Display for InvalidHeader { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { InvalidHeader::PrevrandaoNotSet => write!(f, "Prevrandao not set"), InvalidHeader::ExcessBlobGasNotSet => write!(f, "Excess blob gas not set"), @@ -313,7 +313,7 @@ impl fmt::Display for InvalidHeader { } /// Reason a transaction successfully completed. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Eval { Stop, @@ -323,7 +323,7 @@ pub enum Eval { /// Indicates that the EVM has experienced an exceptional halt. This causes execution to /// immediately end with all gas being consumed. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Halt { OutOfGas(OutOfGasError), @@ -352,7 +352,7 @@ pub enum Halt { CallTooDeep, } -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum OutOfGasError { // Basic OOG error diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index 741271535b..61c2d7f6d7 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -6,7 +6,7 @@ pub use SpecId::*; /// /// Information was obtained from: #[repr(u8)] -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, enumn::N)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum SpecId { FRONTIER = 0, // Frontier 0 @@ -117,6 +117,7 @@ pub trait Spec: Sized { macro_rules! spec { ($spec_id:ident, $spec_name:ident) => { + #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $spec_name; impl Spec for $spec_name { diff --git a/crates/primitives/src/state.rs b/crates/primitives/src/state.rs index f3dc3f2238..79c2abcfc4 100644 --- a/crates/primitives/src/state.rs +++ b/crates/primitives/src/state.rs @@ -1,5 +1,6 @@ use crate::{Address, Bytecode, B256, KECCAK_EMPTY, U256}; use bitflags::bitflags; +use core::hash::{Hash, Hasher}; use hashbrown::HashMap; /// EVM State is a mapping from addresses to accounts. @@ -11,7 +12,7 @@ pub type TransientStorage = HashMap<(Address, U256), U256>; /// An account's Storage is a mapping from 256-bit integer keys to [StorageSlot]s. pub type Storage = HashMap; -#[derive(Debug, Clone, Eq, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Account { /// Balance, nonce, and code. @@ -128,7 +129,7 @@ impl From for Account { } } -#[derive(Debug, Clone, Default, Eq, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct StorageSlot { pub previous_or_original_value: U256, @@ -199,6 +200,14 @@ impl PartialEq for AccountInfo { } } +impl Hash for AccountInfo { + fn hash(&self, state: &mut H) { + self.balance.hash(state); + self.nonce.hash(state); + self.code_hash.hash(state); + } +} + impl AccountInfo { pub fn new(balance: U256, nonce: u64, code_hash: B256, code: Bytecode) -> Self { Self { diff --git a/crates/revm/src/db/ethersdb.rs b/crates/revm/src/db/ethersdb.rs index 3a755ec945..48e4b0836b 100644 --- a/crates/revm/src/db/ethersdb.rs +++ b/crates/revm/src/db/ethersdb.rs @@ -5,6 +5,7 @@ use ethers_providers::Middleware; use std::sync::Arc; use tokio::runtime::{Handle, Runtime}; +#[derive(Debug)] pub struct EthersDB { client: Arc, runtime: Option, @@ -153,7 +154,7 @@ mod tests { .unwrap(); let client = Arc::new(client); - let mut ethersdb = EthersDB::new( + let ethersdb = EthersDB::new( Arc::clone(&client), // public infura mainnet Some(BlockId::from(16148323)), ) @@ -179,7 +180,7 @@ mod tests { .unwrap(); let client = Arc::new(client); - let mut ethersdb = EthersDB::new( + let ethersdb = EthersDB::new( Arc::clone(&client), // public infura mainnet Some(BlockId::from(16148323)), ) @@ -210,7 +211,7 @@ mod tests { .unwrap(); let client = Arc::new(client); - let mut ethersdb = EthersDB::new( + let ethersdb = EthersDB::new( Arc::clone(&client), // public infura mainnet None, ) diff --git a/crates/revm/src/db/in_memory_db.rs b/crates/revm/src/db/in_memory_db.rs index d395d2aa44..ce0644eaf6 100644 --- a/crates/revm/src/db/in_memory_db.rs +++ b/crates/revm/src/db/in_memory_db.rs @@ -329,7 +329,7 @@ impl From for DbAccount { } } -#[derive(Debug, Clone, Default, Eq, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] pub enum AccountState { /// Before Spurious Dragon hardfork there was a difference between empty and not existing. /// And we are flagging it here. diff --git a/crates/revm/src/db/states/account_status.rs b/crates/revm/src/db/states/account_status.rs index f75ae3a61e..5003ecaf19 100644 --- a/crates/revm/src/db/states/account_status.rs +++ b/crates/revm/src/db/states/account_status.rs @@ -1,7 +1,7 @@ /// After account get loaded from database it can be in a lot of different states /// while we execute multiple transaction and even blocks over account that is in memory. /// This structure models all possible states that account can be in. -#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)] pub enum AccountStatus { #[default] LoadedNotExisting, diff --git a/crates/revm/src/db/states/bundle_state.rs b/crates/revm/src/db/states/bundle_state.rs index b2f9873e42..1cab208038 100644 --- a/crates/revm/src/db/states/bundle_state.rs +++ b/crates/revm/src/db/states/bundle_state.rs @@ -30,6 +30,7 @@ pub struct BundleBuilder { } /// Option for [`BundleState`] when converting it to the plain state. +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum OriginalValuesKnown { /// Check changed with original values that [BundleState] has /// If we dont expect parent blocks to be committed or unwinded from database diff --git a/crates/revm/src/db/states/cache.rs b/crates/revm/src/db/states/cache.rs index 43e0da66c0..51168e434a 100644 --- a/crates/revm/src/db/states/cache.rs +++ b/crates/revm/src/db/states/cache.rs @@ -12,7 +12,7 @@ use revm_interpreter::primitives::{ /// It loads all accounts from database and applies revm output to it. /// /// It generates transitions that is used to build BundleState. -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct CacheState { /// Block state account with account state pub accounts: HashMap, diff --git a/crates/revm/src/db/states/cache_account.rs b/crates/revm/src/db/states/cache_account.rs index c9b29b803a..c6769eba99 100644 --- a/crates/revm/src/db/states/cache_account.rs +++ b/crates/revm/src/db/states/cache_account.rs @@ -7,7 +7,7 @@ use revm_precompile::HashMap; /// Cache account contains plain state that gets updated /// at every transaction when evm output is applied to CacheState. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct CacheAccount { pub account: Option, pub status: AccountStatus, diff --git a/crates/revm/src/db/states/plain_account.rs b/crates/revm/src/db/states/plain_account.rs index 716d6540b8..f6cb76618c 100644 --- a/crates/revm/src/db/states/plain_account.rs +++ b/crates/revm/src/db/states/plain_account.rs @@ -1,7 +1,7 @@ use revm_interpreter::primitives::{AccountInfo, HashMap, StorageSlot, U256}; -/// TODO rename this to BundleAccount. As for the block level we have original state. -#[derive(Clone, Debug, Default)] +// TODO rename this to BundleAccount. As for the block level we have original state. +#[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct PlainAccount { pub info: AccountInfo, pub storage: PlainStorage, diff --git a/crates/revm/src/db/states/reverts.rs b/crates/revm/src/db/states/reverts.rs index 3166e1a1f6..513101ded2 100644 --- a/crates/revm/src/db/states/reverts.rs +++ b/crates/revm/src/db/states/reverts.rs @@ -181,7 +181,7 @@ impl AccountRevert { /// Depending on previous state of account info this /// will tell us what to do on revert. -#[derive(Clone, Default, Debug, PartialEq, Eq)] +#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)] pub enum AccountInfoRevert { #[default] /// Nothing changed @@ -199,7 +199,7 @@ pub enum AccountInfoRevert { /// /// Note: It is completely different state if Storage is Zero or Some or if Storage was /// Destroyed. Because if it is destroyed, previous values can be found in database or it can be zero. -#[derive(Clone, Debug, Copy, PartialEq, Eq)] +#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)] pub enum RevertToSlot { Some(U256), Destroyed, diff --git a/crates/revm/src/db/states/state.rs b/crates/revm/src/db/states/state.rs index fe74d373cc..8f7ccdc3b6 100644 --- a/crates/revm/src/db/states/state.rs +++ b/crates/revm/src/db/states/state.rs @@ -25,6 +25,7 @@ pub type StateDBBox<'a, E> = State>; /// /// State clear flag is set inside CacheState and by default it is enabled. /// If you want to disable it use `set_state_clear_flag` function. +#[derive(Debug)] pub struct State { /// Cached state contains both changed from evm execution and cached/loaded account/storages /// from database. This allows us to have only one layer of cache where we can fetch data. @@ -34,7 +35,7 @@ pub struct State { /// return not existing account and storage. /// /// Note: It is marked as Send so database can be shared between threads. - pub database: DB, //Box + Send + 'a>, + pub database: DB, /// Block state, it aggregates transactions transitions into one state. /// /// Build reverts and state that gets applied to the state. diff --git a/crates/revm/src/db/states/state_builder.rs b/crates/revm/src/db/states/state_builder.rs index 79cfdc20f3..07978a518b 100644 --- a/crates/revm/src/db/states/state_builder.rs +++ b/crates/revm/src/db/states/state_builder.rs @@ -7,6 +7,7 @@ use revm_interpreter::primitives::{ }; /// Allows building of State and initializing it with different options. +#[derive(Clone, Debug, PartialEq, Eq)] pub struct StateBuilder { /// Database that we use to fetch data from. database: DB, diff --git a/crates/revm/src/db/states/transition_account.rs b/crates/revm/src/db/states/transition_account.rs index c8fea5eb1f..1eb4baa01a 100644 --- a/crates/revm/src/db/states/transition_account.rs +++ b/crates/revm/src/db/states/transition_account.rs @@ -7,7 +7,7 @@ use revm_interpreter::primitives::{hash_map, AccountInfo, Bytecode, B256}; /// /// It is used when block state gets merged to bundle state to /// create needed Reverts. -#[derive(Clone, Debug, Eq, PartialEq, Default)] +#[derive(Clone, Debug, PartialEq, Eq, Default)] pub struct TransitionAccount { pub info: Option, pub status: AccountStatus, diff --git a/crates/revm/src/db/states/transition_state.rs b/crates/revm/src/db/states/transition_state.rs index 802a29c1ee..269492405e 100644 --- a/crates/revm/src/db/states/transition_state.rs +++ b/crates/revm/src/db/states/transition_state.rs @@ -2,7 +2,7 @@ use super::TransitionAccount; use alloc::vec::Vec; use revm_interpreter::primitives::{hash_map::Entry, Address, HashMap}; -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct TransitionState { /// Block state account with account state pub transitions: HashMap, diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index 5c98d142bd..b67c1c8b8a 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -38,7 +38,7 @@ use revm_precompile::Precompiles; /// assert!(evm.db.is_none()); /// ``` /// -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct EVM { pub env: Env, pub db: Option, diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index dc15c98265..e3aa4a15c2 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -12,6 +12,7 @@ use crate::primitives::{ use crate::{db::Database, journaled_state::JournaledState, precompile, Inspector}; use alloc::boxed::Box; use alloc::vec::Vec; +use core::fmt; use core::marker::PhantomData; use revm_interpreter::gas::initial_tx_gas; use revm_interpreter::{SharedMemory, MAX_CODE_SIZE}; @@ -23,6 +24,7 @@ use crate::optimism; /// EVM call stack limit. pub const CALL_STACK_LIMIT: u64 = 1024; +#[derive(Debug)] pub struct EVMData<'a, DB: Database> { pub env: &'a mut Env, pub journaled_state: JournaledState, @@ -41,6 +43,19 @@ pub struct EVMImpl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> { _phantomdata: PhantomData, } +impl fmt::Debug for EVMImpl<'_, GSPEC, DB, INSPECT> +where + GSPEC: Spec, + DB: Database + fmt::Debug, + DB::Error: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("EVMImpl") + .field("data", &self.data) + .finish_non_exhaustive() + } +} + struct PreparedCreate { gas: Gas, created_address: Address, @@ -845,11 +860,15 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, impl<'a, GSPEC: Spec, DB: Database + 'a, const INSPECT: bool> Host for EVMImpl<'a, GSPEC, DB, INSPECT> { - fn step(&mut self, interp: &mut Interpreter) -> InstructionResult { + fn step(&mut self, interp: &mut Interpreter<'_>) -> InstructionResult { self.inspector.step(interp, &mut self.data) } - fn step_end(&mut self, interp: &mut Interpreter, ret: InstructionResult) -> InstructionResult { + fn step_end( + &mut self, + interp: &mut Interpreter<'_>, + ret: InstructionResult, + ) -> InstructionResult { self.inspector.step_end(interp, &mut self.data, ret) } diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index 9a5e2f5b2f..819cc49dd4 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -25,6 +25,7 @@ type CalculateGasRefundHandle = fn(&Env, &Gas) -> u64; /// Handler acts as a proxy and allow to define different behavior for different /// sections of the code. This allows nice integration of different chains or /// to disable some mainnet behavior. +#[derive(Debug)] pub struct Handler { // Uses env, call resul and returned gas from the call to determine the gas // that is returned from transaction execution.. diff --git a/crates/revm/src/inspector.rs b/crates/revm/src/inspector.rs index f66cbfcb60..7868da2e5a 100644 --- a/crates/revm/src/inspector.rs +++ b/crates/revm/src/inspector.rs @@ -30,7 +30,7 @@ pub trait Inspector { #[inline] fn initialize_interp( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, ) -> InstructionResult { let _ = interp; @@ -47,7 +47,11 @@ pub trait Inspector { /// /// To get the current opcode, use `interp.current_opcode()`. #[inline] - fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult { + fn step( + &mut self, + interp: &mut Interpreter<'_>, + data: &mut EVMData<'_, DB>, + ) -> InstructionResult { let _ = interp; let _ = data; InstructionResult::Continue @@ -74,7 +78,7 @@ pub trait Inspector { #[inline] fn step_end( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, eval: InstructionResult, ) -> InstructionResult { diff --git a/crates/revm/src/inspector/customprinter.rs b/crates/revm/src/inspector/customprinter.rs index f150650aca..f47d80f1d8 100644 --- a/crates/revm/src/inspector/customprinter.rs +++ b/crates/revm/src/inspector/customprinter.rs @@ -1,3 +1,6 @@ +//! Custom print inspector, it has step level information of execution. +//! It is a great tool if some debugging is needed. + use crate::interpreter::{opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter}; use crate::primitives::{Address, Bytes, U256}; use crate::{inspectors::GasInspector, Database, EVMData, Inspector}; @@ -5,7 +8,7 @@ use crate::{inspectors::GasInspector, Database, EVMData, Inspector}; /// Custom print [Inspector], it has step level information of execution. /// /// It is a great tool if some debugging is needed. -#[derive(Clone, Default)] +#[derive(Clone, Debug, Default)] pub struct CustomPrintTracer { gas_inspector: GasInspector, } @@ -13,7 +16,7 @@ pub struct CustomPrintTracer { impl Inspector for CustomPrintTracer { fn initialize_interp( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, ) -> InstructionResult { self.gas_inspector.initialize_interp(interp, data); @@ -22,7 +25,11 @@ impl Inspector for CustomPrintTracer { // get opcode by calling `interp.contract.opcode(interp.program_counter())`. // all other information can be obtained from interp. - fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult { + fn step( + &mut self, + interp: &mut Interpreter<'_>, + data: &mut EVMData<'_, DB>, + ) -> InstructionResult { let opcode = interp.current_opcode(); let opcode_str = opcode::OPCODE_JUMPMAP[opcode as usize]; @@ -49,7 +56,7 @@ impl Inspector for CustomPrintTracer { fn step_end( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, eval: InstructionResult, ) -> InstructionResult { diff --git a/crates/revm/src/inspector/eip3155.rs b/crates/revm/src/inspector/eip3155.rs index fb6ead5e97..b7a635b62f 100644 --- a/crates/revm/src/inspector/eip3155.rs +++ b/crates/revm/src/inspector/eip3155.rs @@ -48,7 +48,7 @@ impl TracerEip3155 { impl Inspector for TracerEip3155 { fn initialize_interp( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, ) -> InstructionResult { self.gas_inspector.initialize_interp(interp, data); @@ -57,7 +57,11 @@ impl Inspector for TracerEip3155 { // get opcode by calling `interp.contract.opcode(interp.program_counter())`. // all other information can be obtained from interp. - fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult { + fn step( + &mut self, + interp: &mut Interpreter<'_>, + data: &mut EVMData<'_, DB>, + ) -> InstructionResult { self.gas_inspector.step(interp, data); self.stack = interp.stack.clone(); self.pc = interp.program_counter(); @@ -69,7 +73,7 @@ impl Inspector for TracerEip3155 { fn step_end( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, eval: InstructionResult, ) -> InstructionResult { diff --git a/crates/revm/src/inspector/gas.rs b/crates/revm/src/inspector/gas.rs index 22639a3edc..ef6e345b2c 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/revm/src/inspector/gas.rs @@ -26,7 +26,7 @@ impl Inspector for GasInspector { #[cfg(not(feature = "no_gas_measuring"))] fn initialize_interp( &mut self, - interp: &mut crate::interpreter::Interpreter, + interp: &mut crate::interpreter::Interpreter<'_>, _data: &mut EVMData<'_, DB>, ) -> InstructionResult { self.gas_remaining = interp.gas.limit(); @@ -36,7 +36,7 @@ impl Inspector for GasInspector { #[cfg(not(feature = "no_gas_measuring"))] fn step_end( &mut self, - interp: &mut crate::interpreter::Interpreter, + interp: &mut crate::interpreter::Interpreter<'_>, _data: &mut EVMData<'_, DB>, _eval: InstructionResult, ) -> InstructionResult { @@ -91,7 +91,7 @@ mod tests { impl Inspector for StackInspector { fn initialize_interp( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, ) -> InstructionResult { self.gas_inspector.initialize_interp(interp, data); @@ -100,7 +100,7 @@ mod tests { fn step( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, ) -> InstructionResult { self.pc = interp.program_counter(); @@ -120,7 +120,7 @@ mod tests { fn step_end( &mut self, - interp: &mut Interpreter, + interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>, eval: InstructionResult, ) -> InstructionResult { diff --git a/crates/revm/src/journaled_state.rs b/crates/revm/src/journaled_state.rs index 55e9b4b9dc..c55369ca2b 100644 --- a/crates/revm/src/journaled_state.rs +++ b/crates/revm/src/journaled_state.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use core::mem; use revm_interpreter::primitives::SpecId; -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct JournaledState { /// Current state. @@ -712,7 +712,7 @@ impl JournaledState { } } -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum JournalEntry { /// Used to mark account that is warm inside EVM in regards to EIP-2929 AccessList. @@ -775,6 +775,7 @@ pub enum JournalEntry { } /// SubRoutine checkpoint that will help us to go back from this +#[derive(Debug, Clone, PartialEq, Eq)] pub struct JournalCheckpoint { log_i: usize, journal_i: usize, diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 4101eb372e..6a5814e0f8 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -1,6 +1,8 @@ -#![cfg_attr(not(feature = "std"), no_std)] #![warn(unreachable_pub)] #![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![deny(unused_must_use, rust_2018_idioms)] +#![cfg_attr(not(feature = "std"), no_std)] #[macro_use] extern crate alloc;