Skip to content

crypto: Migrate ExtPoint to AffinePoint<E2> #1547

Open
chfast wants to merge 2 commits into
masterfrom
crypto/bn254-simplify
Open

crypto: Migrate ExtPoint to AffinePoint<E2> #1547
chfast wants to merge 2 commits into
masterfrom
crypto/bn254-simplify

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented May 26, 2026

No description provided.

chfast added 2 commits May 26, 2026 22:24
Pushes G2 field-element validation and Montgomery conversion to the
precompile boundary, mirroring G1. ExtPoint becomes AffinePoint<E2>;
pairing_check now takes pre-validated G2 points directly.

Fq, Fq2Config, Fq2, and E2 move from pairing/bn254/fields.hpp to
bn254.hpp so the boundary code in precompiles.cpp can construct
ExtPoint without depending on pairing internals.

The boundary uses Fq::from_bytes per coefficient (which performs the
field-element check), then constructs Fq2/AffinePoint<E2> directly,
applying the EVM-ABI imag-before-real swap.

is_field_element helper deleted (no remaining callers).

Tests: G2 literals updated to use Fq2({Fq(...), Fq(...)}) explicit
construction. Negation uses unary -Q. The "Coordinate not a field
element" G2 unit test is dropped — it is structurally inexpressible
post-migration (Fq is field-reduced by type), and the field-element
rejection is covered at the boundary by Fq::from_bytes (same primitive
as the existing bn254_point_from_bytes_fp_invalid G1 test).
precompiles.cpp::ecpairing_execute:
- Function-local `namespace bn = evmmax::bn254;` alias drops six `evmmax::bn254::`
  prefixes from the per-pair decoding block.
- `std::move(*p)` and `std::move(q)` on `pairs.emplace_back` avoid copying two
  AffinePoints (~192 B) per pair.

Comments:
- The "(real, imaginary) order" note migrates from E2's definition to the Fq2
  alias (where it belongs); the "boundary swaps imag-before-real" half moves to
  the boundary site in precompiles.cpp where the swap actually happens.
- The verify-Q comment in pairing_check explains the *why* (small subgroup vs
  full twisted-curve group) instead of narrating the helper names.

Fq2Config stays in namespace evmmax::bn254 with a load-bearing note: ADL for
multiply()/inverse() on Fq2 traverses Fq2Config's namespace, so a `detail::`
wrap would cut the chain to fields.hpp's operator definitions.
@chfast chfast force-pushed the crypto/bn254-simplify branch from 0720679 to 685e4de Compare May 26, 2026 20:24
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.96%. Comparing base (47e5f9d) to head (685e4de).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1547      +/-   ##
==========================================
- Coverage   96.97%   96.96%   -0.01%     
==========================================
  Files         163      163              
  Lines       14444    14418      -26     
  Branches     3382     3380       -2     
==========================================
- Hits        14007    13981      -26     
  Misses        307      307              
  Partials      130      130              
Flag Coverage Δ
eest-develop 91.92% <100.00%> (-0.01%) ⬇️
eest-develop-gmp 26.52% <25.00%> (+0.01%) ⬆️
eest-legacy 17.60% <0.00%> (+0.03%) ⬆️
eest-libsecp256k1 28.16% <25.00%> (+0.01%) ⬆️
eest-stable 91.85% <100.00%> (-0.01%) ⬇️
evmone-unittests 92.63% <96.15%> (-0.02%) ⬇️

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

Components Coverage Δ
core 96.01% <100.00%> (-0.01%) ⬇️
tooling 86.71% <ø> (ø)
tests 99.79% <100.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
lib/evmone_precompiles/pairing/bn254/fields.hpp 100.00% <ø> (ø)
lib/evmone_precompiles/pairing/bn254/pairing.cpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/pairing/bn254/utils.hpp 100.00% <ø> (ø)
test/state/precompiles.cpp 100.00% <100.00%> (ø)
test/unittests/evmmax_bn254_pairing_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.

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