crypto: Use hex literals in bn254 FROBENIUS_COEFFS and make it constexpr#1565
Merged
Conversation
Hex _u256 literals load directly instead of the costly compile-time decimal parse, halving pairing.cpp compile cost (~35G->15.5G instructions, ~4.5s->2.2s). This also fits the array under -fconstexpr-steps, so promote it to `inline constexpr` (was `static inline const` + consteval make_fq2).
eeb4587 to
8faa995
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1565 +/- ##
=======================================
Coverage 97.36% 97.36%
=======================================
Files 163 163
Lines 14497 14497
Branches 3387 3387
=======================================
Hits 14115 14115
Misses 280 280
Partials 102 102
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes BN254 pairing code compilation by replacing large decimal _u256 literals with hex _u256 literals (avoiding expensive compile-time decimal parsing) and promoting the Frobenius coefficient table to an inline constexpr variable now that it fits within constexpr evaluation limits.
Changes:
- Convert
FROBENIUS_COEFFSentries from large decimal literals to hex_u256literals. - Change
FROBENIUS_COEFFSstorage fromstatic inline consttoinline constexpr. - Keep coefficient construction via
consteval make_fq2().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+32
to
+36
| make_fq2(0x30644e72e131a0295e6dd9e7e0acccb0c28f069fbb966e3de4bd44e5607cfd49_u256, 0), | ||
| make_fq2(0x30644e72e131a0295e6dd9e7e0acccb0c28f069fbb966e3de4bd44e5607cfd48_u256, 0), | ||
| make_fq2(0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd46_u256, 0), | ||
| make_fq2(0x59e26bcea0d48bacd4f263f1acdb5c4f5763473177fffffe_u256, 0), | ||
| make_fq2(0x59e26bcea0d48bacd4f263f1acdb5c4f5763473177ffffff_u256, 0), |
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.
Hex _u256 literals load directly instead of the costly compile-time decimal parse, halving pairing.cpp compile cost (~35G->15.5G instructions, ~4.5s->2.2s). This also fits the array under -fconstexpr-steps, so promote it to
inline constexpr(wasstatic inline const+ consteval make_fq2).