crypto: Migrate ExtPoint to AffinePoint<E2> #1547
Open
chfast wants to merge 2 commits into
Open
Conversation
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.
0720679 to
685e4de
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.