Skip to content
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

chore(eips): make sha2 optional, add kzg-sidecar feature #949

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workspace = true
[dependencies]
alloy-primitives = { workspace = true, features = ["rlp"] }
alloy-rlp.workspace = true
alloy-eips.workspace = true
alloy-eips = { workspace = true, features = ["kzg-sidecar"] }
alloy-serde = { workspace = true, optional = true }

# kzg
Expand Down
14 changes: 8 additions & 6 deletions crates/eips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ workspace = true
alloy-primitives = { workspace = true, features = ["rlp"] }
alloy-rlp = { workspace = true, features = ["derive"] }

sha2.workspace = true

# serde
alloy-serde = { workspace = true, optional = true }
serde = { workspace = true, optional = true }

# kzg
derive_more = { workspace = true, optional = true }
c-kzg = { workspace = true, optional = true }
derive_more = { workspace = true, optional = true }
once_cell = { workspace = true, features = ["race", "alloc"], optional = true }
sha2 = { workspace = true, optional = true }

# ssz
ethereum_ssz_derive = { workspace = true, optional = true }
Expand All @@ -54,7 +53,7 @@ proptest-derive.workspace = true
serde_json.workspace = true

[features]
default = ["std"]
default = ["std", "kzg-sidecar"]
std = [
"alloy-primitives/std",
"alloy-rlp/std",
Expand All @@ -68,7 +67,9 @@ serde = [
"alloy-primitives/serde",
"c-kzg?/serde",
]
kzg = ["dep:derive_more", "dep:c-kzg", "dep:once_cell"]
kzg = ["kzg-sidecar", "sha2", "dep:derive_more", "dep:c-kzg", "dep:once_cell"]
kzg-sidecar = ["sha2"]
sha2 = ["dep:sha2"]
ssz = [
"std",
"dep:ethereum_ssz",
Expand All @@ -77,9 +78,10 @@ ssz = [
]
arbitrary = [
"std",
"kzg-sidecar",
"dep:arbitrary",
"dep:proptest-derive",
"dep:proptest",
"alloy-primitives/arbitrary",
"alloy-serde/arbitrary",
"alloy-serde?/arbitrary",
]
5 changes: 4 additions & 1 deletion crates/eips/src/eip4844/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ pub mod builder;
pub mod utils;

/// Contains sidecar related types
#[cfg(feature = "kzg-sidecar")]
mod sidecar;
#[cfg(feature = "kzg-sidecar")]
pub use sidecar::*;

use alloy_primitives::{b256, FixedBytes, B256, U256};

/// The modulus of the BLS group used in the KZG commitment scheme. All field
/// elements contained in a blob MUST be STRICTLY LESS than this value.
pub const BLS_MODULUS_BYTES: FixedBytes<32> =
pub const BLS_MODULUS_BYTES: B256 =
b256!("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001");

/// The modulus of the BLS group used in the KZG commitment scheme. All field
Expand Down Expand Up @@ -90,6 +92,7 @@ pub type Bytes48 = FixedBytes<48>;
/// # Panics
///
/// If the given commitment is not 48 bytes long.
#[cfg(feature = "sha2")]
pub fn kzg_to_versioned_hash(commitment: &[u8]) -> B256 {
use sha2::Digest;

Expand Down
1 change: 1 addition & 0 deletions crates/eips/src/eip4844/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! [`SidecarCoder`].
//!
//! [`SidecarCoder`]: crate::eip4844::builder::SidecarCoder

use crate::eip4844::USABLE_BITS_PER_FIELD_ELEMENT;

/// Determine whether a slice of bytes can be contained in a field element.
Expand Down