crypto: Compute modexp base_mont using var-length division#1457
crypto: Compute modexp base_mont using var-length division#1457
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1457 +/- ##
==========================================
+ Coverage 96.80% 96.82% +0.01%
==========================================
Files 152 152
Lines 13934 14005 +71
Branches 3238 3245 +7
==========================================
+ Hits 13489 13560 +71
Misses 306 306
Partials 139 139
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 refactors the odd-modulus modular exponentiation path to compute the Montgomery-form base using a new span-based remainder routine, avoiding the previous fixed doubled-width intx::uint<N*2> conversion.
Changes:
- Added a new dynamic-word
mod()helper to compute remainder usingintx::internaldivision primitives. - Split the previous odd-modexp template into
modexp_odd_mont()(expects Montgomery base) and a new Montgomery-base conversion step usingmod(). - Extended expmod unit tests with vectors intended to cover dispatch-width cases where
n != N.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lib/evmone_precompiles/modexp.cpp |
Introduces span-based remainder routine and rewires modexp_odd() to compute base_mont without doubled-width intx integers. |
test/unittests/precompiles_expmod_test.cpp |
Adds test vectors to exercise odd-modulus dispatch-width coverage cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e605a78 to
0f5a8b0
Compare
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace fixed-width intx::udivrem with span-based mod_rem() for computing the Montgomery form of the base in modexp_odd. The mod_rem function reuses intx's internal division primitives (udivrem_by1, udivrem_by2, udivrem_knuth) operating on dynamic word spans. The modexp_odd_fixed_size template is split into modexp_odd_mont (which takes a pre-computed base_mont) and the base_mont computation via mod_rem. This removes the need for doubled-width intx types (uint<N*2>) for the base conversion step.
da801fe to
5f1551b
Compare
Replace fixed-width intx::udivrem with span-based mod_rem() for computing
the Montgomery form of the base in modexp_odd. The mod_rem function reuses
intx's internal division primitives (udivrem_by1, udivrem_by2, udivrem_knuth)
operating on dynamic word spans.
The modexp_odd_fixed_size template is split into modexp_odd_mont (which takes
a pre-computed base_mont) and the base_mont computation via mod_rem.
This removes the need for doubled-width intx types (uint<N*2>) for the
base conversion step.