fix(id): flip recovery id for normalized ECDSA signatures - #4036
Open
Kewe63 wants to merge 1 commit into
Open
Conversation
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.
Summary
Fixes #4035
to_lower_s()normalized high-s ECDSA signatures to low-s form but kept the original recovery id byte unchanged.For recoverable ECDSA signatures, changing
sto its low-s equivalent also requires flipping the recovery id y-parity bit. Otherwise the normalized signature can recover a different Ethereum signer address.Changes
normalize_s()changess.How to Test
Note:
cargo test -p xmtp_idwas also attempted. It passed 39 tests and failed 3 SCW verifier tests because no local RPC/anvil service was listening on127.0.0.1:8545. The failures appear unrelated to this signature normalization change.Checklist
cargo fmtcleanRisk & Impact
Low-to-medium. The fix only changes behavior for high-s signatures that require normalization — the recovery id flip is applied exactly when
normalize_s()changess, so low-s signatures are unaffected. The regression test verifies the normalized signature still recovers the original signer address.Type: 🐛 Bug fix
Fixes: #4035
Note
Fix
to_lower_sto flip recovery id y-parity for normalized ECDSA signaturesto_lower_snormalizes a high-s ECDSA signature to low-s, it now flips the appended recovery id using the newflip_recovery_id_y_parityhelper so the correct signer can still be recovered.SignatureError::Invalidon invalid inputs or arithmetic overflow.u8::MAX,to_lower_smay now returnSignatureError::Invaliddue to overflow where it previously succeeded with an unmodified recovery id.Macroscope summarized 72dbb7c.