fix: validate signature in signedPrefixedMessageToKey to prevent incorrect address recovery#2277
Open
Dev10-sys wants to merge 1 commit intoLFDT-web3j:mainfrom
Open
Conversation
signedPrefixedMessageToKey previously delegated directly to signedMessageHashToKey without any validation of the signature components. This allowed malleable signatures (where s > n/2) to produce a valid-looking but incorrect address recovery. Add a check that rejects signatures where s is in the upper half of the curve order, as required by EIP-2 and Bitcoin strict-DER encoding rules. Invalid or corrupted signature components that prevent key recovery continue to throw SignatureException through the existing path. Move SignValidationTest to the crypto module where Sign.java lives, and add targeted tests for: valid signatures, malleable-s rejection, and high-s rejection. Fixes LFDT-web3j#1989 Signed-off-by: Dev10-sys <kalpanagola9897@gmail.com>
8dfaf09 to
8499971
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.
Fixes an issue where signedPrefixedMessageToKey could return an incorrect address when given invalid signatures or mismatched messages.
Previously, invalid inputs could still produce a valid-looking address without proper verification.
This change adds full signature validation, ensuring that incorrect or tampered signatures throw an error instead of returning a random address.
Tests are added to cover invalid, corrupted, and malleable signature cases.
Fixes #1989