From 0dc261d3c561a3b0f6965a11b7d3f1eb24f45bd7 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 23 Jan 2023 01:54:18 +0100 Subject: [PATCH] chore: includes to libs --- Cargo.lock | 1 + bins/revm-test/src/bin/analysis.rs | 5 +- bins/revm-test/src/bin/snailtracer.rs | 5 +- bins/revme/src/cli_env.rs | 2 +- bins/revme/src/statetest/runner.rs | 6 +- crates/interpreter/src/gas.rs | 86 +++++++++++++++++++ crates/interpreter/src/gas/calc.rs | 6 +- crates/interpreter/src/host.rs | 4 +- crates/interpreter/src/host/dummy_host.rs | 4 +- .../src/instructions/arithmetic.rs | 6 +- .../interpreter/src/instructions/bitwise.rs | 5 +- .../interpreter/src/instructions/control.rs | 4 +- crates/interpreter/src/instructions/i256.rs | 4 +- crates/interpreter/src/instructions/memory.rs | 2 +- crates/interpreter/src/interpreter.rs | 4 +- crates/interpreter/src/interpreter/memory.rs | 2 +- crates/interpreter/src/lib.rs | 6 +- crates/precompiles/Cargo.toml | 1 + crates/precompiles/src/lib.rs | 22 ++--- crates/primitives/src/gas.rs | 85 ------------------ crates/primitives/src/lib.rs | 6 +- crates/primitives/src/models.rs | 1 - .../error.rs => primitives/src/precompile.rs} | 8 +- crates/revm/src/evm.rs | 4 +- crates/revm/src/evm_impl.rs | 33 +++---- crates/revm/src/inspector.rs | 6 +- crates/revm/src/inspector/customprinter.rs | 11 ++- crates/revm/src/inspector/gas.rs | 24 +++--- crates/revm/src/journaled_state.rs | 6 +- crates/revm/src/lib.rs | 2 - 30 files changed, 178 insertions(+), 183 deletions(-) delete mode 100644 crates/primitives/src/gas.rs delete mode 100644 crates/primitives/src/models.rs rename crates/{precompiles/src/error.rs => primitives/src/precompile.rs} (60%) diff --git a/Cargo.lock b/Cargo.lock index 5609ca537e..4a4ac2363a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1608,6 +1608,7 @@ dependencies = [ "k256", "num", "once_cell", + "revm-primitives", "ripemd", "ruint", "secp256k1", diff --git a/bins/revm-test/src/bin/analysis.rs b/bins/revm-test/src/bin/analysis.rs index 573f69f37a..e17aacbae9 100644 --- a/bins/revm-test/src/bin/analysis.rs +++ b/bins/revm-test/src/bin/analysis.rs @@ -2,10 +2,9 @@ use std::time::Instant; use bytes::Bytes; use revm::{ - analysis::to_analysed, db::BenchmarkDB, - primitives::{Bytecode, LondonSpec}, - TransactTo, + interpreter::analysis::to_analysed, + primitives::{Bytecode, LondonSpec, TransactTo}, }; extern crate alloc; diff --git a/bins/revm-test/src/bin/snailtracer.rs b/bins/revm-test/src/bin/snailtracer.rs index 8d9d595065..ff50ba33a0 100644 --- a/bins/revm-test/src/bin/snailtracer.rs +++ b/bins/revm-test/src/bin/snailtracer.rs @@ -2,10 +2,9 @@ use std::time::Duration; use bytes::Bytes; use revm::{ - analysis::to_analysed, db::BenchmarkDB, - primitives::{BerlinSpec, Bytecode}, - BytecodeLocked, DummyHost, TransactTo, + interpreter::{analysis::to_analysed, BytecodeLocked, DummyHost}, + primitives::{BerlinSpec, Bytecode, TransactTo}, }; extern crate alloc; diff --git a/bins/revme/src/cli_env.rs b/bins/revme/src/cli_env.rs index e481637fa9..dd48f11c8d 100644 --- a/bins/revme/src/cli_env.rs +++ b/bins/revme/src/cli_env.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use bytes::Bytes; -use revm::{Env, TransactTo, B160, U256}; +use revm::primitives::{Env, TransactTo, B160, U256}; use structopt::StructOpt; #[derive(StructOpt, Clone, Debug)] diff --git a/bins/revme/src/statetest/runner.rs b/bins/revme/src/statetest/runner.rs index 0a49d57cb9..8eb55c910f 100644 --- a/bins/revme/src/statetest/runner.rs +++ b/bins/revme/src/statetest/runner.rs @@ -8,8 +8,10 @@ use std::{ use indicatif::ProgressBar; use revm::{ - db::AccountState, inspectors::CustomPrintTracer, Bytecode, CreateScheme, Env, ExecutionResult, - SpecId, TransactTo, B160, B256, U256, + db::AccountState, + inspectors::CustomPrintTracer, + interpreter::CreateScheme, + primitives::{Bytecode, Env, ExecutionResult, SpecId, TransactTo, B160, B256, U256}, }; use std::sync::atomic::Ordering; use walkdir::{DirEntry, WalkDir}; diff --git a/crates/interpreter/src/gas.rs b/crates/interpreter/src/gas.rs index 8f40c54692..ad1d8c3721 100644 --- a/crates/interpreter/src/gas.rs +++ b/crates/interpreter/src/gas.rs @@ -3,3 +3,89 @@ mod constants; pub use calc::*; pub use constants::*; + +#[derive(Clone, Copy, Debug)] +pub struct Gas { + /// Gas Limit + limit: u64, + /// used+memory gas. + all_used_gas: u64, + /// Used gas without memory + used: u64, + /// Used gas for memory expansion + memory: u64, + /// Refunded gas. This gas is used only at the end of execution. + refunded: i64, +} +impl Gas { + pub fn new(limit: u64) -> Self { + Self { + limit, + used: 0, + memory: 0, + refunded: 0, + all_used_gas: 0, + } + } + + pub fn limit(&self) -> u64 { + self.limit + } + + pub fn memory(&self) -> u64 { + self.memory + } + + pub fn refunded(&self) -> i64 { + self.refunded + } + + pub fn spend(&self) -> u64 { + self.all_used_gas + } + + pub fn remaining(&self) -> u64 { + self.limit - self.all_used_gas + } + + pub fn erase_cost(&mut self, returned: u64) { + self.used -= returned; + self.all_used_gas -= returned; + } + + pub fn record_refund(&mut self, refund: i64) { + self.refunded += refund; + } + + /// Record an explicit cost. + #[inline(always)] + pub fn record_cost(&mut self, cost: u64) -> bool { + let (all_used_gas, overflow) = self.all_used_gas.overflowing_add(cost); + if overflow || self.limit < all_used_gas { + return false; + } + + self.used += cost; + self.all_used_gas = all_used_gas; + true + } + + /// used in memory_resize! macro to record gas used for memory expansion. + pub fn record_memory(&mut self, gas_memory: u64) -> bool { + if gas_memory > self.memory { + let (all_used_gas, overflow) = self.used.overflowing_add(gas_memory); + if overflow || self.limit < all_used_gas { + return false; + } + self.memory = gas_memory; + self.all_used_gas = all_used_gas; + } + true + } + + /// used in gas_refund! macro to record refund value. + /// Refund can be negative but self.refunded is always positive. + pub fn gas_refund(&mut self, refund: i64) { + self.refunded += refund; + } +} diff --git a/crates/interpreter/src/gas/calc.rs b/crates/interpreter/src/gas/calc.rs index d72a063cd1..08b0320d86 100644 --- a/crates/interpreter/src/gas/calc.rs +++ b/crates/interpreter/src/gas/calc.rs @@ -1,5 +1,9 @@ use super::constants::*; -use crate::{inner_models::SelfDestructResult, primitives::Spec, primitives::SpecId::*, U256}; +use crate::{ + inner_models::SelfDestructResult, + primitives::Spec, + primitives::{SpecId::*, U256}, +}; #[allow(clippy::collapsible_else_if)] pub fn sstore_refund(original: U256, current: U256, new: U256) -> i64 { diff --git a/crates/interpreter/src/host.rs b/crates/interpreter/src/host.rs index c32acef35a..9ee343d499 100644 --- a/crates/interpreter/src/host.rs +++ b/crates/interpreter/src/host.rs @@ -2,8 +2,8 @@ mod dummy_host; use crate::primitives::Bytecode; use crate::{ - primitives::{Bytes, Env, Gas, B160, B256, U256}, - CallInputs, CreateInputs, InstructionResult, Interpreter, SelfDestructResult, + primitives::{Bytes, Env, B160, B256, U256}, + CallInputs, CreateInputs, Gas, InstructionResult, Interpreter, SelfDestructResult, }; pub use dummy_host::DummyHost; diff --git a/crates/interpreter/src/host/dummy_host.rs b/crates/interpreter/src/host/dummy_host.rs index 5dac961129..0115f0ce8d 100644 --- a/crates/interpreter/src/host/dummy_host.rs +++ b/crates/interpreter/src/host/dummy_host.rs @@ -3,8 +3,8 @@ use ruint::aliases::U256; use crate::primitives::Bytecode; use crate::{ - primitives::{Env, Gas, Log, B160, B256, KECCAK_EMPTY}, - CallInputs, CreateInputs, Host, InstructionResult, Interpreter, SelfDestructResult, + primitives::{Env, Log, B160, B256, KECCAK_EMPTY}, + CallInputs, CreateInputs, Gas, Host, InstructionResult, Interpreter, SelfDestructResult, }; pub struct DummyHost { diff --git a/crates/interpreter/src/instructions/arithmetic.rs b/crates/interpreter/src/instructions/arithmetic.rs index 4b9574d221..379e9df1d5 100644 --- a/crates/interpreter/src/instructions/arithmetic.rs +++ b/crates/interpreter/src/instructions/arithmetic.rs @@ -1,5 +1,9 @@ use super::i256::{i256_div, i256_mod}; -use crate::{gas, primitives::Spec, Host, InstructionResult, Interpreter, U256}; +use crate::{ + gas, + primitives::{Spec, U256}, + Host, InstructionResult, Interpreter, +}; pub fn wrapped_add(interpreter: &mut Interpreter, _host: &mut dyn Host) { pop_top!(interpreter, op1, op2); diff --git a/crates/interpreter/src/instructions/bitwise.rs b/crates/interpreter/src/instructions/bitwise.rs index 4db1ba26ed..066e7b6b74 100644 --- a/crates/interpreter/src/instructions/bitwise.rs +++ b/crates/interpreter/src/instructions/bitwise.rs @@ -1,7 +1,8 @@ use super::i256::{i256_cmp, i256_sign, two_compl, Sign}; use crate::{ - primitives::Spec, primitives::SpecId::CONSTANTINOPLE, Host, InstructionResult, Interpreter, - U256, + primitives::SpecId::CONSTANTINOPLE, + primitives::{Spec, U256}, + Host, InstructionResult, Interpreter, }; use core::cmp::Ordering; use core::ops::{BitAnd, BitOr, BitXor}; diff --git a/crates/interpreter/src/instructions/control.rs b/crates/interpreter/src/instructions/control.rs index 13cc302d66..7de642f7bf 100644 --- a/crates/interpreter/src/instructions/control.rs +++ b/crates/interpreter/src/instructions/control.rs @@ -1,6 +1,6 @@ use crate::{ - gas, interpreter::Interpreter, primitives::Spec, primitives::SpecId::*, Host, - InstructionResult, U256, + gas, interpreter::Interpreter, primitives::Spec, primitives::SpecId::*, primitives::U256, Host, + InstructionResult, }; pub fn jump(interpreter: &mut Interpreter, _host: &mut dyn Host) { diff --git a/crates/interpreter/src/instructions/i256.rs b/crates/interpreter/src/instructions/i256.rs index 9b58185229..69b2ddab7b 100644 --- a/crates/interpreter/src/instructions/i256.rs +++ b/crates/interpreter/src/instructions/i256.rs @@ -1,4 +1,4 @@ -use crate::U256; +use crate::primitives::U256; use core::cmp::Ordering; use ruint::uint; @@ -135,7 +135,7 @@ pub fn i256_mod(mut first: U256, mut second: U256) -> U256 { #[cfg(test)] mod tests { use super::*; - use crate::U256; + use crate::primitives::U256; use core::num::Wrapping; #[test] diff --git a/crates/interpreter/src/instructions/memory.rs b/crates/interpreter/src/instructions/memory.rs index ca0ff33e6f..08d720e32b 100644 --- a/crates/interpreter/src/instructions/memory.rs +++ b/crates/interpreter/src/instructions/memory.rs @@ -1,4 +1,4 @@ -use crate::{interpreter::Interpreter, Host, InstructionResult, U256}; +use crate::{interpreter::Interpreter, primitives::U256, Host, InstructionResult}; pub fn mload(interpreter: &mut Interpreter, _host: &mut dyn Host) { // gas!(interp, gas::VERYLOW); diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index 66d5aea7ac..a63fb867f1 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -8,10 +8,10 @@ pub use contract::Contract; pub use memory::Memory; pub use stack::Stack; -use crate::primitives::{Gas, Spec}; +use crate::primitives::Spec; use crate::{ instructions::{eval, InstructionResult}, - Host, USE_GAS, + Gas, Host, USE_GAS, }; use bytes::Bytes; use core::ops::Range; diff --git a/crates/interpreter/src/interpreter/memory.rs b/crates/interpreter/src/interpreter/memory.rs index 517bb1be73..b2d45cc9b5 100644 --- a/crates/interpreter/src/interpreter/memory.rs +++ b/crates/interpreter/src/interpreter/memory.rs @@ -1,4 +1,4 @@ -use crate::{alloc::vec::Vec, U256}; +use crate::{alloc::vec::Vec, primitives::U256}; use core::{ cmp::min, ops::{BitAnd, Not}, diff --git a/crates/interpreter/src/lib.rs b/crates/interpreter/src/lib.rs index 0928443723..5471acbcfa 100644 --- a/crates/interpreter/src/lib.rs +++ b/crates/interpreter/src/lib.rs @@ -13,16 +13,12 @@ extern crate alloc; pub(crate) const USE_GAS: bool = !cfg!(feature = "no_gas_measuring"); // Reexport primary types. +pub use gas::Gas; pub use host::{DummyHost, Host}; pub use inner_models::*; pub use instruction_result::InstructionResult; pub use instructions::opcode::{self, spec_opcode_gas, OpCode, OPCODE_JUMPMAP}; pub use interpreter::*; pub use interpreter::{BytecodeLocked, Contract, Interpreter, Memory, Stack}; -pub use ruint; -pub use ruint::aliases::U256; - -pub use hashbrown::hash_map; -pub use hashbrown::HashMap; pub use revm_primitives as primitives; diff --git a/crates/precompiles/Cargo.toml b/crates/precompiles/Cargo.toml index 687c44634e..348f94e88d 100644 --- a/crates/precompiles/Cargo.toml +++ b/crates/precompiles/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/bluealloy/revm" version = "1.1.2" [dependencies] +revm-primitives = { path = "../primitives", default-features = false } bn = { package = "substrate-bn", version = "0.6", default-features = false } bytes = { version = "1.1", default-features = false } hashbrown = { version = "0.13" } diff --git a/crates/precompiles/src/lib.rs b/crates/precompiles/src/lib.rs index 4b1523a2ad..bb79481ee0 100644 --- a/crates/precompiles/src/lib.rs +++ b/crates/precompiles/src/lib.rs @@ -1,20 +1,18 @@ #![no_std] -use bytes::Bytes; -use once_cell::sync::OnceCell; - -pub type B160 = [u8; 20]; -pub type B256 = [u8; 32]; - mod blake2; mod bn128; -mod error; mod hash; mod identity; mod modexp; mod secp256k1; -pub use error::Error; +use bytes::Bytes; +use once_cell::sync::OnceCell; +pub use revm_primitives::precompile::{PrecompileError as Error, *}; + +pub type B160 = [u8; 20]; +pub type B256 = [u8; 32]; /// libraries for no_std flag #[macro_use] @@ -52,15 +50,9 @@ impl PrecompileOutput { } } -/// A precompile operation result. -pub type PrecompileResult = Result<(u64, Vec), Error>; - -pub type StandardPrecompileFn = fn(&[u8], u64) -> PrecompileResult; -pub type CustomPrecompileFn = fn(&[u8], u64) -> PrecompileResult; - #[derive(Clone, Debug)] pub struct Precompiles { - fun: HashMap, + pub fun: HashMap, } impl Default for Precompiles { diff --git a/crates/primitives/src/gas.rs b/crates/primitives/src/gas.rs deleted file mode 100644 index 83c9b04019..0000000000 --- a/crates/primitives/src/gas.rs +++ /dev/null @@ -1,85 +0,0 @@ -#[derive(Clone, Copy, Debug)] -pub struct Gas { - /// Gas Limit - limit: u64, - /// used+memory gas. - all_used_gas: u64, - /// Used gas without memory - used: u64, - /// Used gas for memory expansion - memory: u64, - /// Refunded gas. This gas is used only at the end of execution. - refunded: i64, -} -impl Gas { - pub fn new(limit: u64) -> Self { - Self { - limit, - used: 0, - memory: 0, - refunded: 0, - all_used_gas: 0, - } - } - - pub fn limit(&self) -> u64 { - self.limit - } - - pub fn memory(&self) -> u64 { - self.memory - } - - pub fn refunded(&self) -> i64 { - self.refunded - } - - pub fn spend(&self) -> u64 { - self.all_used_gas - } - - pub fn remaining(&self) -> u64 { - self.limit - self.all_used_gas - } - - pub fn erase_cost(&mut self, returned: u64) { - self.used -= returned; - self.all_used_gas -= returned; - } - - pub fn record_refund(&mut self, refund: i64) { - self.refunded += refund; - } - - /// Record an explicit cost. - #[inline(always)] - pub fn record_cost(&mut self, cost: u64) -> bool { - let (all_used_gas, overflow) = self.all_used_gas.overflowing_add(cost); - if overflow || self.limit < all_used_gas { - return false; - } - - self.used += cost; - self.all_used_gas = all_used_gas; - true - } - - /// used in memory_resize! macro to record gas used for memory expansion. - pub fn record_memory(&mut self, gas_memory: u64) -> bool { - if gas_memory > self.memory { - let (all_used_gas, overflow) = self.used.overflowing_add(gas_memory); - if overflow || self.limit < all_used_gas { - return false; - } - self.memory = gas_memory; - self.all_used_gas = all_used_gas; - } - true - } - - /// used in gas_refund! macro to record refund value. - /// Refund can be negative but self.refunded is always positive. - pub fn gas_refund(&mut self, refund: i64) { - self.refunded += refund; - } -} diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 6cf7e2fa78..e035288b11 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -2,9 +2,8 @@ pub mod bits; pub mod bytecode; pub mod db; pub mod env; -mod gas; pub mod log; -pub mod models; +pub mod precompile; pub mod result; pub mod specification; pub mod state; @@ -23,9 +22,8 @@ pub type Hash = B256; pub use bytecode::*; pub use env::*; -pub use gas::Gas; pub use log::Log; -pub use models::*; +pub use precompile::*; pub use result::*; pub use ruint; pub use ruint::aliases::U256; diff --git a/crates/primitives/src/models.rs b/crates/primitives/src/models.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/crates/primitives/src/models.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/precompiles/src/error.rs b/crates/primitives/src/precompile.rs similarity index 60% rename from crates/precompiles/src/error.rs rename to crates/primitives/src/precompile.rs index 1809457de9..8a9fa1dbd9 100644 --- a/crates/precompiles/src/error.rs +++ b/crates/primitives/src/precompile.rs @@ -1,5 +1,11 @@ +/// A precompile operation result. +pub type PrecompileResult = Result<(u64, Vec), PrecompileError>; + +pub type StandardPrecompileFn = fn(&[u8], u64) -> PrecompileResult; +pub type CustomPrecompileFn = fn(&[u8], u64) -> PrecompileResult; + #[derive(Clone, Debug, Eq, PartialEq)] -pub enum Error { +pub enum PrecompileError { /// out of gas is the main error. Other are just here for completness OutOfGas, // Blake2 erorr diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index 940a342938..2a10d426b8 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -1,9 +1,9 @@ -use crate::primitives::{specification, EVMError, EVMResult, ExecutionResult, SpecId}; +use crate::primitives::{specification, EVMError, EVMResult, Env, ExecutionResult, SpecId}; use crate::{ db::{Database, DatabaseCommit, DatabaseRef, RefDBWrapper}, evm_impl::{EVMImpl, Transact}, inspectors::NoOpInspector, - Env, Inspector, + Inspector, }; use alloc::boxed::Box; use revm_interpreter::primitives::ResultAndState; diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 0adaa3d92d..4835d70b86 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -1,28 +1,19 @@ -use crate::interpreter::gas; +use crate::interpreter::{ + analysis::to_analysed, gas, instruction_result::SuccessOrHalt, return_ok, return_revert, + CallContext, CallInputs, CallScheme, Contract, CreateInputs, CreateScheme, Gas, Host, + InstructionResult, Interpreter, SelfDestructResult, Transfer, CALL_STACK_LIMIT, +}; use crate::primitives::{ - create2_address, create_address, keccak256, Account, Bytecode, EVMError, EVMResult, - ExecutionResult, Gas, Output, + create2_address, create_address, keccak256, Account, AnalysisKind, Bytecode, EVMError, + EVMResult, Env, ExecutionResult, InvalidTransaction, Log, Output, ResultAndState, Spec, SpecId::{self, *}, - B160, B256, KECCAK_EMPTY, U256, -}; -use crate::{ - db::Database, - inner_models::SelfDestructResult, - interpreter::{self, Host}, - interpreter::{Contract, Interpreter}, - journaled_state::JournaledState, - precompiles, - primitives::Spec, - return_ok, return_revert, AnalysisKind, CallContext, CallInputs, CallScheme, CreateInputs, - CreateScheme, Env, Inspector, InstructionResult, Log, TransactTo, Transfer, + TransactTo, B160, B256, KECCAK_EMPTY, U256, }; +use crate::{db::Database, journaled_state::JournaledState, precompiles, Inspector}; use alloc::vec::Vec; use bytes::Bytes; use core::{cmp::min, marker::PhantomData}; use hashbrown::HashMap as Map; -use interpreter::analysis::to_analysed; -use interpreter::instruction_result::SuccessOrHalt; -use interpreter::primitives::{InvalidTransaction, ResultAndState}; use revm_precompiles::{Precompile, Precompiles}; pub struct EVMData<'a, DB: Database> { @@ -423,7 +414,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, self.load_account(inputs.caller); // Check depth of calls - if self.data.journaled_state.depth() > interpreter::CALL_STACK_LIMIT { + if self.data.journaled_state.depth() > CALL_STACK_LIMIT { return (InstructionResult::CallTooDeep, None, gas, Bytes::new()); } // Check balance of caller and value. Do this before increasing nonce @@ -570,7 +561,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, ); } if crate::USE_GAS { - let gas_for_code = bytes.len() as u64 * crate::gas::CODEDEPOSIT; + let gas_for_code = bytes.len() as u64 * gas::CODEDEPOSIT; if !interpreter.gas.record_cost(gas_for_code) { // record code deposit gas cost and check if we are out of gas. // EIP-2 point 3: If contract creation does not have enough gas to pay for the @@ -644,7 +635,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, }; // Check depth - if self.data.journaled_state.depth() > interpreter::CALL_STACK_LIMIT { + if self.data.journaled_state.depth() > CALL_STACK_LIMIT { let (ret, gas, out) = (InstructionResult::CallTooDeep, gas, Bytes::new()); if INSPECT { return self.inspector.call_end( diff --git a/crates/revm/src/inspector.rs b/crates/revm/src/inspector.rs index 2b67aa4179..80d81c2430 100644 --- a/crates/revm/src/inspector.rs +++ b/crates/revm/src/inspector.rs @@ -1,5 +1,7 @@ -use crate::primitives::{db::Database, Gas, B160, B256}; -use crate::{evm_impl::EVMData, CallInputs, CreateInputs, InstructionResult, Interpreter}; +use crate::evm_impl::EVMData; +use crate::interpreter::{CallInputs, CreateInputs, Gas, InstructionResult, Interpreter}; +use crate::primitives::{db::Database, B160, B256}; + use auto_impl::auto_impl; use bytes::Bytes; diff --git a/crates/revm/src/inspector/customprinter.rs b/crates/revm/src/inspector/customprinter.rs index 2ef3b8f61a..989339df63 100644 --- a/crates/revm/src/inspector/customprinter.rs +++ b/crates/revm/src/inspector/customprinter.rs @@ -1,11 +1,9 @@ //! Custom print inspector, it has step level information of execution. //! It is great tool if some debugging is needed. //! -use crate::primitives::{Bytes, Gas, B160}; -use crate::{ - inspectors::GasInspector, opcode, CallInputs, CreateInputs, Database, EVMData, Inspector, - InstructionResult, Interpreter, -}; +use crate::interpreter::{opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter}; +use crate::primitives::{Bytes, B160}; +use crate::{inspectors::GasInspector, Database, EVMData, Inspector}; use hex; #[derive(Clone, Default)] pub struct CustomPrintTracer { @@ -158,7 +156,8 @@ mod test { evm.env.tx.caller = crate::primitives::B160(hex_literal::hex!( "5fdcca53617f4d2b9134b29090c87d01058e27e0" )); - evm.env.tx.transact_to = crate::TransactTo::Call(crate::primitives::B160(callee)); + evm.env.tx.transact_to = + crate::primitives::TransactTo::Call(crate::primitives::B160(callee)); evm.env.tx.data = crate::primitives::Bytes::from(hex::decode("").unwrap()); evm.env.tx.value = crate::primitives::U256::ZERO; let _ = evm.inspect_commit(super::CustomPrintTracer::default()); diff --git a/crates/revm/src/inspector/gas.rs b/crates/revm/src/inspector/gas.rs index 9654a752cf..cc642b8c53 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/revm/src/inspector/gas.rs @@ -1,7 +1,8 @@ //! GasIspector. Helper Inspector to calculte gas for others. //! -use crate::primitives::{Gas, B160}; -use crate::{evm_impl::EVMData, CallInputs, CreateInputs, Database, Inspector, InstructionResult}; +use crate::interpreter::{CallInputs, CreateInputs, Gas, InstructionResult}; +use crate::primitives::{db::Database, B160}; +use crate::{evm_impl::EVMData, Inspector}; use bytes::Bytes; #[derive(Clone, Copy, Debug, Default)] @@ -26,7 +27,7 @@ impl Inspector for GasInspector { #[cfg(not(feature = "no_gas_measuring"))] fn initialize_interp( &mut self, - interp: &mut crate::Interpreter, + interp: &mut crate::interpreter::Interpreter, _data: &mut EVMData<'_, DB>, _is_static: bool, ) -> InstructionResult { @@ -41,18 +42,18 @@ impl Inspector for GasInspector { #[cfg(not(feature = "no_gas_measuring"))] fn step( &mut self, - interp: &mut crate::Interpreter, + interp: &mut crate::interpreter::Interpreter, data: &mut EVMData<'_, DB>, _is_static: bool, ) -> InstructionResult { let op = interp.current_opcode(); // calculate gas_block - let infos = crate::spec_opcode_gas(data.env.cfg.spec_id); + let infos = crate::interpreter::spec_opcode_gas(data.env.cfg.spec_id); let info = &infos[op as usize]; let pc = interp.program_counter(); - if op == crate::opcode::JUMPI { + if op == crate::interpreter::opcode::JUMPI { self.reduced_gas_block += info.get_gas() as u64; self.was_jumpi = Some(pc); } else if info.is_gas_block_end() { @@ -68,7 +69,7 @@ impl Inspector for GasInspector { #[cfg(not(feature = "no_gas_measuring"))] fn step_end( &mut self, - interp: &mut crate::Interpreter, + interp: &mut crate::interpreter::Interpreter, _data: &mut EVMData<'_, DB>, _is_static: bool, _eval: InstructionResult, @@ -124,14 +125,13 @@ impl Inspector for GasInspector { #[cfg(test)] mod tests { use crate::db::BenchmarkDB; - use crate::primitives::{Bytecode, Gas, B160, B256}; - use crate::{ - inspectors::GasInspector, opcode, CallInputs, CreateInputs, Database, EVMData, Inspector, - InstructionResult, Interpreter, OpCode, TransactTo, + use crate::interpreter::{ + opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter, OpCode, }; + use crate::primitives::{Bytecode, ResultAndState, TransactTo, B160, B256}; + use crate::{inspectors::GasInspector, Database, EVMData, Inspector}; use bytes::Bytes; use hex_literal::hex; - use revm_interpreter::primitives::ResultAndState; #[derive(Default, Debug)] struct StackInspector { diff --git a/crates/revm/src/journaled_state.rs b/crates/revm/src/journaled_state.rs index 3a2746c527..f6fcbe2897 100644 --- a/crates/revm/src/journaled_state.rs +++ b/crates/revm/src/journaled_state.rs @@ -1,5 +1,7 @@ -use crate::interpreter::{inner_models::SelfDestructResult, InstructionResult, U256}; -use crate::primitives::{db::Database, Account, Bytecode, Log, StorageSlot, B160, KECCAK_EMPTY}; +use crate::interpreter::{inner_models::SelfDestructResult, InstructionResult}; +use crate::primitives::{ + db::Database, Account, Bytecode, Log, StorageSlot, B160, KECCAK_EMPTY, U256, +}; use alloc::{vec, vec::Vec}; use core::mem::{self}; use hashbrown::{hash_map::Entry, HashMap as Map}; diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 27fc0803ba..2d45a526f6 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -16,8 +16,6 @@ pub use db::{Database, DatabaseCommit, InMemoryDB}; pub use evm::{evm_inner, new, EVM}; pub use evm_impl::EVMData; pub use journaled_state::{JournalEntry, JournaledState}; -pub use revm_interpreter::primitives::*; -pub use revm_interpreter::*; extern crate alloc;