Skip to content

fix: validate signature in signedPrefixedMessageToKey to prevent incorrect address recovery#2277

Open
Dev10-sys wants to merge 1 commit intoLFDT-web3j:mainfrom
Dev10-sys:fix/signed-prefixed-message-validation
Open

fix: validate signature in signedPrefixedMessageToKey to prevent incorrect address recovery#2277
Dev10-sys wants to merge 1 commit intoLFDT-web3j:mainfrom
Dev10-sys:fix/signed-prefixed-message-validation

Conversation

@Dev10-sys
Copy link
Copy Markdown
Contributor

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

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>
@Dev10-sys Dev10-sys force-pushed the fix/signed-prefixed-message-validation branch from 8dfaf09 to 8499971 Compare April 29, 2026 04:14
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.

Incorrect address returned from signedPrefixedMessageToKey when invalid data passed in

1 participant