Skip to content

precompiles: Optimize KZG point evaluation via joint G1 MSM#1536

Merged
chfast merged 1 commit into
masterfrom
kzg/joint-msm
May 22, 2026
Merged

precompiles: Optimize KZG point evaluation via joint G1 MSM#1536
chfast merged 1 commit into
masterfrom
kzg/joint-msm

Conversation

@chfast

@chfast chfast commented May 22, 2026

Copy link
Copy Markdown
Member

Rearrange the standard KZG verification equation

e(C - [y]₁, [1]₂) =? e(π, [s - z]₂)

into

e(C + [z]π - [y]₁, [1]₂) =? e(π, [s]₂)

by moving the [z] factor from G2 to G1 via the pairing's bilinearity.

The new form:

  • eliminates the G2 scalar multiplication entirely (was z),
  • eliminates the G2 point addition (was [s]G2 - [z]G2),
  • merges the two remaining G1 scalar multiplications ([z]π and [y]₁)
    into a single 2-point Pippenger MSM,
  • keeps both G2 pairing arguments as fixed constants ([1]₂ via
    blst_aggregated_in_g1's precomputed lines and the [s]₂ point from
    the trusted setup).

G2_GENERATOR_NEGATIVE and the blst_p2 mult/add helpers are no longer
needed. G1_GENERATOR_NEGATIVE is redeclared as blst_p1_affine since
the Pippenger MSM consumes affine points.

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (34b3412) to head (410bade).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1536      +/-   ##
==========================================
- Coverage   96.97%   96.97%   -0.01%     
==========================================
  Files         162      162              
  Lines       14449    14447       -2     
  Branches     3382     3383       +1     
==========================================
- Hits        14012    14010       -2     
  Misses        307      307              
  Partials      130      130              
Flag Coverage Δ
eest-develop 91.95% <100.00%> (-0.02%) ⬇️
eest-develop-gmp 26.58% <42.85%> (-0.07%) ⬇️
eest-legacy 17.56% <0.00%> (+<0.01%) ⬆️
eest-libsecp256k1 28.22% <42.85%> (-0.07%) ⬇️
eest-stable 91.86% <100.00%> (-0.02%) ⬇️
evmone-unittests 92.63% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 96.02% <100.00%> (-0.01%) ⬇️
tooling 86.71% <ø> (ø)
tests 99.79% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
lib/evmone_precompiles/kzg.cpp 100.00% <100.00%> (ø)
test/unittests/precompiles_kzg_test.cpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chfast chfast requested a review from Copilot May 22, 2026 10:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the EIP-4844 KZG point-evaluation precompile verification by algebraically rearranging the pairing equation to avoid G2 scalar mul/add and to combine the remaining G1 scalar multiplications into a joint 2-point MSM.

Changes:

  • Rewrites the KZG verification equation to move the [z] factor from G2 to G1 via pairing bilinearity.
  • Removes the need for the negative G2 generator constant and associated G2 mult/add helpers.
  • Introduces a 2-term G1 MSM ([z]π - [y]G1) and pairs the result against fixed G2 inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/evmone_precompiles/kzg.cpp
Comment thread lib/evmone_precompiles/kzg.cpp Outdated
Comment thread lib/evmone_precompiles/kzg.cpp Outdated
Comment thread lib/evmone_precompiles/kzg.cpp
Rearrange the standard KZG verification equation

    e(C - [y]₁, [1]₂) =? e(π, [s - z]₂)

into

    e(C + [z]π - [y]₁, [1]₂) =? e(π, [s]₂)

by moving the [z] factor from G2 to G1 via the pairing's bilinearity.

The new form:
  - eliminates the G2 scalar multiplication entirely (was [z](-G2_gen)),
  - eliminates the G2 point addition (was [s]G2 - [z]G2),
  - merges the two remaining G1 scalar multiplications ([z]π and [y]₁)
    into a single 2-point Pippenger MSM,
  - keeps both G2 pairing arguments as fixed constants ([1]₂ via
    blst_aggregated_in_g1's precomputed lines and the [s]₂ point from
    the trusted setup).

G2_GENERATOR_NEGATIVE and the blst_p2 mult/add helpers are no longer
needed. G1_GENERATOR_NEGATIVE is redeclared as blst_p1_affine since
the Pippenger MSM consumes affine points.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread lib/evmone_precompiles/kzg.cpp
@chfast

chfast commented May 22, 2026

Copy link
Copy Markdown
Member Author
                                                           │ /proc/self/fd/11 │          /proc/self/fd/16          │
                                                           │      gas/s       │    gas/s     vs base               │
precompile<PrecompileId::point_evaluation,_evmone_blst>-14        46.63M ± 0%   50.75M ± 0%  +8.85% (p=0.000 n=11)

@chfast chfast merged commit 42c4a45 into master May 22, 2026
27 checks passed
@chfast chfast deleted the kzg/joint-msm branch May 22, 2026 10:56
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.

2 participants