crypto: Use exact size for x1 in modexp_even CRT#1465
Conversation
120143f to
aa0fb5a
Compare
There was a problem hiding this comment.
Pull request overview
This PR reduces temporary storage in the even-modulus CRT path of the expmod precompile by sizing the x1 (odd-part result) buffer to the odd modulus size and updating internal word-wise add/sub helpers to support unequal operand lengths needed by this optimization.
Changes:
- Allow
add()/sub()helpers inmodexp.cppto acceptx.size() >= y.size()and propagate carry/borrow through remaining high words ofx. - Shrink
modexp_even()temporaryx1buffer fromr.size()words tomod_odd.size()words and adjust subtraction accordingly. - Add a unit test vector covering an even modulus with 1-word odd part and multi-word
2^kfactor to exercise carry/borrow propagation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/evmone_precompiles/modexp.cpp |
Reduces temp allocation in modexp_even() and updates add/sub helpers to handle shorter RHS operands with correct carry/borrow propagation. |
test/unittests/precompiles_expmod_test.cpp |
Adds a regression test vector targeting the shortened-operand add/sub behavior in the even-modulus CRT path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1465 +/- ##
==========================================
+ Coverage 96.82% 97.85% +1.03%
==========================================
Files 152 152
Lines 14050 14057 +7
Branches 3246 3248 +2
==========================================
+ Hits 13604 13756 +152
+ Misses 306 160 -146
- Partials 140 141 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
aa0fb5a to
8d49138
Compare
Shrink the x1 (odd-part result) buffer from r.size() to mod_odd.size() words, reducing temporary storage. Relax add/sub to handle shorter y operand with carry/borrow propagation through remaining high words.
8d49138 to
c6033d1
Compare
Shrink the x1 (odd-part result) buffer from r.size() to mod_odd.size() words, reducing temporary storage. Relax add/sub to handle shorter y operand with carry/borrow propagation through remaining high words.