crypto: Add non-malleable secp256k1 ecrecover mode - #1612
Merged
Conversation
There was a problem hiding this comment.
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
RecoveryModeand threads it throughsecp256k1_ecdsa_recover()andecrecover()(defaulting tomalleableforecrecover()). - 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.
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
chfast
force-pushed
the
crypto/ecrecover_strict
branch
from
July 26, 2026 11:35
1107d75 to
e1197a8
Compare
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.
chfast
force-pushed
the
crypto/ecrecover_strict
branch
from
July 26, 2026 12:13
e1197a8 to
eed696a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extend the secp256k1::ecrecover function with RecoveryMode param. The current behavior matches
malleablemode where full range of the s value is accepted. The new modestrictonly allows s values from (0, ORDER/2]. See EIP-2.