Skip to content

crypto: Use exact size for x1 in modexp_even CRT#1465

Merged
chfast merged 1 commit intomasterfrom
crypto/modexp_result_size
Mar 9, 2026
Merged

crypto: Use exact size for x1 in modexp_even CRT#1465
chfast merged 1 commit intomasterfrom
crypto/modexp_result_size

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented Mar 9, 2026

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.

@chfast chfast force-pushed the crypto/modexp_result_size branch from 120143f to aa0fb5a Compare March 9, 2026 18:29
@chfast chfast requested a review from Copilot March 9, 2026 18:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in modexp.cpp to accept x.size() >= y.size() and propagate carry/borrow through remaining high words of x.
  • Shrink modexp_even() temporary x1 buffer from r.size() words to mod_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^k factor 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
Copy link
Copy Markdown

codecov Bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.85%. Comparing base (3defcdc) to head (c6033d1).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
lib/evmone_precompiles/modexp.cpp 94.11% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
eest-develop 92.67% <94.11%> (-0.02%) ⬇️
eest-develop-gmp 27.81% <0.00%> (-0.02%) ⬇️
eest-legacy 15.84% <0.00%> (+0.72%) ⬆️
eest-libsecp256k1 29.13% <80.00%> (+<0.01%) ⬆️
evmone-unittests 91.58% <95.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 98.97% <94.11%> (+3.08%) ⬆️
tooling 85.03% <ø> (ø)
tests 99.78% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
test/unittests/precompiles_expmod_test.cpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/modexp.cpp 99.25% <94.11%> (-0.37%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chfast chfast force-pushed the crypto/modexp_result_size branch from aa0fb5a to 8d49138 Compare March 9, 2026 19:25
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.
@chfast chfast force-pushed the crypto/modexp_result_size branch from 8d49138 to c6033d1 Compare March 9, 2026 20:47
@chfast chfast merged commit af912df into master Mar 9, 2026
21 checks passed
@chfast chfast deleted the crypto/modexp_result_size branch March 9, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants