Skip to content

crypto: Extract modexp_even()#1413

Merged
chfast merged 1 commit into
masterfrom
crypto/modexp_even_extract
Dec 22, 2025
Merged

crypto: Extract modexp_even()#1413
chfast merged 1 commit into
masterfrom
crypto/modexp_even_extract

Conversation

@chfast

@chfast chfast commented Dec 22, 2025

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

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 extracts the modular exponentiation logic for even moduli into a separate modexp_even() function, improving code organization and reusability. The extraction follows the same pattern as the existing modexp_odd() and modexp_pow2() helper functions.

Key changes:

  • Extracted inline even-modulus logic from modexp_impl() into a new modexp_even() template function
  • Simplified the modexp_impl() function by replacing ~20 lines of inline code with a single function call
  • Added documentation referencing the Montgomery reduction algorithm paper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/evmone_precompiles/modexp.cpp Outdated
{
// Follow "Montgomery reduction with even modulus" by Çetin Kaya Koç.
// https://cetinkayakoc.net/docs/j34.pdf
assert(k != 0);

Copilot AI Dec 22, 2025

Copy link

Choose a reason for hiding this comment

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

Consider adding an explanatory comment for the assertion, similar to the one in modexp_pow2 at line 77. This would clarify why k must be non-zero and improve code consistency.

Suggested change
assert(k != 0);
assert(k != 0); // k must be non-zero because the modulus has the form mod_odd * 2^k with k > 0; k == 0 is handled by the odd-modulus path.

Copilot uses AI. Check for mistakes.
@chfast chfast force-pushed the crypto/modexp_even_extract branch from 6bf47cf to 9be8a68 Compare December 22, 2025 17:32
@codecov

codecov Bot commented Dec 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.67%. Comparing base (6d91420) to head (e66a260).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1413      +/-   ##
==========================================
+ Coverage   78.93%   81.67%   +2.74%     
==========================================
  Files         151      152       +1     
  Lines       13543    13566      +23     
  Branches     3216     3217       +1     
==========================================
+ Hits        10690    11080     +390     
+ Misses        574      343     -231     
+ Partials     2279     2143     -136     
Flag Coverage Δ
eest-develop 91.13% <100.00%> (?)
eest-develop-gmp 29.16% <100.00%> (?)
eest-legacy 15.35% <0.00%> (-0.01%) ⬇️
eest-legacy-silkpre 24.50% <85.71%> (+0.01%) ⬆️
evmone-unittests 76.21% <85.71%> (+<0.01%) ⬆️

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

Components Coverage Δ
core 94.42% <100.00%> (+6.89%) ⬆️
tooling 83.63% <ø> (+3.67%) ⬆️
tests 73.52% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/modexp.cpp 100.00% <100.00%> (+9.21%) ⬆️

... and 21 files 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_even_extract branch from 9be8a68 to e66a260 Compare December 22, 2025 18:28
@chfast chfast merged commit 89e3eca into master Dec 22, 2025
23 checks passed
@chfast chfast deleted the crypto/modexp_even_extract branch December 22, 2025 19:35
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