Skip to content

Comments

BOLT 12: add test vector for invalid bech32 padding#1312

Open
erickcestari wants to merge 1 commit intolightning:masterfrom
erickcestari:add-test-vector-bech32-padding
Open

BOLT 12: add test vector for invalid bech32 padding#1312
erickcestari wants to merge 1 commit intolightning:masterfrom
erickcestari:add-test-vector-bech32-padding

Conversation

@erickcestari
Copy link
Contributor

Closes #1281

Differential fuzzing across Lightning implementations revealed inconsistent handling of bech32 padding. Some implementations (Lightning-kmp, Eclair) enforce BIP-173's 4-bit padding constraint while others (CLN, LDK) do not.

Add test vector to clarify that offers with invalid padding must be rejected per BIP-173 rules.

Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

ACK d5d1e65, this test vector passes in eclair.

t-bast added a commit to ACINQ/eclair that referenced this pull request Jan 19, 2026
t-bast added a commit to ACINQ/eclair that referenced this pull request Jan 19, 2026
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 26, 2026
Add validation for bech32 padding in BOLT 12 offer parsing per BIP-173
which states: "Any incomplete group at the end MUST be 4 bits or less,
MUST be all zeroes, and is discarded."

This adds a test vector from the BOLT specification that ensures offers
with invalid padding (exceeding the 4-bit limit) are properly rejected.

Previously, LDK would accept offers with invalid bech32 padding. This
was identified through differential fuzzing across Lightning
implementations (see lightning/bolts#1312).

The fix calls `validate_segwit_padding()` from the bech32 crate during
offer parsing, and introduces a new `InvalidPadding` variant to
`Bolt12ParseError` to surface these errors.
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 26, 2026
Add validation for bech32 padding in BOLT 12 offer parsing per BIP-173
which states: "Any incomplete group at the end MUST be 4 bits or less,
MUST be all zeroes, and is discarded."

This adds a test vector from the BOLT specification that ensures offers
with invalid padding (exceeding the 4-bit limit) are properly rejected.

Previously, LDK would accept offers with invalid bech32 padding. This
was identified through differential fuzzing across Lightning
implementations (see lightning/bolts#1312).

The fix calls `validate_segwit_padding()` from the bech32 crate during
offer parsing, and introduces a new `InvalidPadding` variant to
`Bolt12ParseError` to surface these errors.
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 26, 2026
Add validation for bech32 padding in BOLT 12 offer parsing per BIP-173
which states: "Any incomplete group at the end MUST be 4 bits or less,
MUST be all zeroes, and is discarded."

This adds a test vector from the BOLT specification that ensures offers
with invalid padding (exceeding the 4-bit limit) are properly rejected.

Previously, LDK would accept offers with invalid bech32 padding. This
was identified through differential fuzzing across Lightning
implementations (see lightning/bolts#1312).

The fix calls `validate_segwit_padding()` from the bech32 crate during
offer parsing, and introduces a new `InvalidPadding` variant to
`Bolt12ParseError` to surface these errors.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

ACK d5d1e65

I reproduce and provide a fix in LDK lightningdevkit/rust-lightning#4349

Differential fuzzing across Lightning implementations revealed
inconsistent handling of bech32 padding. Some implementations
(Lightning-kmp, Eclair) enforce BIP-173's 4-bit padding constraint
while others (CLN, LDK) do not.

Add test vector to clarify that offers with invalid padding must
be rejected per BIP-173 rules.
@erickcestari erickcestari force-pushed the add-test-vector-bech32-padding branch from d5d1e65 to e35dcb0 Compare January 26, 2026 19:48
@erickcestari
Copy link
Contributor Author

Rebased

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.

BOLT 12: Inconsistent bech32 padding validation across implementations

3 participants