crypto: Rename ModArith to MontgomeryArith - #1666
Open
chfast wants to merge 1 commit into
Open
Conversation
The class implements one specific algorithm, so name it after that algorithm: arithmetics keeping the values in other representations are coming, and they will not be Montgomery. For the same reason the conversions become to_internal() and from_internal(), because the Montgomery form is an implementation detail of this one arithmetic rather than something its users need to name. The generated code is unchanged.
Contributor
There was a problem hiding this comment.
Pull request overview
Renames the modular arithmetic implementation to reflect its Montgomery algorithm while abstracting its internal representation.
Changes:
- Renames
ModArithtoMontgomeryArith. - Renames conversion methods to
to_internal()andfrom_internal(). - Updates all affected consumers, tests, benchmarks, and templates.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/evmone_precompiles/modarith.hpp |
Renames the class and conversion API. |
lib/evmone_precompiles/ecc.hpp |
Updates elliptic-curve arithmetic usage. |
lib/evmone_precompiles/secp256r1.cpp |
Updates signature verification usage. |
lib/evmone_precompiles/expmod.tmpl |
Updates the generated function signature. |
test/unittests/modarith_test.cpp |
Updates modular arithmetic tests. |
test/unittests/secp256k1_test.cpp |
Updates scalar inversion tests. |
test/internal_benchmarks/modarith_bench.cpp |
Updates benchmark usage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1666 +/- ##
=======================================
Coverage 97.72% 97.72%
=======================================
Files 171 171
Lines 15636 15636
Branches 3616 3616
=======================================
Hits 15280 15280
Misses 269 269
Partials 87 87
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.
ModArithimplements one specific algorithm, so it is named after that algorithm. Arithmeticskeeping the values in other representations are coming — the pseudo-Mersenne reduction for
secp256k1 works in the plain representation — and they will not be Montgomery.
For the same reason
to_mont()/from_mont()becometo_internal()/from_internal(): theMontgomery form is an implementation detail of this one arithmetic rather than something its users
need to name. In an arithmetic using the plain representation both conversions are identity.
Verified no-op
The modulus stays a runtime member, so nothing about the generated code should move. Comparing the
linked
evmone-precompiles-benchbefore and after:.textThe next step in the series, which makes the modulus a template parameter, changes 57 function sizes
by comparison. Keeping the rename separate is what makes that measurable.