common/bolt11: Fix BOLT11 hash calculation for unknown fallback address versions #8302
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.
When processing BOLT11 invoices containing unknown fallback address versions (discovered using bitcoinfuzz differential fuzzing), the hash calculation produces different results across Lightning implementations (Lnd vs CLightning):
The example invoice is decoded differently by Lnd and CLightning.
This results in different recipient pubkeys:
LND:
03027be81b41bdfda1ded1f4e0dd5a997635ad325a6e119f414a92fe78c86a45cf
CLightning:
03e6b1f437d1984a58e4192289e8e0f21e2bbcd863dc43374037e61621abb8d1de
The difference occurs in the hash calculation which affects signature verification.
Root Cause
The issue occurs in the fallback address processing (
decode_f
function). When an unknown version is encountered in the fallback address field, the current implementation incorrectly includes the version bytes in the hash calculation before determining whether it's a known or unknown version. Then, when delegating to theunknown_field
handler, the version bytes get included in the hash calculation a second time, resulting in inconsistent hash values across implementations.Solution
The fix separates the version reading from the hash commitment:
unknown_field
handlerCI Failure Details
The issue was caught by bitcoinfuzz in CI with the following error:
See full details at: https://github.com/bitcoinfuzz/bitcoinfuzz/actions/runs/15113684421/job/42478878043#step:33:58