From 3273e95ed2e1e86aa86b84a5a2d3736b4481a0ab Mon Sep 17 00:00:00 2001 From: Evgeny Ukhanov Date: Thu, 28 Mar 2024 18:56:27 +0100 Subject: [PATCH 1/5] Update Rust and clippy --- core/src/lib.rs | 1 + core/src/memory.rs | 1 + core/src/stack.rs | 1 + core/src/valids.rs | 1 + evm-tests/ethjson/src/spec/authority_round.rs | 1 - evm-tests/ethjson/src/test_helpers/state.rs | 1 - gasometer/src/lib.rs | 1 + runtime/src/eval/mod.rs | 1 + runtime/src/eval/system.rs | 1 + runtime/src/handler.rs | 1 + runtime/src/lib.rs | 1 + rust-toolchain.toml | 2 +- src/backend/memory.rs | 1 + src/backend/mod.rs | 1 + src/executor/stack/executor.rs | 4 +++- src/executor/stack/memory.rs | 8 +++----- src/executor/stack/precompile.rs | 4 +++- 17 files changed, 21 insertions(+), 10 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 822a7c715..113ee0fa2 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -24,6 +24,7 @@ pub use crate::valids::Valids; use crate::eval::{eval, Control}; use alloc::rc::Rc; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::ops::Range; use primitive_types::{H160, U256}; diff --git a/core/src/memory.rs b/core/src/memory.rs index a2f24e8d2..37486fee9 100644 --- a/core/src/memory.rs +++ b/core/src/memory.rs @@ -1,4 +1,5 @@ use crate::{ExitError, ExitFatal}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::min; use core::ops::{BitAnd, Not}; diff --git a/core/src/stack.rs b/core/src/stack.rs index 13cd4724d..3a9b56a0c 100644 --- a/core/src/stack.rs +++ b/core/src/stack.rs @@ -1,4 +1,5 @@ use crate::ExitError; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H256, U256}; diff --git a/core/src/valids.rs b/core/src/valids.rs index b7674d7d7..cc51c35b6 100644 --- a/core/src/valids.rs +++ b/core/src/valids.rs @@ -1,4 +1,5 @@ use crate::Opcode; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; /// Mapping of valid jump destination from code. diff --git a/evm-tests/ethjson/src/spec/authority_round.rs b/evm-tests/ethjson/src/spec/authority_round.rs index f136aed1c..50ae3dacf 100644 --- a/evm-tests/ethjson/src/spec/authority_round.rs +++ b/evm-tests/ethjson/src/spec/authority_round.rs @@ -118,7 +118,6 @@ mod tests { use std::str::FromStr; use ethereum_types::{H160, U256}; - use serde_json; use super::{Address, StepDuration, Uint}; use crate::spec::{authority_round::AuthorityRound, validator_set::ValidatorSet}; diff --git a/evm-tests/ethjson/src/test_helpers/state.rs b/evm-tests/ethjson/src/test_helpers/state.rs index 34fef578c..ca1b95da6 100644 --- a/evm-tests/ethjson/src/test_helpers/state.rs +++ b/evm-tests/ethjson/src/test_helpers/state.rs @@ -178,7 +178,6 @@ pub struct PostStateResult { #[cfg(test)] mod tests { use super::{MultiTransaction, State}; - use serde_json; #[test] fn multi_transaction_deserialization() { diff --git a/gasometer/src/lib.rs b/gasometer/src/lib.rs index 4f753fb54..87d847894 100644 --- a/gasometer/src/lib.rs +++ b/gasometer/src/lib.rs @@ -37,6 +37,7 @@ mod costs; mod memory; mod utils; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::max; use evm_core::{ExitError, Opcode, Stack}; diff --git a/runtime/src/eval/mod.rs b/runtime/src/eval/mod.rs index 344596c12..c40c4d911 100644 --- a/runtime/src/eval/mod.rs +++ b/runtime/src/eval/mod.rs @@ -3,6 +3,7 @@ mod macros; mod system; use crate::{CallScheme, ExitReason, Handler, Opcode, Runtime}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::min; use primitive_types::{H160, H256, U256}; diff --git a/runtime/src/eval/system.rs b/runtime/src/eval/system.rs index 7a1841b1b..f88bc8b2f 100644 --- a/runtime/src/eval/system.rs +++ b/runtime/src/eval/system.rs @@ -2,6 +2,7 @@ use super::Control; use crate::{ CallScheme, Capture, Context, CreateScheme, ExitError, ExitSucceed, Handler, Runtime, Transfer, }; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H256, U256}; use sha3::{Digest, Keccak256}; diff --git a/runtime/src/handler.rs b/runtime/src/handler.rs index b649fb2e9..514c5fcdc 100644 --- a/runtime/src/handler.rs +++ b/runtime/src/handler.rs @@ -1,4 +1,5 @@ use crate::{Capture, Context, CreateScheme, ExitError, ExitReason, Machine, Opcode}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H160, H256, U256}; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index cff10c61c..f46612534 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -34,6 +34,7 @@ pub use crate::handler::{Handler, Transfer}; pub use crate::interrupt::{Resolve, ResolveCall, ResolveCreate}; use alloc::rc::Rc; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::H160; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 052b739c9..ced0c69b8 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.72.1" +channel = "1.77.0" profile = "minimal" components = [ "rustfmt", "clippy" ] diff --git a/src/backend/memory.rs b/src/backend/memory.rs index 3fcbe5da1..511ceddb3 100644 --- a/src/backend/memory.rs +++ b/src/backend/memory.rs @@ -1,5 +1,6 @@ use super::{Apply, ApplyBackend, Backend, Basic, Log}; use alloc::collections::BTreeMap; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H160, H256, U256}; diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 297f475f7..b9e2f8de6 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -5,6 +5,7 @@ mod memory; pub use self::memory::{MemoryAccount, MemoryBackend, MemoryVicinity}; +#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H160, H256, U256}; /// Basic account information. diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 33209a422..c8d1d3b9b 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -9,7 +9,9 @@ use crate::{ Capture, Config, Context, CreateScheme, ExitError, ExitReason, Handler, Opcode, Runtime, Transfer, }; -use alloc::{collections::BTreeSet, rc::Rc, vec::Vec}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; +use alloc::{collections::BTreeSet, rc::Rc}; use core::{cmp::min, convert::Infallible}; use evm_core::{ExitFatal, InterpreterHandler, Machine, Trap}; use evm_runtime::Resolve; diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index c6c31eace..e680d2946 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -1,11 +1,9 @@ use crate::backend::{Apply, Backend, Basic, Log}; use crate::executor::stack::executor::{Accessed, StackState, StackSubstateMetadata}; use crate::{ExitError, Transfer}; -use alloc::{ - boxed::Box, - collections::{BTreeMap, BTreeSet}, - vec::Vec, -}; +use alloc::collections::{BTreeMap, BTreeSet}; +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, vec::Vec}; use core::mem; use primitive_types::{H160, H256, U256}; diff --git a/src/executor/stack/precompile.rs b/src/executor/stack/precompile.rs index 8e4a01d54..1cc7df87b 100644 --- a/src/executor/stack/precompile.rs +++ b/src/executor/stack/precompile.rs @@ -1,5 +1,7 @@ use crate::{Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed, Transfer}; -use alloc::{collections::BTreeMap, vec::Vec}; +use alloc::collections::BTreeMap; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use primitive_types::{H160, H256}; /// A precompile result. From 8fccd35200b821f8cd781731aa881cb513314232 Mon Sep 17 00:00:00 2001 From: Evgeny Ukhanov Date: Thu, 28 Mar 2024 18:59:49 +0100 Subject: [PATCH 2/5] Updated CI script --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b17047f7e..e84b0cb7f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,8 @@ jobs: run: cargo fmt --all -- --check - name: Clippy run: cargo clippy --workspace --all-targets -- -D clippy::all -D clippy::nursery + - name: Clippy + run: cargo clippy --no-default-features -- -D clippy::all -D clippy::nursery build: runs-on: ubuntu-latest steps: From 49e88fc0976fd353a7aa75a803cd3330a0f743c9 Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Fri, 29 Mar 2024 09:41:46 +0000 Subject: [PATCH 3/5] chore: remove redundant cfg annotation --- core/src/lib.rs | 1 - core/src/memory.rs | 1 - core/src/stack.rs | 1 - core/src/valids.rs | 1 - gasometer/src/lib.rs | 1 - gasometer/src/utils.rs | 2 +- runtime/src/eval/mod.rs | 1 - runtime/src/eval/system.rs | 1 - runtime/src/handler.rs | 1 - runtime/src/lib.rs | 1 - src/backend/memory.rs | 1 - src/backend/mod.rs | 8 ++++---- src/executor/stack/executor.rs | 4 +--- src/executor/stack/memory.rs | 8 ++++---- src/executor/stack/mod.rs | 4 ++-- src/executor/stack/precompile.rs | 1 - 16 files changed, 12 insertions(+), 25 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 113ee0fa2..822a7c715 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -24,7 +24,6 @@ pub use crate::valids::Valids; use crate::eval::{eval, Control}; use alloc::rc::Rc; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::ops::Range; use primitive_types::{H160, U256}; diff --git a/core/src/memory.rs b/core/src/memory.rs index 37486fee9..a2f24e8d2 100644 --- a/core/src/memory.rs +++ b/core/src/memory.rs @@ -1,5 +1,4 @@ use crate::{ExitError, ExitFatal}; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::min; use core::ops::{BitAnd, Not}; diff --git a/core/src/stack.rs b/core/src/stack.rs index 3a9b56a0c..13cd4724d 100644 --- a/core/src/stack.rs +++ b/core/src/stack.rs @@ -1,5 +1,4 @@ use crate::ExitError; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H256, U256}; diff --git a/core/src/valids.rs b/core/src/valids.rs index cc51c35b6..b7674d7d7 100644 --- a/core/src/valids.rs +++ b/core/src/valids.rs @@ -1,5 +1,4 @@ use crate::Opcode; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; /// Mapping of valid jump destination from code. diff --git a/gasometer/src/lib.rs b/gasometer/src/lib.rs index 87d847894..4f753fb54 100644 --- a/gasometer/src/lib.rs +++ b/gasometer/src/lib.rs @@ -37,7 +37,6 @@ mod costs; mod memory; mod utils; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::max; use evm_core::{ExitError, Opcode, Stack}; diff --git a/gasometer/src/utils.rs b/gasometer/src/utils.rs index 9630b9ab9..b2d7880f1 100644 --- a/gasometer/src/utils.rs +++ b/gasometer/src/utils.rs @@ -1,7 +1,7 @@ use primitive_types::U256; pub fn log2floor(value: U256) -> u64 { - assert!(value != U256::zero()); + assert_ne!(value, U256::zero()); let mut l: u64 = 256; for i in 0..4 { let i = 3 - i; diff --git a/runtime/src/eval/mod.rs b/runtime/src/eval/mod.rs index c40c4d911..344596c12 100644 --- a/runtime/src/eval/mod.rs +++ b/runtime/src/eval/mod.rs @@ -3,7 +3,6 @@ mod macros; mod system; use crate::{CallScheme, ExitReason, Handler, Opcode, Runtime}; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::min; use primitive_types::{H160, H256, U256}; diff --git a/runtime/src/eval/system.rs b/runtime/src/eval/system.rs index f88bc8b2f..7a1841b1b 100644 --- a/runtime/src/eval/system.rs +++ b/runtime/src/eval/system.rs @@ -2,7 +2,6 @@ use super::Control; use crate::{ CallScheme, Capture, Context, CreateScheme, ExitError, ExitSucceed, Handler, Runtime, Transfer, }; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H256, U256}; use sha3::{Digest, Keccak256}; diff --git a/runtime/src/handler.rs b/runtime/src/handler.rs index 514c5fcdc..b649fb2e9 100644 --- a/runtime/src/handler.rs +++ b/runtime/src/handler.rs @@ -1,5 +1,4 @@ use crate::{Capture, Context, CreateScheme, ExitError, ExitReason, Machine, Opcode}; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H160, H256, U256}; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index f46612534..cff10c61c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -34,7 +34,6 @@ pub use crate::handler::{Handler, Transfer}; pub use crate::interrupt::{Resolve, ResolveCall, ResolveCreate}; use alloc::rc::Rc; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::H160; diff --git a/src/backend/memory.rs b/src/backend/memory.rs index 511ceddb3..3fcbe5da1 100644 --- a/src/backend/memory.rs +++ b/src/backend/memory.rs @@ -1,6 +1,5 @@ use super::{Apply, ApplyBackend, Backend, Basic, Log}; use alloc::collections::BTreeMap; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H160, H256, U256}; diff --git a/src/backend/mod.rs b/src/backend/mod.rs index b9e2f8de6..f5b5cc407 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1,13 +1,13 @@ //! # EVM backends //! //! Backends store state information of the VM, and exposes it to runtime. +use alloc::vec::Vec; +use primitive_types::{H160, H256, U256}; + +pub use self::memory::{MemoryAccount, MemoryBackend, MemoryVicinity}; mod memory; -pub use self::memory::{MemoryAccount, MemoryBackend, MemoryVicinity}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; -use primitive_types::{H160, H256, U256}; /// Basic account information. #[derive(Clone, Eq, PartialEq, Debug, Default)] #[cfg_attr( diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index c8d1d3b9b..33209a422 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -9,9 +9,7 @@ use crate::{ Capture, Config, Context, CreateScheme, ExitError, ExitReason, Handler, Opcode, Runtime, Transfer, }; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; -use alloc::{collections::BTreeSet, rc::Rc}; +use alloc::{collections::BTreeSet, rc::Rc, vec::Vec}; use core::{cmp::min, convert::Infallible}; use evm_core::{ExitFatal, InterpreterHandler, Machine, Trap}; use evm_runtime::Resolve; diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index e680d2946..aeba7e558 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -1,9 +1,9 @@ use crate::backend::{Apply, Backend, Basic, Log}; use crate::executor::stack::executor::{Accessed, StackState, StackSubstateMetadata}; use crate::{ExitError, Transfer}; +use alloc::boxed::Box; use alloc::collections::{BTreeMap, BTreeSet}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, vec::Vec}; +use alloc::vec::Vec; use core::mem; use primitive_types::{H160, H256, U256}; @@ -28,7 +28,7 @@ impl<'config> MemoryStackSubstate<'config> { pub const fn new(metadata: StackSubstateMetadata<'config>) -> Self { Self { metadata, - parent: None, + parent: None::>, logs: Vec::new(), accounts: BTreeMap::new(), storages: BTreeMap::new(), @@ -289,7 +289,7 @@ impl<'config> MemoryStackSubstate<'config> { }) .unwrap_or_else(|| MemoryStackAccount { basic: backend.basic(address), - code: None, + code: None::>, reset: false, }); self.accounts.insert(address, account); diff --git a/src/executor/stack/mod.rs b/src/executor/stack/mod.rs index fddb737eb..2c9fca670 100644 --- a/src/executor/stack/mod.rs +++ b/src/executor/stack/mod.rs @@ -1,6 +1,6 @@ //! A stack-based executor with customizable state. -//! A memory-based state is provided, but can replaced by a custom -//! implementation, for exemple one interacting with a database. +//! A memory-based state is provided, but can be replaced by a custom +//! implementation, for example one interacting with a database. mod executor; mod memory; diff --git a/src/executor/stack/precompile.rs b/src/executor/stack/precompile.rs index 1cc7df87b..b0c9c7285 100644 --- a/src/executor/stack/precompile.rs +++ b/src/executor/stack/precompile.rs @@ -1,6 +1,5 @@ use crate::{Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed, Transfer}; use alloc::collections::BTreeMap; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use primitive_types::{H160, H256}; From f981b3e15444ff48e2271dd90e4ab0ce34917c0a Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Fri, 29 Mar 2024 10:34:24 +0000 Subject: [PATCH 4/5] chore: use prelude --- .github/workflows/rust.yml | 38 ++++++++++++++++---------------- core/src/error.rs | 2 +- core/src/lib.rs | 15 ++++++++++--- core/src/memory.rs | 2 +- core/src/stack.rs | 2 +- core/src/valids.rs | 2 +- gasometer/src/lib.rs | 12 +++++++++- runtime/src/eval/mod.rs | 2 +- runtime/src/eval/system.rs | 2 +- runtime/src/handler.rs | 2 +- runtime/src/lib.rs | 13 +++++++++-- src/backend/memory.rs | 3 +-- src/backend/mod.rs | 2 +- src/executor/stack/executor.rs | 2 +- src/executor/stack/memory.rs | 4 +--- src/executor/stack/precompile.rs | 3 +-- src/lib.rs | 19 ++++++++++++++++ 17 files changed, 84 insertions(+), 41 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e84b0cb7f..886fae4f9 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,28 +12,28 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Rustfmt - run: cargo fmt --all -- --check - - name: Clippy - run: cargo clippy --workspace --all-targets -- -D clippy::all -D clippy::nursery - - name: Clippy - run: cargo clippy --no-default-features -- -D clippy::all -D clippy::nursery + - uses: actions/checkout@v4 + - name: Rustfmt + run: cargo fmt --all -- --check + - name: Clippy + run: cargo clippy --workspace --all-targets -- -D clippy::all -D clippy::nursery + - name: Clippy + run: cargo clippy --workspace --all-targets --no-default-features -- -D clippy::all -D clippy::nursery build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Build NoStd - run: cargo build --no-default-features --verbose - - name: Build for feature (tracing) - run: cargo build --features tracing --verbose + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose + - name: Build NoStd + run: cargo build --no-default-features --verbose + - name: Build for feature (tracing) + run: cargo build --features tracing --verbose tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - name: Run tests - run: cargo test --all --verbose + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Run tests + run: cargo test --all --verbose diff --git a/core/src/error.rs b/core/src/error.rs index 4cace11a9..e72b16b40 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -1,5 +1,5 @@ +use crate::prelude::*; use crate::Opcode; -use alloc::borrow::Cow; /// Trap which indicates that an `ExternalOpcode` has to be handled. pub type Trap = Opcode; diff --git a/core/src/lib.rs b/core/src/lib.rs index 822a7c715..53f2aada6 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -4,8 +4,18 @@ #![forbid(unsafe_code, unused_variables, unused_imports)] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(not(feature = "std"))] +pub mod prelude { + pub use alloc::{borrow::Cow, rc::Rc, vec, vec::Vec}; +} +#[cfg(feature = "std")] +pub mod prelude { + pub use std::{borrow::Cow, rc::Rc, vec::Vec}; +} + mod error; mod eval; mod external; @@ -23,8 +33,7 @@ pub use crate::stack::Stack; pub use crate::valids::Valids; use crate::eval::{eval, Control}; -use alloc::rc::Rc; -use alloc::vec::Vec; +use crate::prelude::*; use core::ops::Range; use primitive_types::{H160, U256}; @@ -127,7 +136,7 @@ impl Machine { #[must_use] pub fn return_value(&self) -> Vec { if self.return_range.start > U256::from(usize::MAX) { - alloc::vec![0; (self.return_range.end - self.return_range.start).as_usize()] + vec![0; (self.return_range.end - self.return_range.start).as_usize()] } else if self.return_range.end > U256::from(usize::MAX) { let mut ret = self.memory.get( self.return_range.start.as_usize(), diff --git a/core/src/memory.rs b/core/src/memory.rs index a2f24e8d2..174c43d79 100644 --- a/core/src/memory.rs +++ b/core/src/memory.rs @@ -1,5 +1,5 @@ +use crate::prelude::*; use crate::{ExitError, ExitFatal}; -use alloc::vec::Vec; use core::cmp::min; use core::ops::{BitAnd, Not}; use primitive_types::{H256, U256}; diff --git a/core/src/stack.rs b/core/src/stack.rs index 13cd4724d..4f18edbe6 100644 --- a/core/src/stack.rs +++ b/core/src/stack.rs @@ -1,5 +1,5 @@ +use crate::prelude::*; use crate::ExitError; -use alloc::vec::Vec; use primitive_types::{H256, U256}; /// EVM stack. diff --git a/core/src/valids.rs b/core/src/valids.rs index b7674d7d7..752d04c54 100644 --- a/core/src/valids.rs +++ b/core/src/valids.rs @@ -1,5 +1,5 @@ +use crate::prelude::*; use crate::Opcode; -use alloc::vec::Vec; /// Mapping of valid jump destination from code. #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/gasometer/src/lib.rs b/gasometer/src/lib.rs index 4f753fb54..288566ef1 100644 --- a/gasometer/src/lib.rs +++ b/gasometer/src/lib.rs @@ -4,8 +4,18 @@ #![forbid(unsafe_code, unused_variables)] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(not(feature = "std"))] +pub mod prelude { + pub use alloc::vec::Vec; +} +#[cfg(feature = "std")] +pub mod prelude { + pub use std::vec::Vec; +} + #[cfg(feature = "tracing")] pub mod tracing; @@ -37,7 +47,7 @@ mod costs; mod memory; mod utils; -use alloc::vec::Vec; +use crate::prelude::*; use core::cmp::max; use evm_core::{ExitError, Opcode, Stack}; use evm_runtime::{Config, Handler}; diff --git a/runtime/src/eval/mod.rs b/runtime/src/eval/mod.rs index 344596c12..e157cef70 100644 --- a/runtime/src/eval/mod.rs +++ b/runtime/src/eval/mod.rs @@ -2,8 +2,8 @@ mod macros; mod system; +use crate::prelude::*; use crate::{CallScheme, ExitReason, Handler, Opcode, Runtime}; -use alloc::vec::Vec; use core::cmp::min; use primitive_types::{H160, H256, U256}; diff --git a/runtime/src/eval/system.rs b/runtime/src/eval/system.rs index 7a1841b1b..a20be69c2 100644 --- a/runtime/src/eval/system.rs +++ b/runtime/src/eval/system.rs @@ -1,8 +1,8 @@ use super::Control; +use crate::prelude::*; use crate::{ CallScheme, Capture, Context, CreateScheme, ExitError, ExitSucceed, Handler, Runtime, Transfer, }; -use alloc::vec::Vec; use primitive_types::{H256, U256}; use sha3::{Digest, Keccak256}; diff --git a/runtime/src/handler.rs b/runtime/src/handler.rs index b649fb2e9..4b16575ff 100644 --- a/runtime/src/handler.rs +++ b/runtime/src/handler.rs @@ -1,5 +1,5 @@ +use crate::prelude::*; use crate::{Capture, Context, CreateScheme, ExitError, ExitReason, Machine, Opcode}; -use alloc::vec::Vec; use primitive_types::{H160, H256, U256}; /// Transfer from source to target, with given value. diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index cff10c61c..f4d965c43 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -4,8 +4,18 @@ #![forbid(unsafe_code, unused_variables)] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(not(feature = "std"))] +pub mod prelude { + pub use alloc::{rc::Rc, vec::Vec}; +} +#[cfg(feature = "std")] +pub mod prelude { + pub use std::{rc::Rc, vec::Vec}; +} + #[cfg(feature = "tracing")] pub mod tracing; @@ -33,8 +43,7 @@ pub use crate::context::{CallScheme, Context, CreateScheme}; pub use crate::handler::{Handler, Transfer}; pub use crate::interrupt::{Resolve, ResolveCall, ResolveCreate}; -use alloc::rc::Rc; -use alloc::vec::Vec; +use prelude::*; use primitive_types::H160; macro_rules! step { diff --git a/src/backend/memory.rs b/src/backend/memory.rs index 3fcbe5da1..f37fceda1 100644 --- a/src/backend/memory.rs +++ b/src/backend/memory.rs @@ -1,6 +1,5 @@ use super::{Apply, ApplyBackend, Backend, Basic, Log}; -use alloc::collections::BTreeMap; -use alloc::vec::Vec; +use crate::prelude::*; use primitive_types::{H160, H256, U256}; /// Vicinity value of a memory backend. diff --git a/src/backend/mod.rs b/src/backend/mod.rs index f5b5cc407..728b92376 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1,7 +1,7 @@ //! # EVM backends //! //! Backends store state information of the VM, and exposes it to runtime. -use alloc::vec::Vec; +use crate::prelude::*; use primitive_types::{H160, H256, U256}; pub use self::memory::{MemoryAccount, MemoryBackend, MemoryVicinity}; diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 33209a422..1e8efece3 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -5,11 +5,11 @@ use crate::executor::stack::precompile::{ use crate::executor::stack::tagged_runtime::{RuntimeKind, TaggedRuntime}; use crate::gasometer::{self, Gasometer, StorageTarget}; use crate::maybe_borrowed::MaybeBorrowed; +use crate::prelude::*; use crate::{ Capture, Config, Context, CreateScheme, ExitError, ExitReason, Handler, Opcode, Runtime, Transfer, }; -use alloc::{collections::BTreeSet, rc::Rc, vec::Vec}; use core::{cmp::min, convert::Infallible}; use evm_core::{ExitFatal, InterpreterHandler, Machine, Trap}; use evm_runtime::Resolve; diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index aeba7e558..b1a2de1a1 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -1,9 +1,7 @@ use crate::backend::{Apply, Backend, Basic, Log}; use crate::executor::stack::executor::{Accessed, StackState, StackSubstateMetadata}; +use crate::prelude::*; use crate::{ExitError, Transfer}; -use alloc::boxed::Box; -use alloc::collections::{BTreeMap, BTreeSet}; -use alloc::vec::Vec; use core::mem; use primitive_types::{H160, H256, U256}; diff --git a/src/executor/stack/precompile.rs b/src/executor/stack/precompile.rs index b0c9c7285..7605f3984 100644 --- a/src/executor/stack/precompile.rs +++ b/src/executor/stack/precompile.rs @@ -1,6 +1,5 @@ +use crate::prelude::*; use crate::{Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed, Transfer}; -use alloc::collections::BTreeMap; -use alloc::vec::Vec; use primitive_types::{H160, H256}; /// A precompile result. diff --git a/src/lib.rs b/src/lib.rs index 44d3c23c0..52f4a0387 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,27 @@ #![forbid(unsafe_code, unused_variables)] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(not(feature = "std"))] +pub mod prelude { + pub use alloc::{ + boxed::Box, + collections::{BTreeMap, BTreeSet}, + rc::Rc, + vec::Vec, + }; +} +#[cfg(feature = "std")] +pub mod prelude { + pub use std::{ + collections::{BTreeMap, BTreeSet}, + rc::Rc, + vec::Vec, + }; +} + pub use evm_core::*; pub use evm_gasometer as gasometer; pub use evm_runtime::*; From 954ce7f53c4b58301b8bb16f3eeaaff6bbc3de6a Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Fri, 29 Mar 2024 10:48:49 +0000 Subject: [PATCH 5/5] chore: remove --workspace from clippy check --- .github/workflows/rust.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 886fae4f9..2b48c4aef 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,9 +16,9 @@ jobs: - name: Rustfmt run: cargo fmt --all -- --check - name: Clippy - run: cargo clippy --workspace --all-targets -- -D clippy::all -D clippy::nursery - - name: Clippy - run: cargo clippy --workspace --all-targets --no-default-features -- -D clippy::all -D clippy::nursery + run: cargo clippy --all-targets -- -D clippy::all -D clippy::nursery + - name: Clippy no_std + run: cargo clippy --all-targets --no-default-features -- -D clippy::all -D clippy::nursery build: runs-on: ubuntu-latest steps: