Skip to content

crypto: Use dynamic spans in modexp_odd and mul_amm#1462

Merged
chfast merged 1 commit into
masterfrom
crypto/modexp_fulldyn
Mar 3, 2026
Merged

crypto: Use dynamic spans in modexp_odd and mul_amm#1462
chfast merged 1 commit into
masterfrom
crypto/modexp_fulldyn

Conversation

@chfast

@chfast chfast commented Mar 3, 2026

Copy link
Copy Markdown
Member

Replace fixed-size template dispatch with runtime-sized std::span parameters. This merges modexp_odd_fixed_size() into modexp_odd() and simplifies mul_amm() to work with dynamic spans, eliminating the per-size template instantiations.

@codecov

codecov Bot commented Mar 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.82%. Comparing base (c38e254) to head (092bf46).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1462      +/-   ##
==========================================
- Coverage   96.83%   96.82%   -0.01%     
==========================================
  Files         152      152              
  Lines       14062    14035      -27     
  Branches     3249     3243       -6     
==========================================
- Hits        13617    13590      -27     
  Misses        306      306              
  Partials      139      139              
Flag Coverage Δ
eest-develop 92.66% <100.00%> (-0.05%) ⬇️
eest-develop-gmp 27.85% <0.00%> (+0.05%) ⬆️
eest-legacy 15.13% <0.00%> (+0.02%) ⬆️
eest-libsecp256k1 29.13% <94.44%> (-0.16%) ⬇️
evmone-unittests 91.59% <100.00%> (-0.02%) ⬇️

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

Components Coverage Δ
core 95.90% <100.00%> (-0.03%) ⬇️
tooling 85.03% <ø> (ø)
tests 99.78% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
lib/evmone_precompiles/modexp.cpp 100.00% <100.00%> (ø)
test/unittests/precompiles_expmod_test.cpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 refactors the modular exponentiation implementation to remove fixed-size template dispatch and instead operate on runtime-sized std::spans, simplifying the Montgomery multiplication/exponentiation path and reducing per-size instantiations.

Changes:

  • Replaced templated mul_amm<N> with a dynamic-span mul_amm(std::span<...>).
  • Merged fixed-size odd-modulus exponentiation into modexp_odd() using dynamic spans and shared scratch storage.
  • Added a regression test vector covering correct zeroing of trailing words for certain even-modulus cases.

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 Refactors Montgomery multiplication and odd-modulus modexp to use dynamic spans and shared scratch buffers.
test/unittests/precompiles_expmod_test.cpp Adds a regression test vector and updates a comment describing odd-modulus size coverage.

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

Comment thread lib/evmone_precompiles/modexp.cpp Outdated
Comment thread lib/evmone_precompiles/modexp.cpp
Replace fixed-size template dispatch with runtime-sized std::span
parameters. This merges modexp_odd_fixed_size() into modexp_odd()
and simplifies mul_amm() to work with dynamic spans, eliminating
the per-size template instantiations.
@chfast chfast force-pushed the crypto/modexp_fulldyn branch from 2e36672 to 092bf46 Compare March 3, 2026 13:57
@chfast chfast merged commit 009b544 into master Mar 3, 2026
23 checks passed
@chfast chfast deleted the crypto/modexp_fulldyn branch March 3, 2026 16:47
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