Skip to content

Commit 7a99f16

Browse files
DaniPopesmattsserakita
authored
feat: derive more traits (#745)
* feat: derive more traits * chore: add unreachable_pub lint * Update crates/revm/src/evm_impl.rs Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> * fmt * cleanup * rm memory * remove required Debug --------- Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: rakita <dragan0rakita@gmail.com>
1 parent 3605451 commit 7a99f16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+272
-191
lines changed

bins/revme/src/cli_env.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use revm::primitives::{Address, Bytes, Env, TransactTo, U256};
22
use structopt::StructOpt;
33

4-
#[derive(StructOpt, Clone, Debug)]
4+
#[derive(StructOpt, Clone, Debug, PartialEq, Eq)]
55
pub struct CliEnv {
66
#[structopt(flatten)]
77
block: CliEnvBlock,
@@ -51,7 +51,7 @@ impl From<CliEnv> for Env {
5151
}
5252
}
5353

54-
#[derive(StructOpt, Clone, Debug)]
54+
#[derive(StructOpt, Clone, Debug, PartialEq, Eq)]
5555
pub struct CliEnvBlock {
5656
#[structopt(long = "env.block.gas_limit")]
5757
pub block_gas_limit: Option<u64>,
@@ -71,7 +71,7 @@ pub struct CliEnvBlock {
7171
pub basefee: Option<u64>,
7272
}
7373

74-
#[derive(StructOpt, Clone, Debug)]
74+
#[derive(StructOpt, Clone, Debug, PartialEq, Eq)]
7575
pub struct CliEnvTx {
7676
/// Caller or Author or tx signer
7777
#[structopt(long = "env.tx.caller")]

bins/revme/src/statetest/merkle_trie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
sec_trie_root::<KeccakHasher, _, _, _>(input)
6060
}
6161

62-
#[derive(Default, Debug, Clone, PartialEq, Eq)]
62+
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
6363
pub struct KeccakHasher;
6464

6565
impl Hasher for KeccakHasher {

bins/revme/src/statetest/models/spec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use revm::primitives::SpecId;
22
use serde::Deserialize;
33

4-
#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Ord, Deserialize)]
4+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize, Hash)]
55
pub enum SpecName {
66
Frontier,
77
FrontierToHomesteadAt5,

crates/interpreter/src/gas.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use calc::*;
77
pub use constants::*;
88

99
/// Represents the state of gas during execution.
10-
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
10+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1111
pub struct Gas {
1212
/// The initial gas limit.
1313
limit: u64,

crates/interpreter/src/host.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ mod dummy;
1212
/// EVM context host.
1313
pub trait Host {
1414
/// Called before the interpreter executes an instruction.
15-
fn step(&mut self, interpreter: &mut Interpreter) -> InstructionResult;
15+
fn step(&mut self, interpreter: &mut Interpreter<'_>) -> InstructionResult;
1616

1717
/// Called after the interpreter executes an instruction.
1818
fn step_end(
1919
&mut self,
20-
interpreter: &mut Interpreter,
20+
interpreter: &mut Interpreter<'_>,
2121
ret: InstructionResult,
2222
) -> InstructionResult;
2323

crates/interpreter/src/host/dummy.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
use alloc::vec::Vec;
88

99
/// A dummy [Host] implementation.
10+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
1011
pub struct DummyHost {
1112
pub env: Env,
1213
pub storage: HashMap<U256, U256>,
@@ -20,9 +21,7 @@ impl DummyHost {
2021
pub fn new(env: Env) -> Self {
2122
Self {
2223
env,
23-
storage: HashMap::new(),
24-
transient_storage: Default::default(),
25-
log: Vec::new(),
24+
..Default::default()
2625
}
2726
}
2827

@@ -36,14 +35,14 @@ impl DummyHost {
3635

3736
impl Host for DummyHost {
3837
#[inline]
39-
fn step(&mut self, _interp: &mut Interpreter) -> InstructionResult {
38+
fn step(&mut self, _interp: &mut Interpreter<'_>) -> InstructionResult {
4039
InstructionResult::Continue
4140
}
4241

4342
#[inline]
4443
fn step_end(
4544
&mut self,
46-
_interp: &mut Interpreter,
45+
_interp: &mut Interpreter<'_>,
4746
_ret: InstructionResult,
4847
) -> InstructionResult {
4948
InstructionResult::Continue

crates/interpreter/src/inner_models.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub use crate::primitives::CreateScheme;
22
use crate::primitives::{Address, Bytes, B256, U256};
33

44
/// Inputs for a call.
5+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
56
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67
pub struct CallInputs {
78
/// The target of the call.
@@ -19,6 +20,7 @@ pub struct CallInputs {
1920
}
2021

2122
/// Inputs for a create call.
23+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2224
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2325
pub struct CreateInputs {
2426
/// Caller address of the EVM.
@@ -56,7 +58,7 @@ impl CreateInputs {
5658
}
5759

5860
/// Call schemes.
59-
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
61+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6062
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6163
pub enum CallScheme {
6264
/// `CALL`
@@ -70,7 +72,7 @@ pub enum CallScheme {
7072
}
7173

7274
/// Context of a runtime call.
73-
#[derive(Clone, Debug, PartialEq, Eq)]
75+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7476
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7577
pub struct CallContext {
7678
/// Execution address.
@@ -98,7 +100,7 @@ impl Default for CallContext {
98100
}
99101

100102
/// Transfer from source to target, with given value.
101-
#[derive(Clone, Debug)]
103+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
102104
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
103105
pub struct Transfer {
104106
/// The source address.
@@ -110,7 +112,7 @@ pub struct Transfer {
110112
}
111113

112114
/// Result of a call that resulted in a self destruct.
113-
#[derive(Default)]
115+
#[derive(Default, Clone, Debug, PartialEq, Eq, Hash)]
114116
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
115117
pub struct SelfDestructResult {
116118
pub had_value: bool,

crates/interpreter/src/instruction_result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::primitives::{Eval, Halt};
22

33
#[repr(u8)]
4-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
4+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
55
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
66
pub enum InstructionResult {
77
// success codes
@@ -89,7 +89,7 @@ impl InstructionResult {
8989
}
9090
}
9191

92-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
92+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
9393
pub enum SuccessOrHalt {
9494
Success(Eval),
9595
Revert,

crates/interpreter/src/instructions/arithmetic.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,67 @@ use crate::{
55
Host, InstructionResult, Interpreter,
66
};
77

8-
pub fn wrapped_add<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
8+
pub fn wrapped_add<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
99
gas!(interpreter, gas::VERYLOW);
1010
pop_top!(interpreter, op1, op2);
1111
*op2 = op1.wrapping_add(*op2);
1212
}
1313

14-
pub fn wrapping_mul<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
14+
pub fn wrapping_mul<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
1515
gas!(interpreter, gas::LOW);
1616
pop_top!(interpreter, op1, op2);
1717
*op2 = op1.wrapping_mul(*op2);
1818
}
1919

20-
pub fn wrapping_sub<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
20+
pub fn wrapping_sub<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
2121
gas!(interpreter, gas::VERYLOW);
2222
pop_top!(interpreter, op1, op2);
2323
*op2 = op1.wrapping_sub(*op2);
2424
}
2525

26-
pub fn div<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
26+
pub fn div<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
2727
gas!(interpreter, gas::LOW);
2828
pop_top!(interpreter, op1, op2);
2929
if *op2 != U256::ZERO {
3030
*op2 = op1.wrapping_div(*op2);
3131
}
3232
}
3333

34-
pub fn sdiv<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
34+
pub fn sdiv<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
3535
gas!(interpreter, gas::LOW);
3636
pop_top!(interpreter, op1, op2);
3737
*op2 = i256_div(op1, *op2);
3838
}
3939

40-
pub fn rem<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
40+
pub fn rem<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
4141
gas!(interpreter, gas::LOW);
4242
pop_top!(interpreter, op1, op2);
4343
if *op2 != U256::ZERO {
4444
*op2 = op1.wrapping_rem(*op2);
4545
}
4646
}
4747

48-
pub fn smod<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
48+
pub fn smod<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
4949
gas!(interpreter, gas::LOW);
5050
pop_top!(interpreter, op1, op2);
5151
if *op2 != U256::ZERO {
5252
*op2 = i256_mod(op1, *op2)
5353
}
5454
}
5555

56-
pub fn addmod<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
56+
pub fn addmod<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
5757
gas!(interpreter, gas::MID);
5858
pop_top!(interpreter, op1, op2, op3);
5959
*op3 = op1.add_mod(op2, *op3)
6060
}
6161

62-
pub fn mulmod<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
62+
pub fn mulmod<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
6363
gas!(interpreter, gas::MID);
6464
pop_top!(interpreter, op1, op2, op3);
6565
*op3 = op1.mul_mod(op2, *op3)
6666
}
6767

68-
pub fn exp<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut H) {
68+
pub fn exp<H: Host, SPEC: Spec>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
6969
pop_top!(interpreter, op1, op2);
7070
gas_or_fail!(interpreter, gas::exp_cost::<SPEC>(*op2));
7171
*op2 = op1.pow(*op2);
@@ -86,7 +86,7 @@ pub fn exp<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut H) {
8686
/// `y | !mask` where `|` is the bitwise `OR` and `!` is bitwise negation. Similarly, if
8787
/// `b == 0` then the yellow paper says the output should start with all zeros, then end with
8888
/// bits from `b`; this is equal to `y & mask` where `&` is bitwise `AND`.
89-
pub fn signextend<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
89+
pub fn signextend<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
9090
gas!(interpreter, gas::LOW);
9191
pop_top!(interpreter, op1, op2);
9292
if op1 < U256::from(32) {

crates/interpreter/src/instructions/bitwise.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,67 @@ use crate::{
66
};
77
use core::cmp::Ordering;
88

9-
pub fn lt<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
9+
pub fn lt<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
1010
gas!(interpreter, gas::VERYLOW);
1111
pop_top!(interpreter, op1, op2);
1212
*op2 = U256::from(op1 < *op2);
1313
}
1414

15-
pub fn gt<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
15+
pub fn gt<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
1616
gas!(interpreter, gas::VERYLOW);
1717
pop_top!(interpreter, op1, op2);
1818
*op2 = U256::from(op1 > *op2);
1919
}
2020

21-
pub fn slt<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
21+
pub fn slt<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
2222
gas!(interpreter, gas::VERYLOW);
2323
pop_top!(interpreter, op1, op2);
2424
*op2 = U256::from(i256_cmp(&op1, op2) == Ordering::Less);
2525
}
2626

27-
pub fn sgt<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
27+
pub fn sgt<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
2828
gas!(interpreter, gas::VERYLOW);
2929
pop_top!(interpreter, op1, op2);
3030
*op2 = U256::from(i256_cmp(&op1, op2) == Ordering::Greater);
3131
}
3232

33-
pub fn eq<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
33+
pub fn eq<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
3434
gas!(interpreter, gas::VERYLOW);
3535
pop_top!(interpreter, op1, op2);
3636
*op2 = U256::from(op1 == *op2);
3737
}
3838

39-
pub fn iszero<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
39+
pub fn iszero<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
4040
gas!(interpreter, gas::VERYLOW);
4141
pop_top!(interpreter, op1);
4242
*op1 = U256::from(*op1 == U256::ZERO);
4343
}
4444

45-
pub fn bitand<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
45+
pub fn bitand<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
4646
gas!(interpreter, gas::VERYLOW);
4747
pop_top!(interpreter, op1, op2);
4848
*op2 = op1 & *op2;
4949
}
5050

51-
pub fn bitor<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
51+
pub fn bitor<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
5252
gas!(interpreter, gas::VERYLOW);
5353
pop_top!(interpreter, op1, op2);
5454
*op2 = op1 | *op2;
5555
}
5656

57-
pub fn bitxor<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
57+
pub fn bitxor<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
5858
gas!(interpreter, gas::VERYLOW);
5959
pop_top!(interpreter, op1, op2);
6060
*op2 = op1 ^ *op2;
6161
}
6262

63-
pub fn not<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
63+
pub fn not<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
6464
gas!(interpreter, gas::VERYLOW);
6565
pop_top!(interpreter, op1);
6666
*op1 = !*op1;
6767
}
6868

69-
pub fn byte<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
69+
pub fn byte<H: Host>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
7070
gas!(interpreter, gas::VERYLOW);
7171
pop_top!(interpreter, op1, op2);
7272

@@ -80,23 +80,23 @@ pub fn byte<H: Host>(interpreter: &mut Interpreter, _host: &mut H) {
8080
}
8181

8282
/// EIP-145: Bitwise shifting instructions in EVM
83-
pub fn shl<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut H) {
83+
pub fn shl<H: Host, SPEC: Spec>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
8484
check!(interpreter, CONSTANTINOPLE);
8585
gas!(interpreter, gas::VERYLOW);
8686
pop_top!(interpreter, op1, op2);
8787
*op2 <<= as_usize_saturated!(op1);
8888
}
8989

9090
/// EIP-145: Bitwise shifting instructions in EVM
91-
pub fn shr<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut H) {
91+
pub fn shr<H: Host, SPEC: Spec>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
9292
check!(interpreter, CONSTANTINOPLE);
9393
gas!(interpreter, gas::VERYLOW);
9494
pop_top!(interpreter, op1, op2);
9595
*op2 >>= as_usize_saturated!(op1);
9696
}
9797

9898
/// EIP-145: Bitwise shifting instructions in EVM
99-
pub fn sar<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut H) {
99+
pub fn sar<H: Host, SPEC: Spec>(interpreter: &mut Interpreter<'_>, _host: &mut H) {
100100
check!(interpreter, CONSTANTINOPLE);
101101
gas!(interpreter, gas::VERYLOW);
102102
pop_top!(interpreter, op1, op2);

0 commit comments

Comments
 (0)