diff --git a/.github/assets/check_no_std.sh b/.github/assets/check_no_std.sh deleted file mode 100755 index f19e39ddac9..00000000000 --- a/.github/assets/check_no_std.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -# TODO -no_std_packages=( -# reth-codecs -# reth-consensus -# reth-db -# reth-errors -# reth-ethereum-forks -# reth-evm -# reth-evm-ethereum -# reth-network-peers -# reth-primitives -# reth-primitives-traits -# reth-revm -) - -for package in "${no_std_packages[@]}"; do - cmd="cargo +stable build -p $package --target riscv32imac-unknown-none-elf --no-default-features" - - if [ -n "$CI" ]; then - echo "::group::$cmd" - else - printf "\n%s:\n %s\n" "$package" "$cmd" - fi - - $cmd - - if [ -n "$CI" ]; then - echo "::endgroup::" - fi -done diff --git a/.github/assets/check_wasm.sh b/.github/assets/check_wasm.sh new file mode 100755 index 00000000000..4b6dd6202d3 --- /dev/null +++ b/.github/assets/check_wasm.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -eo pipefail + +wasm_packages=( + reth-codecs + reth-consensus + reth-db + reth-db-api + reth-ethereum-forks + reth-evm + reth-evm-ethereum + reth-network-peers + reth-primitives + reth-primitives-traits + reth-revm +) + +for package in "${wasm_packages[@]}"; do + cmd="cargo +stable build -p $package --target wasm32-wasi --no-default-features --ignore-rust-version --features std" + + if [ -n "$CI" ]; then + echo "::group::$cmd1 || $cmd2" + else + printf "\n%s:\n %s\n" "$package" "$cmd" + fi + + $cmd + + if [ -n "$CI" ]; then + echo "::endgroup::" + fi +done \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3aefc21c838..a5d0a5416d5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -45,7 +45,7 @@ jobs: env: RUSTFLAGS: -D warnings - no-std: + wasm: runs-on: ubuntu-latest timeout-minutes: 30 steps: @@ -57,7 +57,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - - name: Run no_std checks + - name: Run wasm checks run: .github/assets/check_no_std.sh crate-checks: diff --git a/Cargo.lock b/Cargo.lock index 1494c0d9d21..3a1934db6e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1278,6 +1278,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bls12_381" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" +dependencies = [ + "ff", + "group", + "pairing", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "blst" version = "0.3.12" @@ -3170,6 +3183,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec", "rand_core 0.6.4", "subtle", ] @@ -4533,6 +4547,21 @@ version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" +[[package]] +name = "kzg-rs" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9920cd4460ce3cbca19c62f3bb9a9611562478a4dc9d2c556f4a7d049c5b6b" +dependencies = [ + "bls12_381", + "glob", + "hex", + "once_cell", + "serde", + "serde_derive", + "serde_yaml", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -4561,7 +4590,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -5410,6 +5439,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "pairing" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" +dependencies = [ + "group", +] + [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -8060,8 +8098,10 @@ dependencies = [ "assert_matches", "bytes", "c-kzg", + "cfg-if", "criterion", "derive_more", + "k256", "modular-bitfield", "nybbles", "once_cell", @@ -8861,8 +8901,6 @@ dependencies = [ [[package]] name = "revm" version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44102920a77b38b0144f4b84dcaa31fe44746e78f53685c2ca0149af5312e048" dependencies = [ "auto_impl", "cfg-if", @@ -8876,8 +8914,6 @@ dependencies = [ [[package]] name = "revm-inspectors" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "083fe9c20db39ab4d371e9c4d10367408fa3565ad277a4fa1770f7d9314e1b92" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -8894,8 +8930,6 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "7.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b319602039af3d130f792beba76592e7744bb3c4f2db5179758be33985a16b" dependencies = [ "revm-primitives", "serde", @@ -8904,14 +8938,12 @@ dependencies = [ [[package]] name = "revm-precompile" version = "9.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b441000a0d30e06269f822f42a13fa6bec922e951a84b643818651472c4fe6" dependencies = [ "aurora-engine-modexp", - "blst", "c-kzg", "cfg-if", "k256", + "kzg-rs", "once_cell", "p256", "revm-primitives", @@ -8924,8 +8956,6 @@ dependencies = [ [[package]] name = "revm-primitives" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b518f536bacee396eb28a43f0984b25b2cd80f052ba4f2e794d554d711c13f33" dependencies = [ "alloy-eips", "alloy-primitives", @@ -8939,6 +8969,7 @@ dependencies = [ "enumn", "hashbrown 0.14.5", "hex", + "kzg-rs", "once_cell", "serde", ] @@ -9509,6 +9540,19 @@ dependencies = [ "syn 2.0.69", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.2.6", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "serial_test" version = "3.1.1" @@ -10719,6 +10763,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "unsigned-varint" version = "0.7.2" diff --git a/Cargo.toml b/Cargo.toml index 64cb72a53a3..d387f1ba178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -309,7 +309,7 @@ reth-evm = { path = "crates/evm" } reth-evm-ethereum = { path = "crates/ethereum/evm" } reth-evm-optimism = { path = "crates/optimism/evm" } reth-execution-errors = { path = "crates/evm/execution-errors" } -reth-execution-types = { path = "crates/evm/execution-types" } +reth-execution-types = { path = "crates/evm/execution-types", default-features = false } reth-exex = { path = "crates/exex/exex" } reth-exex-test-utils = { path = "crates/exex/test-utils" } reth-exex-types = { path = "crates/exex/types" } @@ -326,7 +326,7 @@ reth-network-api = { path = "crates/net/network-api" } reth-network-types = { path = "crates/net/network-types" } reth-network-peers = { path = "crates/net/peers", default-features = false } reth-network-p2p = { path = "crates/net/p2p" } -reth-nippy-jar = { path = "crates/storage/nippy-jar" } +reth-nippy-jar = { path = "crates/storage/nippy-jar", default-features = false } reth-node-api = { path = "crates/node/api" } reth-node-builder = { path = "crates/node/builder" } reth-node-core = { path = "crates/node/core" } @@ -341,12 +341,12 @@ reth-optimism-rpc = { path = "crates/optimism/rpc" } reth-payload-builder = { path = "crates/payload/builder" } reth-payload-primitives = { path = "crates/payload/primitives" } reth-payload-validator = { path = "crates/payload/validator" } -reth-primitives = { path = "crates/primitives" } +reth-primitives = { path = "crates/primitives", default-features = false } reth-primitives-traits = { path = "crates/primitives-traits" } reth-provider = { path = "crates/storage/provider" } reth-prune = { path = "crates/prune/prune" } reth-prune-types = { path = "crates/prune/types" } -reth-revm = { path = "crates/revm" } +reth-revm = { path = "crates/revm", default-features = false } reth-rpc = { path = "crates/rpc/rpc" } reth-rpc-api = { path = "crates/rpc/rpc-api" } reth-rpc-api-testing-util = { path = "crates/rpc/rpc-testing-util" } @@ -363,27 +363,26 @@ reth-stages-api = { path = "crates/stages/api" } reth-stages-types = { path = "crates/stages/types" } reth-static-file = { path = "crates/static-file/static-file" } reth-static-file-types = { path = "crates/static-file/types" } -reth-storage-api = { path = "crates/storage/storage-api" } +reth-storage-api = { path = "crates/storage/storage-api", default-features = false } reth-storage-errors = { path = "crates/storage/errors" } reth-tasks = { path = "crates/tasks" } reth-testing-utils = { path = "testing/testing-utils" } 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 = { path = "crates/trie/trie", default-features = false } reth-trie-common = { path = "crates/trie/common" } reth-trie-parallel = { path = "crates/trie/parallel" } # revm -revm = { version = "11.0.0", features = [ +revm = { path = "../bluealloy-revm/crates/revm", features = [ "std", - "secp256k1", - "blst", + "kzg-rs", ], default-features = false } -revm-primitives = { version = "6.0.0", features = [ - "std", +revm-primitives = { path = "../bluealloy-revm/crates/primitives", features = [ + "std" ], default-features = false } -revm-inspectors = "0.4" +revm-inspectors = { path = "../revm-inspectors" } # eth alloy-chains = "0.1.15" diff --git a/crates/consensus/consensus/Cargo.toml b/crates/consensus/consensus/Cargo.toml index 1d4d6d758c4..5b69fb68cf3 100644 --- a/crates/consensus/consensus/Cargo.toml +++ b/crates/consensus/consensus/Cargo.toml @@ -20,5 +20,5 @@ thiserror-no-std = {workspace = true, default-features = false } [features] default = ["std"] -std = ["thiserror-no-std/std"] +std = ["thiserror-no-std/std", "reth-primitives/std"] test-utils = [] diff --git a/crates/errors/Cargo.toml b/crates/errors/Cargo.toml index bb56a8bace5..f7448d1a136 100644 --- a/crates/errors/Cargo.toml +++ b/crates/errors/Cargo.toml @@ -19,3 +19,7 @@ reth-storage-errors.workspace = true # misc thiserror.workspace = true + +[features] +default = ["std"] +std = [] diff --git a/crates/ethereum/evm/Cargo.toml b/crates/ethereum/evm/Cargo.toml index 7ea2e4b587c..3bf51ea07e2 100644 --- a/crates/ethereum/evm/Cargo.toml +++ b/crates/ethereum/evm/Cargo.toml @@ -36,4 +36,4 @@ serde_json.workspace = true [features] default = ["std"] -std = [] \ No newline at end of file +std = ["reth-revm/std"] \ No newline at end of file diff --git a/crates/net/peers/Cargo.toml b/crates/net/peers/Cargo.toml index 5ac24edea75..8b30ffacb39 100644 --- a/crates/net/peers/Cargo.toml +++ b/crates/net/peers/Cargo.toml @@ -35,5 +35,7 @@ serde_json.workspace = true tokio = { workspace = true, features = ["net", "macros", "rt"] } [features] +default = ["std"] +std = [] secp256k1 = ["dep:secp256k1", "enr/secp256k1"] net = ["dep:tokio", "tokio?/net"] diff --git a/crates/primitives-traits/src/constants/gas_units.rs b/crates/primitives-traits/src/constants/gas_units.rs index 0af0d2c24ce..cba13e67f6c 100644 --- a/crates/primitives-traits/src/constants/gas_units.rs +++ b/crates/primitives-traits/src/constants/gas_units.rs @@ -1,4 +1,7 @@ -use std::time::Duration; +#[cfg(not(feature = "std"))] +use alloc::{format, string::String}; + +use core::time::Duration; /// Represents one Kilogas, or `1_000` gas. pub const KILOGAS: u64 = 1_000; diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index b7a42d9c7b5..be0d5f772f7 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -9,6 +9,9 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(not(feature = "std"))] +extern crate alloc; + #[cfg(feature = "alloy-compat")] mod alloy_compat; diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 1e37184ab85..79bce02bfd7 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -33,7 +33,8 @@ secp256k1 = { workspace = true, features = [ "global-context", "recovery", "rand", -] } +], optional = true } +k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"], optional = true } # for eip-4844 c-kzg = { workspace = true, features = ["serde"], optional = true } @@ -51,6 +52,7 @@ zstd = { version = "0.13", features = ["experimental"], optional = true } # arbitrary utils arbitrary = { workspace = true, features = ["derive"], optional = true } proptest = { workspace = true, optional = true } +cfg-if = "1.0.0" # proptest-derive = { workspace = true, optional = true } [dev-dependencies] @@ -84,7 +86,7 @@ pprof = { workspace = true, features = [ secp256k1.workspace = true [features] -default = ["c-kzg", "zstd-codec", "alloy-compat", "std"] +default = ["c-kzg", "zstd-codec", "alloy-compat", "std", "secp256k1"] asm-keccak = ["alloy-primitives/asm-keccak"] arbitrary = [ "reth-primitives-traits/arbitrary", @@ -98,6 +100,8 @@ arbitrary = [ "dep:proptest", "zstd-codec", ] +secp256k1 = ["dep:secp256k1"] +k256 = ["dep:k256"] c-kzg = ["dep:c-kzg", "revm-primitives/c-kzg", "dep:tempfile", "alloy-eips/kzg"] zstd-codec = ["dep:zstd"] optimism = [ diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 29154d591e8..961f688b4e7 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -64,7 +64,6 @@ pub use transaction::{ pub use transaction::BlobTransactionValidationError; pub use transaction::{ - util::secp256k1::{public_key_to_address, recover_signer_unchecked, sign_message}, AccessList, AccessListItem, IntoRecoveredTransaction, InvalidTransactionError, Signature, Transaction, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TryFromRecoveredTransaction, TxEip1559, TxEip2930, TxEip4844, @@ -72,6 +71,13 @@ pub use transaction::{ LEGACY_TX_TYPE_ID, }; +#[cfg(feature = "secp256k1")] +pub use transaction::util::secp256k1::{ + public_key_to_address, sign_message, +}; +pub use transaction::util::secp256k1::recover_signer_unchecked; + + // Re-exports pub use self::ruint::UintTryTo; pub use alloy_primitives::{ diff --git a/crates/primitives/src/transaction/eip1559.rs b/crates/primitives/src/transaction/eip1559.rs index cce6f0ca22f..f4989fc0778 100644 --- a/crates/primitives/src/transaction/eip1559.rs +++ b/crates/primitives/src/transaction/eip1559.rs @@ -4,6 +4,9 @@ use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; use reth_codecs::{main_codec, Compact}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)). #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] diff --git a/crates/primitives/src/transaction/eip2930.rs b/crates/primitives/src/transaction/eip2930.rs index ebaa12785c1..69caa6a1d37 100644 --- a/crates/primitives/src/transaction/eip2930.rs +++ b/crates/primitives/src/transaction/eip2930.rs @@ -4,6 +4,9 @@ use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; use reth_codecs::{main_codec, Compact}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)). #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] diff --git a/crates/primitives/src/transaction/legacy.rs b/crates/primitives/src/transaction/legacy.rs index 09b661cf799..5d99570032b 100644 --- a/crates/primitives/src/transaction/legacy.rs +++ b/crates/primitives/src/transaction/legacy.rs @@ -3,6 +3,9 @@ use alloy_rlp::{length_of_length, Encodable, Header}; use core::mem; use reth_codecs::{main_codec, Compact}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Legacy transaction. #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] diff --git a/crates/primitives/src/transaction/util.rs b/crates/primitives/src/transaction/util.rs index b4a2db7f6b5..1f6704e6f45 100644 --- a/crates/primitives/src/transaction/util.rs +++ b/crates/primitives/src/transaction/util.rs @@ -1,49 +1,98 @@ -pub(crate) mod secp256k1 { - use super::*; - use crate::{keccak256, Address, Signature}; - pub(crate) use ::secp256k1::Error; - use ::secp256k1::{ - ecdsa::{RecoverableSignature, RecoveryId}, - Message, PublicKey, SecretKey, SECP256K1, - }; - use revm_primitives::{B256, U256}; - - /// Recovers the address of the sender using secp256k1 pubkey recovery. - /// - /// Converts the public key into an ethereum address by hashing the public key with keccak256. - /// - /// This does not ensure that the `s` value in the signature is low, and _just_ wraps the - /// underlying secp256k1 library. - pub fn recover_signer_unchecked(sig: &[u8; 65], msg: &[u8; 32]) -> Result
{ - let sig = - RecoverableSignature::from_compact(&sig[0..64], RecoveryId::from_i32(sig[64] as i32)?)?; - - let public = SECP256K1.recover_ecdsa(&Message::from_digest(*msg), &sig)?; - Ok(public_key_to_address(public)) - } +cfg_if::cfg_if! { + if #[cfg(feature = "secp256k1")] { + pub(crate) mod secp256k1 { + use super::*; + use crate::{keccak256, Address, Signature}; + pub(crate) use ::secp256k1::Error; + use ::secp256k1::{ + ecdsa::{RecoverableSignature, RecoveryId}, + Message, PublicKey, SecretKey, SECP256K1, + }; + use revm_primitives::{B256, U256}; - /// Signs message with the given secret key. - /// Returns the corresponding signature. - pub fn sign_message(secret: B256, message: B256) -> Result