Batch EIP-2537 pairing check Miller loops and use affine MSM#12329
Batch EIP-2537 pairing check Miller loops and use affine MSM#12329Marchhill wants to merge 2 commits into
Conversation
…affine MSM Adopt the new Nethermind.Crypto.Bls 1.1.0-preview.197 APIs: - BLS12_PAIRING_CHECK: decode all pairs into contiguous affine buffers (validated in parallel like the MSM precompiles), then compute the product of Miller loops in a single batched MillerLoopN call sharing the Fp12 squarings across pairs, instead of one MillerLoop + GT multiplication per pair. Pairs containing a point at infinity contribute e(x, y) = 1 and are excluded from the batch, but both of their points are still validated and subgroup-checked as before. - BLS12_G1MSM / BLS12_G2MSM: decode points directly into affine layout via the new raw affine Decode (shrinking the rented point buffers from P1.Sz/P2.Sz to P1Affine.Sz/P2Affine.Sz longs per slot) and call MultiMultAffine, skipping the internal Jacobian-to-affine batch conversion that MultiMult performed. Validation order and error results are unchanged. Add regression tests for all-infinity pairing input, subgroup-invalid points in infinity pairs, and all-infinity multi-point MSM. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Claude finished @Marchhill's task in 6m 39s —— View job Review: Batch EIP-2537 pairing check Miller loops and use affine MSM
I reviewed the full diff against Correctness — verified equivalent to the serial implementation
Concurrency / thread-safety — no consensus risk
Performance / repo rules
FindingsLow — Low — Known blocker (already acknowledged in the PR description) — unpublished dependency. VerdictThe code changes are sound and consensus-safe; I found no defect that should block merge on its own. The only thing preventing merge is the explicitly-acknowledged draft state / unpublished dependency. Once I could not run the build/tests here (the unpublished package makes |
| GT acc = new(stackalloc long[GT.Sz]); | ||
| acc.MillerLoopN(g2Points, g1Points, npairs); |
There was a problem hiding this comment.
Low / robustness. acc is stackalloc'd under [SkipLocalsInit] (uninitialized), and when npairs == 0 the result is correct only if MillerLoopN(..., 0) writes the Fp12 identity into acc rather than leaving it untouched. This is a new, implicit dependency on the binding's behavior for the empty-product case — the old code made it explicit with GT.One(...).
It is covered by the new All_infinity_input_returns_one regression test, so it's correct today. But since a silent regression here would be consensus-affecting, consider making it explicit and cheaper — mirroring the npoints == 0 short-circuit the MSM precompiles already use:
GT acc = new(stackalloc long[GT.Sz]);
if (npairs == 0)
{
byte[] one = new byte[32];
one[31] = 1;
return one;
}
acc.MillerLoopN(g2Points, g1Points, npairs);Not blocking — just removes reliance on unspecified MillerLoopN(0) semantics.
Temporary until the final package ships to nuget.org Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Related PR: NethermindEth/blst-bindings#9
Changes
Adopts new Nethermind.Crypto.Bls
1.1.0-preview.199APIs (NethermindEth/blst-bindings#9) in the EIP-2537 precompiles:MillerLoopNcall that shares the Fp12 squarings across pairs — measured 1.14×–1.45× end-to-end pairing-check speedup for 2–16 pairs — replacing the serial per-pairMillerLoop+ GT multiplication. Pairs containing an infinity point contribute e(x, y) = 1 and are excluded from the batch; their points are still fully validated, preserving exact consensus semantics (validation order, error results, and gas are unchanged).MultiMultAffine, skipping the internal Jacobian→affine batch conversion.Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Notes on testing
New regression tests: all-infinity pairing check input returns 1; subgroup-invalid G1/G2 points in infinity-paired slots are still rejected; all-infinity multi-point MSM returns infinity. Full EIP-2537 vector suites (1073 tests), the EIP-2537 gas tests, and the full Nethermind.Evm.Test suite pass; zkevm configurations verified to compile.
Remarks
The referenced⚠️ Before merging: NethermindEth/blst-bindings#9 must be merged and a final package published to nuget.org, then the version pin,
Nethermind.Crypto.Bls 1.1.0-preview.199is published on the nugettest.org staging feed (already a configured package source in this repo), so CI restores normally.nuget.configmapping, andpackages.lock.jsonupdated accordingly.🤖 Generated with Claude Code