diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b17047f7e..2b48c4aef 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,26 +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 + - uses: actions/checkout@v4 + - name: Rustfmt + run: cargo fmt --all -- --check + - name: Clippy + 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: - - 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/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..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/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 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/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..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 297f475f7..728b92376 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1,12 +1,13 @@ //! # EVM backends //! //! Backends store state information of the VM, and exposes it to runtime. +use crate::prelude::*; +use primitive_types::{H160, H256, U256}; + +pub use self::memory::{MemoryAccount, MemoryBackend, MemoryVicinity}; mod memory; -pub use self::memory::{MemoryAccount, MemoryBackend, MemoryVicinity}; -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 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 c6c31eace..b1a2de1a1 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -1,11 +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, - collections::{BTreeMap, BTreeSet}, - vec::Vec, -}; use core::mem; use primitive_types::{H160, H256, U256}; @@ -30,7 +26,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(), @@ -291,7 +287,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 8e4a01d54..7605f3984 100644 --- a/src/executor/stack/precompile.rs +++ b/src/executor/stack/precompile.rs @@ -1,5 +1,5 @@ +use crate::prelude::*; use crate::{Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed, Transfer}; -use alloc::{collections::BTreeMap, 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::*;