ethereum-optimism / ethereum-optimism/optimism
kona-sp1: EIP-2537 (BLS12-381) precompiles run on unaccelerated arkworks in the zkVM guest
- Dominant language
- Go
- Stars
- 6.5k
- Forks
- 4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 145
Description
## Summary
In the kona-sp1 zkVM guest, revm's **EIP-2537 (BLS12-381) precompiles** (`0x0b`–`0x11`: G1ADD, G1MSM, G2ADD, G2MSM, PAIRING, MAP_FP_TO_G1, MAP_FP2_TO_G2) execute on **stock, unaccelerated `arkworks`**. Every other consensus-relevant crypto primitive in the guest is SP1-accelerated (via `[patch.crates-io]` or a runtime `Crypto` override), but the BLS12-381 curve ops are not. These precompiles are live in OP Stack consensus as of the **Isthmus** hardfork (`op-revm/src/precompiles.rs:74`, which extends the precompile set with `precompile::bls12_381::precompiles()`), so a post-Isthmus L2 block that calls them will incur very high cycle counts when re-executed in a proof.
This is **not a soundness or correctness bug** — `arkworks` is pure-Rust, deterministic, and `no_std`, so it produces consensus-correct results and compiles for the zkVM. The issue is purely proving cost / performance.
## Evidence
- revm's EIP-2537 precompiles dispatch through the swappable global `Crypto` provider: `crypto().bls12_381_g1_add / g1_msm / g2_add / g2_msm / pairing_check / fp_to_g1 / fp2_to_g2` (revm-precompile-36.0.3 `src/bls12_381/{g1_add,g1_msm,g2_add,g2_msm,pairing,map_fp_to_g1,map_fp2_to_g2}.rs`).
- The backend is feature-selected in `src/bls12_381.rs`: `blst` feature → blst, else → `arkworks`. `blst` is a *default* feature of revm-precompile, but the guest builds it **without** `blst` — in `rust/kona/sp1/programs/Cargo.lock`, `revm-precompile`'s deps include `ark-bls12-381`/`ark-ec`/`ark-ff`/`ark-serialize` but **not** `blst` (the `blst` in the lock is pulled only by `c-kzg`, host-side). So the guest resolves to the **arkworks** backend.
- Those arkworks crates are stock crates.io v0.5.0 (`source = registry+https://github.com/rust-lang/crates.io-index`).
- The guest's only `[patch.crates-io]` table (`rust/kona/sp1/programs/Cargo.toml`) patches `sha2`, `sha3`, `crypto-bigint`, `k256`, `p256`, `substrate-bn` — no `ark-*`, `bls12_381`, or `blst` entry.
- `CustomCrypto` (`rust/kona/sp1/crates/client/src/precompiles/custom.rs`) overrides only `verify_kzg_proof`, leaving revm's default (arkworks-backed) `bls12_381_*` `Crypto` methods in place.
- `sp1_bls12_381` (SP1-accelerated fork of the zkcrypto `bls12_381` crate) is already present, but pulled only by `kzg-rs` for the KZG point-evaluation precompile (`0x0a`) — a different precompile from the EIP-2537 set. revm does **not** depend on the zkcrypto `bls12_381` crate, so a cargo `[patch]` of it would not touch these precompiles.
## Impact
- Any post-Isthmus L2 block that invokes an EIP-2537 precompile will be disproportionately expensive to prove (BLS12-381 MSM/pairing on unaccelerated arkworks).
- Applies to both super-range block execution and consolidation deposit-only re-execution, and to the broader kona-sp1 STF path — it is not specific to any one guest.
## Proposed fix (follow-up PR)
Because revm dispatches EIP-2537 through the global `Crypto` provider, the surgical fix mirrors the existing KZG override: implement the `bls12_381_g1_add / g1_msm / g2_add / g2_msm / pairing_check / fp_to_g1 / fp2_to_g2` methods on `CustomCrypto` (`precompiles/custom.rs`) backed by `sp1_bls12_381` (already in the tree), exactly as `verify_kzg_proof` is backed by `kzg-rs`. No `arkworks` cargo `[patch]` is required. Verify:
- Accelerated results match the arkworks reference (add a precompile equivalence test across all seven ops, including edge cases: identity/infinity points, subgroup checks, invalid encodings).
- `sp1_bls12_381` exposes the map-to-curve (`fp_to_g1` / `fp2_to_g2`) isogeny maps; if not, keep those two on arkworks and accelerate the MSM/pairing/add ops that dominate cost.
- Cycle-count reduction via the existing `precompile-*` cycle trackers.
(Alternative: patch the arkworks `ark-ff`/`ark-ec` stack to an SP1 fork — broader, only viable if such a fork exists, and touches field arithmetic globally. The `Crypto`-override above is preferred.)
## Notes
Discovered during review of #21677 (super-range consolidation execution). Pre-existing; not introduced by that PR.
Contributor guide
Assessment
This issue has not been assessed yet.