Skip to content

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

Open
chfast wants to merge 1 commit into
masterfrom
precompiles/bn254-fq2-sqr
Open

precompiles: Add Fq2 sqr() and use it in BN254 pairing helpers#1539
chfast wants to merge 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 (f2407aa) to head (3d392a0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1539   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files         162      162           
  Lines       14436    14441    +5     
  Branches     3383     3384    +1     
=======================================
+ Hits        13999    14004    +5     
  Misses        307      307           
  Partials      130      130           
Flag Coverage Δ
eest-develop 91.94% <100.00%> (+<0.01%) ⬆️
eest-develop-gmp 26.55% <100.00%> (+0.02%) ⬆️
eest-legacy 17.57% <0.00%> (-0.01%) ⬇️
eest-libsecp256k1 28.19% <100.00%> (+0.02%) ⬆️
eest-stable 91.85% <100.00%> (+<0.01%) ⬆️
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% <ø> (ø)
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.

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