Skip to content

precompiles: Add Fq2 sqr() and use it in BN254 pairing helpers#1539

Merged
chfast merged 1 commit into
masterfrom
precompiles/bn254-fq2-sqr
May 25, 2026
Merged

precompiles: Add Fq2 sqr() and use it in BN254 pairing helpers#1539
chfast merged 1 commit into
masterfrom
precompiles/bn254-fq2-sqr

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented May 22, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

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 enhances BN254 pairing field arithmetic by introducing an optimized squaring implementation for Fq2 and teaching the generic extension-field multiplication operator to use sqr() when multiplying an element by itself. This fits into the precompiles pairing code by reducing the cost of common “square” operations that appear in pairing-related formulas.

Changes:

  • Added constexpr Fq2 sqr(const Fq2&) using a 2-multiplication squaring formula.
  • Updated ecc::ExtFieldElem’s operator* to detect e * e and dispatch to sqr(e) when available via ADL.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/evmone_precompiles/pairing/field_template.hpp Optimizes self-multiplication (a * a) by calling sqr(a) when a suitable overload exists.
lib/evmone_precompiles/pairing/bn254/fields.hpp Adds Fq2 squaring helper to enable the generic self-multiply optimization and improve pairing arithmetic performance.

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

@chfast
Copy link
Copy Markdown
Member Author

chfast commented May 22, 2026

                                                   │ /proc/self/fd/11 │          /proc/self/fd/16          │
                                                   │      gas/s       │    gas/s     vs base               │
precompile<PrecompileId::ecpairing,_evmmax_cpp>-14        86.92M ± 0%   92.11M ± 0%  +5.98% (p=0.000 n=11)

@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 (6539fcf) to head (781dccc).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1539   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files         163      163           
  Lines       14450    14455    +5     
  Branches     3384     3385    +1     
=======================================
+ Hits        14013    14018    +5     
  Misses        307      307           
  Partials      130      130           
Flag Coverage Δ
eest-develop 91.94% <100.00%> (+<0.01%) ⬆️
eest-develop-gmp 26.53% <100.00%> (+0.02%) ⬆️
eest-legacy 17.55% <0.00%> (-0.01%) ⬇️
eest-libsecp256k1 28.17% <100.00%> (+0.02%) ⬆️
eest-stable 91.85% <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.02% <100.00%> (+<0.01%) ⬆️
tooling 86.71% <ø> (ø)
tests 99.79% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/pairing/bn254/fields.hpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/pairing/field_template.hpp 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 force-pushed the precompiles/bn254-fq2-sqr branch from 3d392a0 to 781dccc Compare May 25, 2026 14:00
Copy link
Copy Markdown

Copilot AI left a comment

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 on lines +74 to +78
if constexpr (requires { sqr(e1); }) // Use sqr() if available.
{
if (&e1 == &e2)
return sqr(e1);
}
Copy link
Copy Markdown

Copilot AI left a comment

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 no new comments.

@chfast chfast merged commit 61163aa into master May 25, 2026
24 checks passed
@chfast chfast deleted the precompiles/bn254-fq2-sqr branch May 25, 2026 15:23
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