Repository navigation
perf(precompile): use fused multi-miller loop for BLS12-381 pairing - #3823
Merged
Merged
Conversation
Replace the per-pair miller loop and fp12 multiply accumulation in the blst `pairing_check` with a single `blst_miller_loop_n` call, sharing the per-bit fp12 squaring across all pairs. This mirrors the arkworks backend, which already fuses via `multi_pairing`. Uses the raw FFI rather than blst's `miller_loop_n` Rust wrapper, which fans out to a thread pool (undesirable inside a precompile and unavailable on no_std targets), keeping the computation single-threaded and deterministic. The result is bit-identical; only faster. Bench (eip2537, end-to-end precompile): ~6% at 2 pairs, ~21% at 8, ~30% at 16.
Merging this PR will improve performance by 21.46%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
blst_miller_loop_n does not special-case points at infinity, so filter such pairs out before the fused pairing check (e.g. the proof of a constant polynomial is the point at infinity). Add tests for the valid constant-polynomial proof and the invalid mixed-infinity case, and simplify pair collection with unzip/filter.
Member
|
Nice one! Have pushed commit that would skip infinity points in kzg as blst_miller_loop had it. For bls precompile, we are already skipping those. |
This was referenced Aug 2, 2026
4waan
added a commit
to 4waan/revm
that referenced
this pull request
Aug 7, 2026
Move z from G2 to G1 in the EIP-4844 point-evaluation pairing check via bilinearity `e(proof, -[z]G2) = e([z]·proof, -G2)`, so both G2 pairing inputs collapse to the constants -G2 and [τ]G2: e(D, -G2) · e(proof, [τ]G2) == 1, D = commitment - [y]G1 + [z]·proof This replaces the per-call G2 scalar multiplication (plus a G2 subtraction and its Fp2 inversion) with a single cheaper G1 scalar multiplication, in both the arkworks and blst backends. c-kzg is unchanged (external). - arkworks: cache the two now-constant G2 points as G2Prepared (Miller-loop lines computed once) and run multi_miller_loop + one final exponentiation, which still fuses the per-bit squaring across pairs. Fewer G2 ops and cached line prep with no loss of fusion. - blst: keep the fused pairing_check (blst_miller_loop_n from bluealloy#3823); only the reformulation applies. Precomputed lines are deliberately not used: blst has no fused-multi-loop-with-precomputed-lines primitive, so precomputing would forfeit the bluealloy#3823 fusion. That trade is left for a follow-up benchmark. Tests: add an all-finite tampered-y rejection (pins the pairing relation to the correct evaluation using the c-kzg vector as oracle) and a D=∞ / finite-proof rejection (exercises the mirror infinity-filter path introduced by moving z to G1).
Merged
RealiCZ
added a commit
to megaeth-labs/revm
that referenced
this pull request
Sep 18, 2026
…luealloy#3784 bluealloy#3823 bluealloy#3840 (#57) Co-authored-by: Saylor Mike <[email protected]> Co-authored-by: Matthias Seitz <[email protected]> Co-authored-by: alpharush <[email protected]> Co-authored-by: a <[email protected]> Co-authored-by: rakita <[email protected]>
30 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace the per-pair miller loop and fp12 multiply accumulation in the blst
pairing_checkwith a singleblst_miller_loop_ncall followed by one final exponentiation, sharing the per-bit fp12 squaring across all pairs.This brings the blst backend to parity with the arkworks backend, which already fuses via
multi_pairing.Result
Bit-identical output (the product of the individual miller loops equals the fused product) — only faster. Benchmark via the existing
eip2537pairing bench, end-to-end through the precompile:Notes
blst_miller_loop_n, not blst'smiller_loop_nRust wrapper, which fans out to a thread pool — undesirable inside a precompile and unavailable onno_stdtargets. This keeps the computation single-threaded and deterministic.