Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0c7123a
move methods that use blst types into wrapper
kevaundray Mar 26, 2025
d793bdc
g1.rs and g2.rs are no longer needed
kevaundray Mar 26, 2025
c2bb3e5
deserialization methods have been moved into blst wrapper
kevaundray Mar 26, 2025
ff5654a
refactor precompiles to use blst wrapper
kevaundray Mar 26, 2025
b227749
move methods that remove padding to precompile layer
kevaundray Mar 26, 2025
0ff0a08
refactor precompile code
kevaundray Mar 26, 2025
d5108c5
function and comment refactoring
kevaundray Mar 26, 2025
ac164c8
for type safety and invariant guarantees, use blst_scalar in the API
kevaundray Mar 26, 2025
4c91998
add arkworks dependency
kevaundray Mar 26, 2025
22720f2
add initial arkworks code
kevaundray Mar 26, 2025
86c723e
make blst the default and conditionally compile arkworks-bls12-381
kevaundray Mar 26, 2025
bf7847f
move is_valid_be into blst.rs
kevaundray Mar 26, 2025
00e45a5
make blst optional and arkworks default
kevaundray Mar 26, 2025
0e96bf4
fix error message: there is a test that matches on error string
kevaundray Mar 26, 2025
0c526ea
add explicit imports for riscv compilation
kevaundray Mar 26, 2025
4ac5c54
replace unwrap with expect
kevaundray Mar 26, 2025
8ba6e96
Merge branch 'main' into kw/cleanup-blst-wrapper
kevaundray Mar 27, 2025
a24aa21
move `is_valid_be` into blst
kevaundray Mar 27, 2025
f3c2521
Update crates/precompile/src/bls12_381/utils.rs
kevaundray Mar 27, 2025
5215fae
Update crates/precompile/src/bls12_381/g1_msm.rs
kevaundray Mar 27, 2025
3712276
Update crates/precompile/src/bls12_381/utils.rs
kevaundray Mar 27, 2025
2695bbd
Update crates/precompile/src/bls12_381/g2_msm.rs
kevaundray Mar 27, 2025
b39921b
use arkworks as optional
kevaundray Mar 27, 2025
a952183
Merge branch 'kw/cleanup-blst-wrapper' into kw/add-arkworks-bls12-381
kevaundray Mar 27, 2025
cd48c06
add imports for riscv compilation
kevaundray Mar 27, 2025
176a5d1
make blst optional, but the default
kevaundray Mar 27, 2025
a884036
Merge branch 'main' into kw/add-arkworks-bls12-381
kevaundray Mar 27, 2025
1116cad
add blst back into revme and portable feature
kevaundray Mar 27, 2025
c600f12
manually import std::vec::Vec because of riscv target not knowing whi…
kevaundray Mar 27, 2025
85161b4
add feature gate on test methods that need bls
kevaundray Mar 27, 2025
7cfe11b
undo cargo fmt
kevaundray Mar 27, 2025
bda5e32
multi:
kevaundray Mar 27, 2025
a4b749a
remove feature gate from isthmus fork
kevaundray Mar 27, 2025
db39bff
remove feature gate from prague (this didn't fail tests)
kevaundray Mar 27, 2025
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
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ alloy-transport = { version = "0.12.4", default-features = false }

# precompiles
ark-bn254 = { version = "0.5", default-features = false }
ark-bls12-381 = { version = "0.5", default-features = false }
ark-ec = { version = "0.5", default-features = false }
ark-ff = { version = "0.5", default-features = false }
ark-serialize = { version = "0.5", default-features = false }
Expand Down
17 changes: 0 additions & 17 deletions crates/optimism/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g1_add_out_of_gas() {
let ctx = Context::op()
.modify_tx_chained(|tx| {
Expand Down Expand Up @@ -311,7 +310,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g1_add_input_wrong_size() {
let ctx = Context::op()
.modify_tx_chained(|tx| {
Expand Down Expand Up @@ -370,7 +368,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g1_msm_input_wrong_size() {
let ctx = g1_msm_test_tx().modify_tx_chained(|tx| tx.base.data = tx.base.data.slice(1..));

Expand All @@ -388,7 +385,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g1_msm_out_of_gas() {
let ctx = g1_msm_test_tx().modify_tx_chained(|tx| tx.base.gas_limit -= 1);

Expand All @@ -406,7 +402,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g1_msm_wrong_input_layout() {
let ctx = g1_msm_test_tx();

Expand All @@ -424,7 +419,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g2_add_out_of_gas() {
let ctx = Context::op()
.modify_tx_chained(|tx| {
Expand Down Expand Up @@ -452,7 +446,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g2_add_input_wrong_size() {
let ctx = Context::op()
.modify_tx_chained(|tx| {
Expand Down Expand Up @@ -512,7 +505,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g2_msm_input_wrong_size() {
let ctx = g2_msm_test_tx().modify_tx_chained(|tx| tx.base.data = tx.base.data.slice(1..));

Expand All @@ -530,7 +522,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g2_msm_out_of_gas() {
let ctx = g2_msm_test_tx().modify_tx_chained(|tx| tx.base.gas_limit -= 1);

Expand All @@ -548,7 +539,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_g2_msm_wrong_input_layout() {
let ctx = g2_msm_test_tx();

Expand Down Expand Up @@ -596,7 +586,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_pairing_input_wrong_size() {
let ctx = bl12_381_pairing_test_tx()
.modify_tx_chained(|tx| tx.base.data = tx.base.data.slice(1..));
Expand All @@ -615,7 +604,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_pairing_out_of_gas() {
let ctx = bl12_381_pairing_test_tx().modify_tx_chained(|tx| tx.base.gas_limit -= 1);

Expand All @@ -633,7 +621,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_tx_call_bls12_381_pairing_wrong_input_layout() {
let ctx = bl12_381_pairing_test_tx();

Expand Down Expand Up @@ -678,7 +665,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_map_fp_to_g1_out_of_gas() {
let ctx = fp_to_g1_test_tx().modify_tx_chained(|tx| tx.base.gas_limit -= 1);

Expand All @@ -696,7 +682,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_map_fp_to_g1_input_wrong_size() {
let ctx = fp_to_g1_test_tx().modify_tx_chained(|tx| tx.base.data = tx.base.data.slice(1..));

Expand Down Expand Up @@ -741,7 +726,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_map_fp2_to_g2_out_of_gas() {
let ctx = fp2_to_g2_test_tx().modify_tx_chained(|tx| tx.base.gas_limit -= 1);

Expand All @@ -759,7 +743,6 @@ mod tests {
}

#[test]
#[cfg(feature = "blst")]
fn test_halted_tx_call_bls12_381_map_fp2_to_g2_input_wrong_size() {
let ctx =
fp2_to_g2_test_tx().modify_tx_chained(|tx| tx.base.data = tx.base.data.slice(1..));
Expand Down
16 changes: 2 additions & 14 deletions crates/optimism/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,9 @@ pub fn granite() -> &'static Precompiles {
pub fn isthmus() -> &'static Precompiles {
static INSTANCE: OnceBox<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
let precompiles = granite().clone();
let mut precompiles = granite().clone();
// Prague bls12 precompiles
// Don't include BLS12-381 precompiles in no_std builds.
#[cfg(feature = "blst")]
let precompiles = {
let mut precompiles = precompiles;
precompiles.extend(precompile::bls12_381::precompiles());
precompiles
};
#[cfg(not(feature = "blst"))]
let precompiles = {
let mut precompiles = precompiles;
precompiles.extend(precompile::bls12_381_utils::bls12_381_precompiles_not_supported());
precompiles
};
precompiles.extend(precompile::bls12_381::precompiles());
Box::new(precompiles)
})
}
Expand Down
8 changes: 6 additions & 2 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ c-kzg = { workspace = true, optional = true, features = [
# Optionally use `kzg-rs` for a pure Rust implementation of KZG point evaluation.
kzg-rs = { workspace = true, optional = true }

# BLS12-381 precompiles
# Use the BLS12-381 implementation of blst for EIP2537
blst = { workspace = true, optional = true }

# Use the BLS12-381 implementation of arkworks for EIP2537
ark-bls12-381 = { workspace = true, features = ["curve"] }

# p256verify precompile
p256 = { workspace = true, optional = true, features = ["ecdsa"] }

Expand Down Expand Up @@ -98,6 +101,7 @@ std = [
"serde/std",
"serde_json/std",
"ark-bn254/std",
"ark-bls12-381/std",
"ark-ec/std",
"ark-ff/std",
"ark-serialize/std",
Expand Down Expand Up @@ -125,7 +129,7 @@ portable = ["c-kzg?/portable", "blst?/portable"]
secp256k1 = ["dep:secp256k1"]
libsecp256k1 = ["dep:libsecp256k1"]

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

# Enables the substrate implementation of eip1962
Expand Down
10 changes: 9 additions & 1 deletion crates/precompile/src/bls12_381.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use crate::PrecompileWithAddress;

mod blst;
cfg_if::cfg_if! {
if #[cfg(feature = "blst")]{
mod blst;
use blst as crypto_backend;
} else {
mod arkworks;
use arkworks as crypto_backend;
}
}

pub mod g1_add;
pub mod g1_msm;
Expand Down
Loading
Loading