Skip to content

Reject non-canonical bech32 in Cosmos and Cardano addresses - #1959

Merged
gemcoder21 merged 1 commit into
mainfrom
hm/bech32-padding
Nov 18, 2026
Merged

gemcoder21 merged 1 commit into
mainfrom
hm/bech32-padding

Conversation

@0xh3rman

Copy link
Copy Markdown
Collaborator

Why: Follow-up to #1957. The Cosmos and Cardano address parsers used bech32::decode, which drops leftover padding bits without checking them. A Cosmos address with one extra padding character and a valid checksum passed validation as the same 20-byte address, and a Cardano address with non-zero padding bits in its last character passed as the same address. No funds are at risk, since both decode to the same bytes, but the non-canonical forms should be rejected.

What changed: Both parsers validate the padding before converting the payload to bytes. They also now accept only the Bech32 checksum; bech32::decode accepted Bech32m as well, which neither chain uses.

Proof: New test cases reject a padded Cosmos address, a Bech32m Cosmos address, and a Cardano address with non-zero padding. All three were accepted before the change. Existing valid-address tests still pass.

@gemcoder21 gemcoder21 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: both parsers now reject non-canonical padding and Bech32m, and a real 103-character Cardano address still parses on the new path.

@gemcoder21
gemcoder21 merged commit 26f7fd3 into main Nov 18, 2026
7 checks passed
@gemcoder21
gemcoder21 deleted the hm/bech32-padding branch November 18, 2026 17:45
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