Skip to content

perf(precompile): skip bls msm infinity points in arkworks backend#3770

Open
mark0-cn wants to merge 1 commit into
bluealloy:dan/bls12-381-precompile-benchesfrom
mark0-cn:perf/bls-msm-arkworks-parity
Open

perf(precompile): skip bls msm infinity points in arkworks backend#3770
mark0-cn wants to merge 1 commit into
bluealloy:dan/bls12-381-precompile-benchesfrom
mark0-cn:perf/bls-msm-arkworks-parity

Conversation

@mark0-cn

Copy link
Copy Markdown
Contributor

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:

  • Add read_g1_msm / read_g2_msm in arkworks.rs mirroring the blst helpers: validate on-curve, return None for the point at infinity (skip it), then subgroup-check the non-infinity points. Wire them into p1_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).
  • Resolve the now-contradictory read_scalar doc comment in blst.rs: it reduces modulo the subgroup order r via blst_scalar_from_be_bytes, so the leftover "we do not reduce" note was wrong. Clarify the arkworks equivalent too. Reducing modulo r is sound because every MSM input point is subgroup-checked (order r), so scalar · P == (scalar mod r) · P.

Tests

  • arkworks unit tests mirroring blst's read_g{1,2}_msm_skips_infinity.
  • Backend-agnostic integration tests 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 passed
  • cargo test -p revm-precompile --no-default-features --features std bls12_381 (arkworks) — 11 passed
  • cargo clippy -p revm-precompile and --no-default-features --features std — clean

Targeting dan/bls12-381-precompile-benches so the diff is only these changes on top of #3766.

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.
@codspeed-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 196 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing mark0-cn:perf/bls-msm-arkworks-parity (570647e) with dan/bls12-381-precompile-benches (bb5a88e)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@mark0-cn

Copy link
Copy Markdown
Contributor Author

@Rjected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant