Skip to content

fix: Added CI back for check_no_std with compilation to wasm32 #9347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/assets/check_no_std.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ set -eo pipefail

# TODO
no_std_packages=(
# reth-codecs
reth-codecs
reth-primitives-traits
# reth-primitives
# 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"
cmd="cargo +stable build -p $package --target wasm32-wasi --no-default-features"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd="cargo +stable build -p $package --target wasm32-wasi --no-default-features"
cmd="cargo +stable build -p $package --target wasm32-wasip1 --no-default-features"

wasm32-wasi is being renamed to wasm32-wasip1 and will be removed
rust-lang/compiler-team#607


if [ -n "$CI" ]; then
echo "::group::$cmd"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: riscv32imac-unknown-none-elf
target: wasm32-wasi
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ revm-primitives = { workspace = true, features = ["serde"] }
# misc
thiserror-no-std = { workspace = true, default-features = false }
roaring = "0.10.2"
byteorder = "1"
byteorder = { version = "1", default-features = false }

# required by reth-codecs
modular-bitfield.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion crates/primitives-traits/src/constants/gas_units.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ secp256k1 = { workspace = true, features = [
"global-context",
"recovery",
"rand",
] }
], optional = true }
k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this if we're not using it?

# for eip-4844
c-kzg = { workspace = true, features = ["serde"], optional = true }

Expand Down Expand Up @@ -83,8 +84,9 @@ 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",
Expand All @@ -98,6 +100,7 @@ arbitrary = [
"dep:proptest",
"zstd-codec",
]
secp256k1 = ["dep:secp256k1"]
c-kzg = ["dep:c-kzg", "revm-primitives/c-kzg", "dep:tempfile", "alloy-eips/kzg"]
zstd-codec = ["dep:zstd"]
optimism = [
Expand Down
11 changes: 10 additions & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,23 @@ 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,
TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
};

#[cfg(feature = "secp256k1")]
pub use transaction::util::secp256k1::{
public_key_to_address, recover_signer_unchecked, sign_message,
};

#[cfg(not(feature = "secp256k1"))]
pub use transaction::util::secp256k1::recover_signer_unchecked;

use k256 as _;

// Re-exports
pub use self::ruint::UintTryTo;
pub use alloy_primitives::{
Expand Down
4 changes: 4 additions & 0 deletions crates/primitives/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use super::access_list::AccessList;
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
use core::mem;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use reth_codecs::{main_codec, Compact};

/// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)).
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
38 changes: 38 additions & 0 deletions crates/primitives/src/transaction/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "secp256k1")]
pub(crate) mod secp256k1 {
use super::*;
use crate::{keccak256, Address, Signature};
Expand Down Expand Up @@ -47,6 +48,43 @@ pub(crate) mod secp256k1 {
}
}

#[cfg(not(feature = "secp256k1"))]
pub(crate) mod secp256k1 {
use super::*;
use crate::{keccak256, Address};
pub(crate) use ::k256::ecdsa::Error;
use k256::ecdsa::{RecoveryId, Signature, VerifyingKey};

/// 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<Address, Error> {
let mut signature = Signature::from_slice(&sig[0..64])?;
let mut recid = sig[64];

// normalize signature and flip recovery id if needed.
if let Some(sig_normalized) = signature.normalize_s() {
signature = sig_normalized;
recid ^= 1;
}
let recid = RecoveryId::from_byte(recid).expect("recovery ID is valid");

// recover key
let recovered_key = VerifyingKey::recover_from_prehash(&msg[..], &signature, recid)?;
Ok(public_key_to_address(recovered_key))
}

/// Converts a public key into an ethereum address by hashing the encoded public key with
/// keccak256.
fn public_key_to_address(public: VerifyingKey) -> Address {
let hash = keccak256(&public.to_encoded_point(/* compress = */ false).as_bytes()[1..]);
Address::from_slice(&hash[12..])
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions crates/storage/codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

pub use reth_codecs_derive::*;

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use alloy_primitives::{Address, Bloom, Bytes, FixedBytes, U256};
use bytes::Buf;

Expand Down
Loading