Skip to content

crypto: Reuse V in the G2 point addition - #1636

Merged
chfast merged 1 commit into
masterfrom
crypto/reuse-v-in-g2-add
Aug 10, 2026
Merged

crypto: Reuse V in the G2 point addition#1636
chfast merged 1 commit into
masterfrom
crypto/reuse-v-in-g2-add

Conversation

@chfast

@chfast chfast commented Aug 10, 2026

Copy link
Copy Markdown
Member

Y3 re-expanded U1 * H_squared, the term already bound to V one line above
for X3. This is the canonical add-1998-cmo-2 formula, which defines V and
reuses it in Y3 = r·(V − X3) − S1·HHH — so it was never a different formula
variant, just one term written out longhand. V has been there since the
original commit.

#1542 ("Trivial reuse of computed values in pairing helpers") made this exact
substitution in the sibling lin_func_and_add but did not reach add(), which
is why the two disagreed. ecc::add reuses its v correctly too, so this was
the only one of the three copies still expanding the term.

Worth about 0.3% of the ECPAIRING instruction count — add() runs ~20 times per
pair through mul_by_X/g2_subgroup_check. Consistent with the +0.83% Mgas/s
#1542 measured for the same substitution in the hotter function, and confirmation
that the compiler does not CSE this away on its own.

🤖 Generated with Claude Code

Y3 re-expanded U1 * H_squared, the term already bound to V one line above for
X3. PR #1542 made this exact substitution in lin_func_and_add but did not reach
add(). Cuts about 0.3% off the ECPAIRING instruction count.

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

Optimizes BN254 G2 point addition by reusing an existing intermediate value.

Changes:

  • Reuses V when calculating Y3, avoiding a redundant field multiplication.
  • Aligns add() with equivalent pairing and ECC formulas.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chfast
chfast merged commit 155eb66 into master Aug 10, 2026
21 of 22 checks passed
@chfast
chfast deleted the crypto/reuse-v-in-g2-add branch August 10, 2026 21:26
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.71%. Comparing base (9888163) to head (d43c961).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1636   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files         171      171           
  Lines       15607    15607           
  Branches     3610     3610           
=======================================
  Hits        15251    15251           
  Misses        269      269           
  Partials       87       87           
Flag Coverage Δ
eest-develop 88.62% <100.00%> (ø)
eest-develop-gmp 26.53% <100.00%> (ø)
eest-legacy 17.15% <0.00%> (ø)
eest-libsecp256k1 28.83% <100.00%> (ø)
eest-stable 88.62% <100.00%> (ø)
evmone-unittests 93.42% <100.00%> (ø)

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

Components Coverage Δ
core 96.10% <100.00%> (ø)
tooling 91.92% <ø> (ø)
tests 99.80% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/pairing/bn254/utils.hpp 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.

2 participants