perf(precompile): skip bls msm infinity points in arkworks backend#3770
Open
mark0-cn wants to merge 1 commit into
Open
perf(precompile): skip bls msm infinity points in arkworks backend#3770mark0-cn wants to merge 1 commit into
mark0-cn wants to merge 1 commit into
Conversation
The blst backend skips points at infinity in G1/G2 MSM, but the arkworks fallback still pushed them into the MSM. Mirror the blst `read_g1_msm` / `read_g2_msm` helpers in arkworks so both backends validate (on-curve + subgroup) and skip infinity identically. Also: - Resolve the contradictory `read_scalar` doc comment in blst (it now reduces modulo the subgroup order via `blst_scalar_from_be_bytes`) and clarify the arkworks equivalent. - Add arkworks unit tests mirroring blst's infinity-skip tests, plus backend-agnostic g1/g2 integration tests asserting an infinity point with a non-zero scalar yields the same result as omitting it.
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
Author
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.
Builds on #3766. That PR adds BLS12-381 MSM benches and teaches the blst backend to skip points at infinity and zero-reduced scalars in G1/G2 MSM. The arkworks fallback only got the zero-scalar skip — it still pushed infinity points into the MSM.
This PR brings the arkworks backend to parity:
read_g1_msm/read_g2_msminarkworks.rsmirroring the blst helpers: validate on-curve, returnNonefor the point at infinity (skip it), then subgroup-check the non-infinity points. Wire them intop1_msm_bytes/p2_msm_bytes. Output is unchanged — an infinity point contributes nothing to the MSM — but it no longer enters the MSM (and skips the subgroup check, matching blst).read_scalardoc comment inblst.rs: it reduces modulo the subgroup orderrviablst_scalar_from_be_bytes, so the leftover "we do not reduce" note was wrong. Clarify the arkworks equivalent too. Reducing moduloris sound because every MSM input point is subgroup-checked (orderr), soscalar · P == (scalar mod r) · P.Tests
read_g{1,2}_msm_skips_infinity.bls_g{1,2}msm_skips_infinity_points, asserting an infinity point paired with a non-zero scalar yields the same result as omitting it.Verified locally:
cargo test -p revm-precompile bls12_381(blst, default) — 13 passedcargo test -p revm-precompile --no-default-features --features std bls12_381(arkworks) — 11 passedcargo clippy -p revm-precompileand--no-default-features --features std— cleanTargeting
dan/bls12-381-precompile-benchesso the diff is only these changes on top of #3766.