diff --git a/Cargo.toml b/Cargo.toml index 2542186c7b16..a3e6f2e23567 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,10 +88,11 @@ rand = "0.8" reqwest = { version = "0.11", default-features = false } semver = "1.0" thiserror = "1.0" +thiserror-no-std = "2.0.2" url = "2.5" ## serde -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"], default-features = false } serde_json = "1.0" ## misc-testing diff --git a/crates/eips/Cargo.toml b/crates/eips/Cargo.toml index 0466594e2c5f..1b4af5c287a0 100644 --- a/crates/eips/Cargo.toml +++ b/crates/eips/Cargo.toml @@ -12,13 +12,11 @@ repository.workspace = true exclude.workspace = true [dependencies] -alloy-primitives = { workspace = true, features = ["rlp"] } +alloy-primitives = { workspace = true, features = ["rlp"], default-features = false } alloy-rlp = { workspace = true, features = ["derive"] } -thiserror.workspace = true - # serde -serde = { workspace = true, optional = true } +serde = { workspace = true, default-features = false, optional = true } # arbitrary arbitrary = { workspace = true, features = ["derive"], optional = true } @@ -31,5 +29,12 @@ proptest = { workspace = true } proptest-derive = { workspace = true } [features] +default = ["std"] +std = [ + "alloy-primitives/std", + "alloy-rlp/std", + + "serde/std", +] serde = ["dep:serde", "alloy-primitives/serde"] arbitrary = ["dep:arbitrary", "dep:proptest-derive", "dep:proptest", "alloy-primitives/arbitrary"] diff --git a/crates/eips/src/eip2718.rs b/crates/eips/src/eip2718.rs index 79b260029504..593c2409b4fe 100644 --- a/crates/eips/src/eip2718.rs +++ b/crates/eips/src/eip2718.rs @@ -2,8 +2,13 @@ //! //! [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 +use alloc::{vec, vec::Vec}; use alloy_primitives::{keccak256, Sealed, B256}; use alloy_rlp::{BufMut, Header, EMPTY_STRING_CODE}; +use core::{ + fmt, + fmt::{Display, Formatter}, +}; // https://eips.ethereum.org/EIPS/eip-2718#transactiontype-only-goes-up-to-0x7f const TX_TYPE_BYTE_MAX: u8 = 0x7f; @@ -11,19 +16,32 @@ const TX_TYPE_BYTE_MAX: u8 = 0x7f; /// [EIP-2718] decoding errors. /// /// [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 -#[derive(thiserror::Error, Debug)] +#[derive(Debug, Copy, Clone)] pub enum Eip2718Error { /// Rlp error from [`alloy_rlp`]. - #[error(transparent)] - RlpError(#[from] alloy_rlp::Error), + RlpError(alloy_rlp::Error), /// Got an unexpected type flag while decoding. - #[error("Unexpected type flag. Got {0}.")] UnexpectedType(u8), - /// Some other error occurred. - #[error(transparent)] - Custom(#[from] Box), } +impl Display for Eip2718Error { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Self::RlpError(err) => write!(f, "{err}"), + Self::UnexpectedType(t) => write!(f, "Unexpected type flag. Got {t}."), + } + } +} + +impl From for Eip2718Error { + fn from(err: alloy_rlp::Error) -> Self { + Self::RlpError(err) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for Eip2718Error {} + /// Decoding trait for [EIP-2718] envelopes. These envelopes wrap a transaction /// or a receipt with a type flag. /// diff --git a/crates/eips/src/eip2930.rs b/crates/eips/src/eip2930.rs index 4ca18c51f8ba..b64eee3ed8bd 100644 --- a/crates/eips/src/eip2930.rs +++ b/crates/eips/src/eip2930.rs @@ -4,9 +4,10 @@ #![allow(unknown_lints, non_local_definitions)] +use alloc::vec::Vec; use alloy_primitives::{Address, B256, U256}; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; -use std::mem; +use core::mem; /// A list of addresses and storage keys that the transaction plans to access. /// Accesses outside the list are possible, but become more expensive. diff --git a/crates/eips/src/lib.rs b/crates/eips/src/lib.rs index 5935ff12ec3b..ef08b6620ba8 100644 --- a/crates/eips/src/lib.rs +++ b/crates/eips/src/lib.rs @@ -11,9 +11,12 @@ clippy::missing_const_for_fn, rustdoc::all )] -#![cfg_attr(not(test), warn(unused_crate_dependencies))] #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(feature = "arbitrary", cfg(feature = "std"))] +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; pub mod eip1559; pub use eip1559::calc_next_block_base_fee; diff --git a/crates/eips/src/merge.rs b/crates/eips/src/merge.rs index 026440baa49f..76fd09d11db8 100644 --- a/crates/eips/src/merge.rs +++ b/crates/eips/src/merge.rs @@ -1,6 +1,6 @@ //! Constants related to the beacon chain consensus. -use std::time::Duration; +use core::time::Duration; /// An EPOCH is a series of 32 slots. pub const EPOCH_SLOTS: u64 = 32; diff --git a/crates/rpc-types/Cargo.toml b/crates/rpc-types/Cargo.toml index 1a0673ba6c0f..2716292744e7 100644 --- a/crates/rpc-types/Cargo.toml +++ b/crates/rpc-types/Cargo.toml @@ -14,7 +14,7 @@ exclude.workspace = true [dependencies] # ethereum alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] } -alloy-primitives = { workspace = true, features = ["rlp", "serde"] } +alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] } alloy-serde.workspace = true ethereum_ssz_derive = { workspace = true, optional = true }