Skip to content

test: Add modular inversion tests - #1812

Merged
chfast merged 1 commit into
masterfrom
test/modinv
Nov 9, 2026
Merged

chfast merged 1 commit into
masterfrom
test/modinv

Conversation

@chfast

@chfast chfast commented Nov 9, 2026

Copy link
Copy Markdown
Member

The modular inversion is tested through ModArith::inv() on a few values
for each modulus, and through the curve precompiles, whose inversions
see random-looking Montgomery forms.

Test inv() on random values also for the orders of secp256k1 and P-256
and the P-256 prime, telling the non-invertible values of 2^256 - 1 by
its prime factors. Test modinv_scaled() on small values, on values near
powers of 2, and on the inputs needing the most divsteps of the safegcd
algorithm found for 256 and 384 bits. Add bn254 addition, ecrecover
and p256verify vectors whose inversions start from 2^211 or need the
most divsteps found for their modulus.

The tests come from the safegcd inversion (#1806) and pass with the
current binary GCD.

The modular inversion is tested through ModArith::inv() on a few values
for each modulus, and through the curve precompiles, whose inversions
see random-looking Montgomery forms.

Test inv() on random values also for the orders of secp256k1 and P-256
and the P-256 prime, telling the non-invertible values of 2^256 - 1 by
its prime factors. Test modinv_scaled() on small values, on values near
powers of 2, and on the inputs needing the most divsteps of the safegcd
algorithm found for 256 and 384 bits. Add bn254 addition, ecrecover
and p256verify vectors whose inversions start from 2^211 or need the
most divsteps found for their modulus.

The tests come from the safegcd inversion (#1806) and pass with the
current binary GCD.
@codspeed

codspeed Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 899 untouched benchmarks


Comparing test/modinv (92febed) with master (b54d323)

Open in CodSpeed

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.23%. Comparing base (b54d323) to head (92febed).

Files with missing lines Patch % Lines
test/unittests/modarith_test.cpp 96.07% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1812      +/-   ##
==========================================
- Coverage   98.23%   98.23%   -0.01%     
==========================================
  Files         186      186              
  Lines       17144    17192      +48     
  Branches     3950     3963      +13     
==========================================
+ Hits        16842    16888      +46     
- Misses        233      235       +2     
  Partials       69       69              
Flag Coverage Δ
eest-develop-gmp 26.75% <0.00%> (-0.08%) ⬇️
eest-legacy 17.21% <0.00%> (-0.05%) ⬇️
eest-libsecp256k1 28.72% <0.00%> (-0.09%) ⬇️
eest-stable 83.74% <ø> (ø)
evmone-unittests 93.94% <96.07%> (+<0.01%) ⬆️
riscv64 94.81% <90.19%> (-0.01%) ⬇️

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

Components Coverage Δ
core 96.60% <ø> (ø)
tooling 94.87% <ø> (ø)
tests 99.80% <96.07%> (-0.02%) ⬇️
Files with missing lines Coverage Δ
test/unittests/bn254_add_test.cpp 100.00% <ø> (ø)
test/unittests/precompiles_secp256r1_test.cpp 100.00% <ø> (ø)
test/unittests/secp256k1_test.cpp 100.00% <ø> (ø)
test/unittests/modarith_test.cpp 91.73% <96.07%> (+2.69%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chfast
chfast merged commit 6fb712f into master Nov 9, 2026
30 of 32 checks passed
@chfast
chfast deleted the test/modinv branch November 9, 2026 21:52
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.

1 participant