Skip to content

crypto: Add non-malleable secp256k1 ecrecover mode - #1612

Merged
chfast merged 1 commit into
masterfrom
crypto/ecrecover_strict
Jul 26, 2026
Merged

crypto: Add non-malleable secp256k1 ecrecover mode#1612
chfast merged 1 commit into
masterfrom
crypto/ecrecover_strict

Conversation

@chfast

@chfast chfast commented Jul 26, 2026

Copy link
Copy Markdown
Member

Extend the secp256k1::ecrecover function with RecoveryMode param. The current behavior matches malleable mode where full range of the s value is accepted. The new mode strict only allows s values from (0, ORDER/2]. See EIP-2.

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 extends the evmmax::secp256k1 signer recovery API with an explicit RecoveryMode, enabling an opt-in EIP-2 “low-s” (non-malleable) recovery path while keeping the current behavior as the default.

Changes:

  • Introduces RecoveryMode and threads it through secp256k1_ecdsa_recover() and ecrecover() (defaulting to malleable for ecrecover()).
  • Implements strict low-s validation by adding an optional “lower-half” bound in ecc::FieldElement::from_bytes.
  • Adds unit coverage to verify strict recovery rejects high-s signatures while matching existing outputs for low-s cases.

Reviewed changes

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

File Description
test/unittests/evmmax_secp256k1_test.cpp Splits malleable vs strict recovery tests and validates strict low-s behavior against existing vectors.
lib/evmone_precompiles/secp256k1.hpp Adds RecoveryMode and updates the public recovery APIs to accept the mode.
lib/evmone_precompiles/secp256k1.cpp Enforces strict mode by parsing s with a lower-half constraint when requested.
lib/evmone_precompiles/ecc.hpp Extends FieldElement::from_bytes with an optional lower-half upper bound used by strict recovery.

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

Comment thread test/unittests/evmmax_secp256k1_test.cpp
Comment thread lib/evmone_precompiles/ecc.hpp Outdated
Comment thread lib/evmone_precompiles/secp256k1.hpp Outdated
Comment thread lib/evmone_precompiles/secp256k1.hpp
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.38%. Comparing base (83d2c6f) to head (eed696a).

Files with missing lines Patch % Lines
lib/evmone_precompiles/ecc.hpp 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1612      +/-   ##
==========================================
- Coverage   97.39%   97.38%   -0.01%     
==========================================
  Files         164      164              
  Lines       14764    14789      +25     
  Branches     3400     3411      +11     
==========================================
+ Hits        14379    14403      +24     
  Misses        281      281              
- Partials      104      105       +1     
Flag Coverage Δ
eest-develop 89.37% <50.00%> (-0.05%) ⬇️
eest-develop-gmp 25.96% <10.71%> (-0.05%) ⬇️
eest-legacy 17.42% <0.00%> (-0.03%) ⬇️
eest-libsecp256k1 27.58% <3.57%> (-0.05%) ⬇️
eest-stable 89.33% <50.00%> (-0.05%) ⬇️
evmone-unittests 92.68% <96.42%> (+<0.01%) ⬆️

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

Components Coverage Δ
core 95.89% <83.33%> (-0.02%) ⬇️
tooling 90.32% <ø> (ø)
tests 99.80% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
lib/evmone_precompiles/secp256k1.cpp 100.00% <100.00%> (ø)
test/unittests/evmmax_secp256k1_test.cpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/ecc.hpp 97.24% <50.00%> (-0.45%) ⬇️
🚀 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/ecrecover_strict branch from 1107d75 to e1197a8 Compare July 26, 2026 11:35
Extend the secp256k1::ecrecover function with RecoveryMode param.
The current behavior matches `malleable` mode where full range
of the s value is accepted. The new mode `strict` only allows s values
from (0, ORDER/2]. See EIP-2.

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

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

@chfast
chfast merged commit bcefc4f into master Jul 26, 2026
23 of 24 checks passed
@chfast
chfast deleted the crypto/ecrecover_strict branch July 26, 2026 12: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