Skip to content
Prev Previous commit
Next Next commit
chore: remove prelude
  • Loading branch information
DaniPopes committed Aug 25, 2023
commit 6eaa0e75ff9646af05cf7eafe1ea23a8b1b999cf
8 changes: 0 additions & 8 deletions crates/interpreter/src/instructions.rs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to eval to opcode.rs, and the return instructions to control

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,4 @@ pub mod opcode;
mod stack;
mod system;

mod prelude {
pub(super) use crate::primitives::{
Bytes, Spec, SpecId, SpecId::*, B160, B256, KECCAK_EMPTY, U256,
};
pub(super) use crate::{gas, Host, InstructionResult, Interpreter};
pub(super) use core::cmp::Ordering;
}

pub use opcode::{OpCode, OPCODE_JUMPMAP};
6 changes: 5 additions & 1 deletion crates/interpreter/src/instructions/arithmetic.rs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • avoid reassigning to 0 when already 0 in div and rem

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use super::i256::{i256_div, i256_mod};
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, U256},
Host, InstructionResult, Interpreter,
};

pub(super) fn wrapped_add(interpreter: &mut Interpreter, _host: &mut dyn Host) {
gas!(interpreter, gas::VERYLOW);
Expand Down
7 changes: 6 additions & 1 deletion crates/interpreter/src/instructions/bitwise.rs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • cmp opcodes are now branchless
  • byte indexes into the slice instead of performing shifts
  • sar uses U256::MAX instead of computing it at runtime

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use super::i256::{i256_cmp, i256_sign, two_compl, Sign};
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, U256},
Host, InstructionResult, Interpreter,
};
use core::cmp::Ordering;

pub(super) fn lt(interpreter: &mut Interpreter, _host: &mut dyn Host) {
gas!(interpreter, gas::VERYLOW);
Expand Down
6 changes: 5 additions & 1 deletion crates/interpreter/src/instructions/control.rs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • factored out the set up in common for return and revert

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, U256},
Host, InstructionResult, Interpreter,
};

pub(super) fn jump(interpreter: &mut Interpreter, _host: &mut dyn Host) {
gas!(interpreter, gas::MID);
Expand Down
8 changes: 3 additions & 5 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use super::prelude::*;
use crate::MAX_INITCODE_SIZE;
use crate::{
alloc::boxed::Box,
alloc::vec::Vec,
gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST},
interpreter::Interpreter,
primitives::{Bytes, Spec, SpecId::*, B160, B256, U256},
return_ok, return_revert, CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme,
Host, InstructionResult, Transfer,
Host, InstructionResult, Transfer, MAX_INITCODE_SIZE,
};
use alloc::{boxed::Box, vec::Vec};
use core::cmp::min;
use revm_primitives::BLOCK_HASH_HISTORY;

Expand Down
6 changes: 5 additions & 1 deletion crates/interpreter/src/instructions/host_env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, SpecId::*},
Host, InstructionResult, Interpreter,
};

// EIP-1344: ChainID opcode
pub(super) fn chainid<SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Host) {
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions/i256.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::prelude::*;
use crate::primitives::U256;
use core::cmp::Ordering;

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
Expand Down
6 changes: 5 additions & 1 deletion crates/interpreter/src/instructions/memory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, U256},
Host, InstructionResult, Interpreter,
};
use core::cmp::max;

pub(super) fn mload(interpreter: &mut Interpreter, _host: &mut dyn Host) {
Expand Down
7 changes: 6 additions & 1 deletion crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! EVM opcode definitions and utilities.

use super::{prelude::*, *};
use super::*;
use crate::{
gas,
primitives::{Spec, SpecId},
Host, Interpreter,
};
use core::fmt;

macro_rules! opcodes {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro declares all of:

  • const NAME: u8 = $value;
  • OPCODE_JUMPMAP[$value] = Some(stringify!($name));
  • eval dispatch

Left out gas, which is improved below.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was wondering if gas should be part of the opcode, but maybe not? it'd be nice if they were all declared in one place, but ig fine as-is?

Expand Down
6 changes: 5 additions & 1 deletion crates/interpreter/src/instructions/stack.rs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • changed stack methods return type from Option<IR> to Result<(), IR>

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, U256},
Host, InstructionResult, Interpreter,
};

pub(super) fn pop(interpreter: &mut Interpreter, _host: &mut dyn Host) {
gas!(interpreter, gas::BASE);
Expand Down
6 changes: 5 additions & 1 deletion crates/interpreter/src/instructions/system.rs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • use U256 and get_unchecked in calldataload

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::prelude::*;
use crate::{
gas,
primitives::{Spec, B256, KECCAK_EMPTY, U256},
Host, InstructionResult, Interpreter,
};

pub(super) fn keccak256(interpreter: &mut Interpreter, _host: &mut dyn Host) {
pop!(interpreter, from, len);
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/interpreter/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl BytecodeLocked {
if self.is_empty() {
KECCAK_EMPTY
} else {
keccak256(&self.original_bytecode_slice())
keccak256(self.original_bytecode_slice())
}
}

Expand Down