diff --git a/Cargo.toml b/Cargo.toml index 4abed9a85..2ad2bc9f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -419,7 +419,7 @@ reth-tokio-util = { path = "crates/tokio-util" } reth-tracing = { path = "crates/tracing" } reth-transaction-pool = { path = "crates/transaction-pool" } reth-trie = { path = "crates/trie/trie" } -reth-trie-common = { path = "crates/trie/common" } +reth-trie-common = { path = "crates/trie/common", default-features = false } reth-trie-db = { path = "crates/trie/db" } reth-trie-parallel = { path = "crates/trie/parallel" } reth-trie-sparse = { path = "crates/trie/sparse" } diff --git a/crates/chainspec/Cargo.toml b/crates/chainspec/Cargo.toml index 0e56cf2d3..9e38feb8b 100644 --- a/crates/chainspec/Cargo.toml +++ b/crates/chainspec/Cargo.toml @@ -51,7 +51,8 @@ std = [ "alloy-rlp/std", "reth-ethereum-forks/std", "derive_more/std", - "reth-network-peers/std" + "reth-network-peers/std", + "reth-trie-common/std" ] arbitrary = [ "alloy-chains/arbitrary", diff --git a/crates/evm/execution-types/Cargo.toml b/crates/evm/execution-types/Cargo.toml index c0ef2c5a6..5d872846a 100644 --- a/crates/evm/execution-types/Cargo.toml +++ b/crates/evm/execution-types/Cargo.toml @@ -64,5 +64,6 @@ std = [ "serde?/std", "reth-primitives-traits/std", "alloy-consensus/std", - "serde_with?/std" + "serde_with?/std", + "reth-trie-common?/std" ] diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 712abd652..5f7194a6a 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -114,7 +114,8 @@ std = [ "bytes/std", "derive_more/std", "reth-zstd-compressors?/std", - "secp256k1?/std" + "secp256k1?/std", + "reth-trie-common/std" ] reth-codec = [ "dep:reth-codecs", diff --git a/crates/trie/common/Cargo.toml b/crates/trie/common/Cargo.toml index acebc2a7d..73d9a3a85 100644 --- a/crates/trie/common/Cargo.toml +++ b/crates/trie/common/Cargo.toml @@ -58,6 +58,22 @@ serde_json.workspace = true serde_with.workspace = true [features] +default = ["std"] +std = [ + "alloy-consensus/std", + "alloy-genesis/std", + "alloy-primitives/std", + "alloy-rlp/std", + "alloy-rpc-types-eth?/std", + "alloy-serde?/std", + "alloy-trie/std", + "bytes?/std", + "derive_more/std", + "nybbles/std", + "reth-primitives-traits/std", + "serde?/std", + "serde_with?/std" +] eip1186 = [ "alloy-rpc-types-eth/serde", "dep:alloy-serde", diff --git a/crates/trie/common/src/hash_builder/state.rs b/crates/trie/common/src/hash_builder/state.rs index 4bf3bade3..7ed369491 100644 --- a/crates/trie/common/src/hash_builder/state.rs +++ b/crates/trie/common/src/hash_builder/state.rs @@ -1,4 +1,5 @@ use crate::TrieMask; +use alloc::vec::Vec; use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder}; use nybbles::Nibbles; diff --git a/crates/trie/common/src/lib.rs b/crates/trie/common/src/lib.rs index 6647de678..093c2969b 100644 --- a/crates/trie/common/src/lib.rs +++ b/crates/trie/common/src/lib.rs @@ -7,6 +7,9 @@ )] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; /// The implementation of hash builder. pub mod hash_builder; diff --git a/crates/trie/common/src/nibbles.rs b/crates/trie/common/src/nibbles.rs index b1cc2f10c..a7db55b85 100644 --- a/crates/trie/common/src/nibbles.rs +++ b/crates/trie/common/src/nibbles.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use derive_more::Deref; pub use nybbles::Nibbles; @@ -30,7 +31,7 @@ impl PartialEq<[u8]> for StoredNibbles { impl PartialOrd<[u8]> for StoredNibbles { #[inline] - fn partial_cmp(&self, other: &[u8]) -> Option { + fn partial_cmp(&self, other: &[u8]) -> Option { self.0.as_slice().partial_cmp(other) } } diff --git a/crates/trie/common/src/prefix_set.rs b/crates/trie/common/src/prefix_set.rs index d58531f12..7c6a2c3a7 100644 --- a/crates/trie/common/src/prefix_set.rs +++ b/crates/trie/common/src/prefix_set.rs @@ -1,6 +1,6 @@ use crate::Nibbles; +use alloc::{sync::Arc, vec::Vec}; use alloy_primitives::map::{B256HashMap, B256HashSet}; -use std::sync::Arc; /// Collection of mutable prefix sets. #[derive(Clone, Default, Debug)] @@ -209,7 +209,7 @@ impl PrefixSet { impl<'a> IntoIterator for &'a PrefixSet { type Item = &'a Nibbles; - type IntoIter = std::slice::Iter<'a, Nibbles>; + type IntoIter = core::slice::Iter<'a, Nibbles>; fn into_iter(self) -> Self::IntoIter { self.iter() } diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index 12419ec62..541717107 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -1,6 +1,7 @@ //! Merkle trie proofs. use crate::{Nibbles, TrieAccount}; +use alloc::vec::Vec; use alloy_consensus::constants::KECCAK_EMPTY; use alloy_primitives::{ keccak256, diff --git a/crates/trie/common/src/root.rs b/crates/trie/common/src/root.rs index 982dec988..b23d3b42d 100644 --- a/crates/trie/common/src/root.rs +++ b/crates/trie/common/src/root.rs @@ -1,6 +1,7 @@ //! Common root computation functions. use crate::TrieAccount; +use alloc::vec::Vec; use alloy_primitives::{keccak256, Address, B256, U256}; use alloy_rlp::Encodable; use alloy_trie::HashBuilder; diff --git a/crates/trie/common/src/subnode.rs b/crates/trie/common/src/subnode.rs index de65a7887..7ef8a349f 100644 --- a/crates/trie/common/src/subnode.rs +++ b/crates/trie/common/src/subnode.rs @@ -1,4 +1,5 @@ use super::BranchNodeCompact; +use alloc::vec::Vec; /// Walker sub node for storing intermediate state root calculation state in the database. #[derive(Debug, Clone, PartialEq, Eq, Default)] diff --git a/crates/trie/common/src/updates.rs b/crates/trie/common/src/updates.rs index 1f5046250..99e2c908c 100644 --- a/crates/trie/common/src/updates.rs +++ b/crates/trie/common/src/updates.rs @@ -1,4 +1,5 @@ use crate::{BranchNodeCompact, HashBuilder, Nibbles}; +use alloc::vec::Vec; use alloy_primitives::{ map::{B256HashMap, B256HashSet, HashMap, HashSet}, B256, @@ -230,6 +231,10 @@ impl StorageTrieUpdates { #[cfg(any(test, feature = "serde"))] mod serde_nibbles_set { use crate::Nibbles; + use alloc::{ + string::{String, ToString}, + vec::Vec, + }; use alloy_primitives::map::HashSet; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; @@ -266,13 +271,17 @@ mod serde_nibbles_set { #[cfg(any(test, feature = "serde"))] mod serde_nibbles_map { use crate::Nibbles; + use alloc::{ + string::{String, ToString}, + vec::Vec, + }; use alloy_primitives::{hex, map::HashMap}; + use core::marker::PhantomData; use serde::{ de::{Error, MapAccess, Visitor}, ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer, }; - use std::marker::PhantomData; pub(super) fn serialize( map: &HashMap, @@ -308,7 +317,7 @@ mod serde_nibbles_map { { type Value = HashMap; - fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter.write_str("a map with hex-encoded Nibbles keys") } @@ -411,10 +420,10 @@ fn exclude_empty_from_pair( #[cfg(feature = "serde-bincode-compat")] pub mod serde_bincode_compat { use crate::{BranchNodeCompact, Nibbles}; + use alloc::borrow::Cow; use alloy_primitives::map::{B256HashMap, HashMap, HashSet}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; - use std::borrow::Cow; /// Bincode-compatible [`super::TrieUpdates`] serde implementation. ///