Skip to content

precompiles: Precompute Miller loop lines for KZG trusted setup point#1537

Draft
chfast wants to merge 1 commit into
masterfrom
kzg/precompute-lines
Draft

precompiles: Precompute Miller loop lines for KZG trusted setup point#1537
chfast wants to merge 1 commit into
masterfrom
kzg/precompute-lines

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented May 22, 2026

Each kzg_verify_proof call recomputed the Miller loop lines for the fixed trusted setup point [s]₂ on every invocation. blst exposes blst_precompute_lines() / blst_miller_loop_lines() to split the per- G2-point line tables from the per-G1-point loop.

Compute the 68-entry (~19 KB) line table for KZG_SETUP_G2_1 once on first call (function-local static, C++11 thread-safe) and pass it to every subsequent Miller loop. The b2 parameter (always KZG_SETUP_G2_1) is dropped from pairings_verify since the table replaces it.

Bench (Release on chfast's 32-thread box, median of 15 reps, 3 s each; freshly built on the same machine state, alternated runs):
before: 1598 ns/op, 31.30 Mgas/s
after: 1504 ns/op, 33.31 Mgas/s (-5.9% time, +6.4% mgas/s)

Each kzg_verify_proof call recomputed the Miller loop lines for the
fixed trusted setup point [s]₂ on every invocation. blst exposes
blst_precompute_lines() / blst_miller_loop_lines() to split the per-
G2-point line tables from the per-G1-point loop.

Compute the 68-entry (~19 KB) line table for KZG_SETUP_G2_1 once on
first call (function-local static, C++11 thread-safe) and pass it to
every subsequent Miller loop. The b2 parameter (always
KZG_SETUP_G2_1) is dropped from pairings_verify since the table
replaces it.

Bench (Release on chfast's 32-thread box, median of 15 reps, 3 s each;
freshly built on the same machine state, alternated runs):
  before:  1598 ns/op, 31.30 Mgas/s
  after:   1504 ns/op, 33.31 Mgas/s   (-5.9% time, +6.4% mgas/s)
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (42c4a45) to head (2077394).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1537   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files         162      162           
  Lines       14447    14452    +5     
  Branches     3383     3383           
=======================================
+ Hits        14010    14015    +5     
  Misses        307      307           
  Partials      130      130           
Flag Coverage Δ
eest-develop 91.96% <100.00%> (+<0.01%) ⬆️
eest-develop-gmp 26.61% <100.00%> (+0.02%) ⬆️
eest-legacy 17.56% <0.00%> (-0.01%) ⬇️
eest-libsecp256k1 28.25% <100.00%> (+0.02%) ⬆️
eest-stable 91.87% <100.00%> (+<0.01%) ⬆️
evmone-unittests 92.64% <100.00%> (+<0.01%) ⬆️

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

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

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