Skip to content

Commit

Permalink
feature-gate blst
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed May 8, 2024
1 parent df85e07 commit 45c279b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ secp256k1 = { version = "0.29.0", default-features = false, features = [
], optional = true }

# BLS12-381 precompiles
blst = "0.3.11"
blst = { version = "0.3.11", optional = true }

[dev-dependencies]
criterion = { version = "0.5" }
rand = { version = "0.8", features = ["std"] }

[features]
default = ["std", "c-kzg", "secp256k1", "portable"]
default = ["std", "c-kzg", "secp256k1", "portable", "blst"]
std = [
"revm-primitives/std",
"k256/std",
Expand Down Expand Up @@ -83,6 +83,9 @@ portable = ["revm-primitives/portable", "c-kzg?/portable"]
# In Linux it passes. If you don't require to build wasm on win/mac, it is safe to use it and it is enabled by default.
secp256k1 = ["dep:secp256k1"]

# Enables the BLS12-381 precompiles.
blst = ["dep:blst"]

[[bench]]
name = "bench"
path = "benches/bench.rs"
Expand Down
14 changes: 11 additions & 3 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
extern crate alloc as std;

pub mod blake2;
#[cfg(feature = "blst")]
pub mod bls12_381;
pub mod bn128;
pub mod hash;
Expand Down Expand Up @@ -160,9 +161,16 @@ impl Precompiles {
pub fn prague() -> &'static Self {
static INSTANCE: OnceBox<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
let mut precompiles = Self::cancun().clone();
// EIP-2537: Precompile for BLS12-381 curve operations
precompiles.extend(bls12_381::precompiles());
let precompiles = Self::berlin().clone();

// Don't include KZG point evaluation precompile in no_std builds.
#[cfg(feature = "blst")]
let precompiles = {
let mut precompiles = precompiles;
precompiles.extend(bls12_381::precompiles());
precompiles
};

Box::new(precompiles)
})
}
Expand Down

0 comments on commit 45c279b

Please sign in to comment.