Skip to content

crypto: Rename ModArith to MontgomeryArith - #1666

Open
chfast wants to merge 1 commit into
masterfrom
crypto/montgomery-arith-rename
Open

crypto: Rename ModArith to MontgomeryArith#1666
chfast wants to merge 1 commit into
masterfrom
crypto/montgomery-arith-rename

Conversation

@chfast

@chfast chfast commented Aug 20, 2026

Copy link
Copy Markdown
Member

ModArith implements one specific algorithm, so it is named after that algorithm. Arithmetics
keeping the values in other representations are coming — the pseudo-Mersenne reduction for
secp256k1 works in the plain representation — and they will not be Montgomery.

For the same reason to_mont()/from_mont() become to_internal()/from_internal(): the
Montgomery form is an implementation detail of this one arithmetic rather than something its users
need to name. In an arithmetic using the plain representation both conversions are identity.

Verified no-op

The modulus stays a runtime member, so nothing about the generated code should move. Comparing the
linked evmone-precompiles-bench before and after:

master this PR
.text 798,617 798,617
defined symbols 1,683 1,683
multiset of function sizes identical

The next step in the series, which makes the modulus a template parameter, changes 57 function sizes
by comparison. Keeping the rename separate is what makes that measurable.

The class implements one specific algorithm, so name it after that
algorithm: arithmetics keeping the values in other representations are
coming, and they will not be Montgomery. For the same reason the
conversions become to_internal() and from_internal(), because the
Montgomery form is an implementation detail of this one arithmetic
rather than something its users need to name.

The generated code is unchanged.
@codspeed-hq

codspeed-hq Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 129 untouched benchmarks


Comparing crypto/montgomery-arith-rename (c2d6511) with master (9344010)

Open in CodSpeed

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

Renames the modular arithmetic implementation to reflect its Montgomery algorithm while abstracting its internal representation.

Changes:

  • Renames ModArith to MontgomeryArith.
  • Renames conversion methods to to_internal() and from_internal().
  • Updates all affected consumers, tests, benchmarks, and templates.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/evmone_precompiles/modarith.hpp Renames the class and conversion API.
lib/evmone_precompiles/ecc.hpp Updates elliptic-curve arithmetic usage.
lib/evmone_precompiles/secp256r1.cpp Updates signature verification usage.
lib/evmone_precompiles/expmod.tmpl Updates the generated function signature.
test/unittests/modarith_test.cpp Updates modular arithmetic tests.
test/unittests/secp256k1_test.cpp Updates scalar inversion tests.
test/internal_benchmarks/modarith_bench.cpp Updates benchmark usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.05128% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.72%. Comparing base (9344010) to head (c2d6511).

Files with missing lines Patch % Lines
test/unittests/modarith_test.cpp 69.56% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1666   +/-   ##
=======================================
  Coverage   97.72%   97.72%           
=======================================
  Files         171      171           
  Lines       15636    15636           
  Branches     3616     3616           
=======================================
  Hits        15280    15280           
  Misses        269      269           
  Partials       87       87           
Flag Coverage Δ
eest-develop 88.60% <100.00%> (ø)
eest-develop-gmp 26.56% <20.51%> (ø)
eest-legacy 17.14% <0.00%> (ø)
eest-libsecp256k1 28.83% <20.51%> (ø)
eest-stable 88.60% <100.00%> (ø)
evmone-unittests 93.44% <82.05%> (ø)

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

Components Coverage Δ
core 96.11% <100.00%> (ø)
tooling 91.92% <ø> (ø)
tests 99.80% <73.07%> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/ecc.hpp 97.24% <100.00%> (ø)
lib/evmone_precompiles/modarith.hpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/secp256r1.cpp 100.00% <100.00%> (ø)
test/unittests/secp256k1_test.cpp 100.00% <100.00%> (ø)
test/unittests/modarith_test.cpp 89.04% <69.56%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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