Skip to content

crypto: Use variadic-length modinv in modexp#1434

Merged
chfast merged 1 commit intomasterfrom
crypto/modexp_modinv_dyn
Feb 5, 2026
Merged

crypto: Use variadic-length modinv in modexp#1434
chfast merged 1 commit intomasterfrom
crypto/modexp_modinv_dyn

Conversation

@chfast
Copy link
Member

@chfast chfast commented Feb 3, 2026

Replace the modular inversion with mod 2ᵏ which uses fixed size intx::uint to one which uses variadic-length numbers represented by std::span<uint64_t>.
This improves performance in pathological cases when the 2ᵏ part of the modexp modulus is significant shorter than the modulus itself.

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.52%. Comparing base (2c62685) to head (5dc11af).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1434   +/-   ##
=======================================
  Coverage   96.51%   96.52%           
=======================================
  Files         152      152           
  Lines       13805    13828   +23     
  Branches     3223     3225    +2     
=======================================
+ Hits        13324    13347   +23     
  Misses        342      342           
  Partials      139      139           
Flag Coverage Δ
eest-develop 92.09% <100.00%> (+0.04%) ⬆️
eest-develop-gmp 29.15% <100.00%> (+0.12%) ⬆️
eest-legacy 15.33% <0.00%> (-0.03%) ⬇️
eest-legacy-silkpre 24.66% <100.00%> (+0.12%) ⬆️
evmone-unittests 91.25% <100.00%> (+0.01%) ⬆️

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

Components Coverage Δ
core 94.91% <100.00%> (+0.02%) ⬆️
tooling 85.28% <ø> (ø)
tests 99.77% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/modexp.cpp 100.00% <100.00%> (ø)
🚀 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_modinv_dyn branch from f2285ac to 72de6b7 Compare February 3, 2026 17:15
@chfast chfast marked this pull request as ready for review February 3, 2026 17:15
Copilot AI review requested due to automatic review settings February 3, 2026 17:15
Copy link

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 pull request refactors the modular inversion function in the modular exponentiation implementation to use variable-length operands via spans instead of fixed-size template types.

Changes:

  • Adds two new helper functions: mul() for truncated multiplication and neg_add2() for computing 2 - x
  • Converts modinv_pow2() from a template function to a span-based function for variable-length operations
  • Updates the call site in modexp_even() to use the new span-based interface

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

Copy link

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


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

@chfast chfast force-pushed the crypto/modexp_modinv_dyn branch 2 times, most recently from f4b9c6c to dacd4d0 Compare February 5, 2026 18:02
@chfast chfast requested a review from Copilot February 5, 2026 18:03
Copy link

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


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

@chfast chfast force-pushed the crypto/modexp_modinv_dyn branch from dacd4d0 to 5dc11af Compare February 5, 2026 18:19
@chfast chfast merged commit dd55876 into master Feb 5, 2026
23 checks passed
@chfast chfast deleted the crypto/modexp_modinv_dyn branch February 5, 2026 18:30
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