From 0890dcfab7e872b864b47867e998e63d306600e4 Mon Sep 17 00:00:00 2001 From: Iaroslav Mazur Date: Thu, 16 Nov 2023 13:46:02 +0300 Subject: [PATCH 1/2] refactor: simplify use statements --- bins/revme/src/cmd/format_kzg_setup.rs | 3 +-- bins/revme/src/cmd/statetest/models/mod.rs | 1 - crates/interpreter/src/host.rs | 5 ++--- crates/interpreter/src/instructions/host.rs | 8 +++----- crates/interpreter/src/instructions/i256.rs | 1 - crates/interpreter/src/interpreter.rs | 5 ++--- crates/precompile/src/blake2.rs | 3 +-- crates/primitives/src/bytecode.rs | 6 ++++-- crates/primitives/src/constants.rs | 2 +- crates/primitives/src/db.rs | 5 +---- crates/primitives/src/state.rs | 4 +--- crates/revm/src/frame.rs | 3 +-- crates/revm/src/handler/optimism.rs | 3 +-- crates/revm/src/inspector/gas.rs | 8 +++++--- crates/revm/src/lib.rs | 3 +-- 15 files changed, 24 insertions(+), 36 deletions(-) diff --git a/bins/revme/src/cmd/format_kzg_setup.rs b/bins/revme/src/cmd/format_kzg_setup.rs index 8874b3f42e..b2dfaa5b0e 100644 --- a/bins/revme/src/cmd/format_kzg_setup.rs +++ b/bins/revme/src/cmd/format_kzg_setup.rs @@ -1,6 +1,5 @@ pub use revm::primitives::kzg::{parse_kzg_trusted_setup, G1Points, G2Points, KzgErrors}; -use std::path::PathBuf; -use std::{env, fs}; +use std::{env, fs, path::PathBuf}; use structopt::StructOpt; /// Statetest command diff --git a/bins/revme/src/cmd/statetest/models/mod.rs b/bins/revme/src/cmd/statetest/models/mod.rs index 24c12f10d3..6a1cd95fa9 100644 --- a/bins/revme/src/cmd/statetest/models/mod.rs +++ b/bins/revme/src/cmd/statetest/models/mod.rs @@ -117,7 +117,6 @@ pub type AccessList = Vec; mod tests { use super::*; - use revm::primitives::Address; use serde_json::Error; #[test] diff --git a/crates/interpreter/src/host.rs b/crates/interpreter/src/host.rs index 93242a633e..8170f1e339 100644 --- a/crates/interpreter/src/host.rs +++ b/crates/interpreter/src/host.rs @@ -1,12 +1,11 @@ -use crate::primitives::Bytecode; use crate::{ - primitives::{Address, Bytes, Env, B256, U256}, + primitives::{Address, Bytecode, Bytes, Env, B256, U256}, SelfDestructResult, }; use alloc::vec::Vec; -pub use dummy::DummyHost; mod dummy; +pub use dummy::DummyHost; /// EVM context host. pub trait Host { diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 7ae9222066..12ca33ee49 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -1,11 +1,9 @@ -use crate::interpreter::InterpreterAction; -use crate::primitives::{Address, Bytes, Spec, SpecId::*, B256, U256}; -use crate::MAX_INITCODE_SIZE; use crate::{ gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST}, - interpreter::Interpreter, + interpreter::{Interpreter, InterpreterAction}, + primitives::{Address, Bytes, Spec, SpecId::*, B256, U256}, CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme, Host, InstructionResult, - Transfer, + Transfer, MAX_INITCODE_SIZE, }; use alloc::{boxed::Box, vec::Vec}; use core::cmp::min; diff --git a/crates/interpreter/src/instructions/i256.rs b/crates/interpreter/src/instructions/i256.rs index 5a5112bf9e..dde7babac7 100644 --- a/crates/interpreter/src/instructions/i256.rs +++ b/crates/interpreter/src/instructions/i256.rs @@ -123,7 +123,6 @@ pub fn i256_mod(mut first: U256, mut second: U256) -> U256 { #[cfg(test)] mod tests { use super::*; - use crate::primitives::U256; use core::num::Wrapping; #[test] diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index 79fda9d13e..ebdd75e0c6 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -8,10 +8,9 @@ pub use contract::Contract; pub use shared_memory::{next_multiple_of_32, SharedMemory}; pub use stack::{Stack, STACK_LIMIT}; -use crate::primitives::Bytes; use crate::{ - push, push_b256, return_ok, return_revert, CallInputs, CreateInputs, Gas, Host, - InstructionResult, + primitives::Bytes, push, push_b256, return_ok, return_revert, CallInputs, CreateInputs, Gas, + Host, InstructionResult, }; use alloc::boxed::Box; use core::cmp::min; diff --git a/crates/precompile/src/blake2.rs b/crates/precompile/src/blake2.rs index 0bbc470ff6..b92a586672 100644 --- a/crates/precompile/src/blake2.rs +++ b/crates/precompile/src/blake2.rs @@ -1,5 +1,4 @@ -use crate::{Error, PrecompileWithAddress, StandardPrecompileFn}; -use crate::{Precompile, PrecompileResult}; +use crate::{Error, Precompile, PrecompileResult, PrecompileWithAddress, StandardPrecompileFn}; use core::convert::TryInto; const F_ROUND: u64 = 1; diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index c535df8c34..bbf8791eef 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -1,7 +1,9 @@ use crate::{hex, keccak256, Bytes, B256, KECCAK_EMPTY}; use alloc::{sync::Arc, vec::Vec}; -use bitvec::prelude::{bitvec, Lsb0}; -use bitvec::vec::BitVec; +use bitvec::{ + prelude::{bitvec, Lsb0}, + vec::BitVec, +}; use core::fmt::Debug; /// A map of valid `jump` destinations. diff --git a/crates/primitives/src/constants.rs b/crates/primitives/src/constants.rs index c57045b656..07745dd3cc 100644 --- a/crates/primitives/src/constants.rs +++ b/crates/primitives/src/constants.rs @@ -4,7 +4,7 @@ use crate::Address; /// By default limit is 0x6000 (~25kb) pub const MAX_CODE_SIZE: usize = 0x6000; -/// Number of blocks hashes that EVM can access in the past +/// Number of block hashes that EVM can access in the past pub const BLOCK_HASH_HISTORY: usize = 256; /// EIP-3860: Limit and meter initcode diff --git a/crates/primitives/src/db.rs b/crates/primitives/src/db.rs index 6ce54028c2..ab3b8135ca 100644 --- a/crates/primitives/src/db.rs +++ b/crates/primitives/src/db.rs @@ -1,7 +1,4 @@ -use crate::AccountInfo; -use crate::U256; -use crate::{Account, Bytecode}; -use crate::{Address, B256}; +use crate::{Account, AccountInfo, Address, Bytecode, B256, U256}; use auto_impl::auto_impl; use hashbrown::HashMap as Map; diff --git a/crates/primitives/src/state.rs b/crates/primitives/src/state.rs index 86bd5d3020..cf80c56bff 100644 --- a/crates/primitives/src/state.rs +++ b/crates/primitives/src/state.rs @@ -279,9 +279,7 @@ impl AccountInfo { #[cfg(test)] mod tests { - use crate::Account; - use crate::KECCAK_EMPTY; - use crate::U256; + use crate::{Account, KECCAK_EMPTY, U256}; #[test] fn account_is_empty_balance() { diff --git a/crates/revm/src/frame.rs b/crates/revm/src/frame.rs index 251cd974de..fc1ff95e18 100644 --- a/crates/revm/src/frame.rs +++ b/crates/revm/src/frame.rs @@ -1,5 +1,4 @@ -use crate::JournalCheckpoint; -use crate::{interpreter::Interpreter, primitives::Address}; +use crate::{interpreter::Interpreter, primitives::Address, JournalCheckpoint}; use core::ops::Range; /// Call CallStackFrame. diff --git a/crates/revm/src/handler/optimism.rs b/crates/revm/src/handler/optimism.rs index b90dc9bad0..49e7c69676 100644 --- a/crates/revm/src/handler/optimism.rs +++ b/crates/revm/src/handler/optimism.rs @@ -238,10 +238,9 @@ pub fn end_handle( #[cfg(test)] mod tests { - use crate::primitives::{BedrockSpec, RegolithSpec}; + use crate::primitives::{BedrockSpec, RegolithSpec, B256}; use super::*; - use crate::primitives::B256; #[test] fn test_revert_gas() { diff --git a/crates/revm/src/inspector/gas.rs b/crates/revm/src/inspector/gas.rs index 965d87e009..3c5462265e 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/revm/src/inspector/gas.rs @@ -150,9 +150,11 @@ mod tests { #[test] #[cfg(not(feature = "optimism"))] fn test_gas_inspector() { - use crate::db::BenchmarkDB; - use crate::interpreter::opcode; - use crate::primitives::{address, Bytecode, Bytes, TransactTo}; + use crate::{ + db::BenchmarkDB, + interpreter::opcode, + primitives::{address, Bytecode, Bytes, TransactTo}, + }; let contract_data: Bytes = Bytes::from(vec![ opcode::PUSH1, diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 93f7c63086..71cac5cf6b 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -47,8 +47,7 @@ pub use revm_interpreter as interpreter; pub use revm_interpreter::primitives; // reexport inspector implementations -pub use inspector::inspectors; -pub use inspector::{inspector_instruction, Inspector}; +pub use inspector::{inspector_instruction, inspectors, Inspector}; // export Optimism types, helpers, and constants #[cfg(feature = "optimism")] From e2b16933c1a6a363685a519be5a94e5633afc933 Mon Sep 17 00:00:00 2001 From: rakita Date: Thu, 16 Nov 2023 17:48:06 +0300 Subject: [PATCH 2/2] Update crates/interpreter/src/instructions/host.rs --- crates/interpreter/src/instructions/host.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index cc60b71f61..12ca33ee49 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -1,4 +1,3 @@ - use crate::{ gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST}, interpreter::{Interpreter, InterpreterAction},