Skip to content

BOLT 12: Validate bech32 padding per BIP-173#4349

Merged
TheBlueMatt merged 1 commit intolightningdevkit:mainfrom
vincenzopalazzo:macros/bolt12-invalid-padding-test-vector
Jan 26, 2026
Merged

BOLT 12: Validate bech32 padding per BIP-173#4349
TheBlueMatt merged 1 commit intolightningdevkit:mainfrom
vincenzopalazzo:macros/bolt12-invalid-padding-test-vector

Conversation

@vincenzopalazzo
Copy link
Contributor

Summary

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."

Previously, LDK would accept offers with invalid bech32 padding, while other implementations (Lightning-kmp, Eclair) correctly reject them. This was identified through differential fuzzing across Lightning implementations.

Changes

  • Call validate_segwit_padding() from the bech32 crate during offer parsing
  • Add new InvalidPadding error variant to Bolt12ParseError
  • Add test vector from the BOLT specification for invalid padding

References

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jan 26, 2026

I've assigned @joostjager as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@vincenzopalazzo vincenzopalazzo force-pushed the macros/bolt12-invalid-padding-test-vector branch from 05d2d4b to 051e3d1 Compare January 26, 2026 19:00
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>
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.08%. Comparing base (3fee76b) to head (cea1c72).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/offers/offer.rs 50.00% 0 Missing and 1 partial ⚠️
lightning/src/offers/parse.rs 90.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4349   +/-   ##
=======================================
  Coverage   86.08%   86.08%           
=======================================
  Files         156      156           
  Lines      102416   102428   +12     
  Branches   102416   102428   +12     
=======================================
+ Hits        88165    88180   +15     
+ Misses      11759    11756    -3     
  Partials     2492     2492           
Flag Coverage Δ
tests 86.08% <83.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

thanks

@TheBlueMatt TheBlueMatt merged commit 9e91b2e into lightningdevkit:main Jan 26, 2026
20 of 21 checks passed
@vincenzopalazzo vincenzopalazzo deleted the macros/bolt12-invalid-padding-test-vector branch January 27, 2026 09:00
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.

3 participants