common/bolt11: Fix BOLT11 hash calculation for unknown fallback address versions#8302
Merged
rustyrussell merged 1 commit intoElementsProject:masterfrom Sep 4, 2025
Conversation
be3f15d to
8848b69
Compare
a02fa9c to
c2f0aad
Compare
…ss versions Changelog-Fixed: Fixed hash calculation inconsistency when processing invoices with unknown fallback address versions.
c2f0aad to
c86a5a2
Compare
Contributor
Author
|
Friendly ping @rustyrussell. the invoice can no longer be decoded since the payment secret is now required. However, we can still replicate the issue by removing the check for the payment secret. I made 2 branches to test this behavior: In this branch, I modified run-bolt11 to print the recipient key and removed the payment secret check to allow decoding the invoice: This second branch is the same as the one above, but it also includes a fix that correctly calculates the hash for unknown fallback versions, resulting in the correct recipient pubkey being printed: |
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.
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:
03027be81b41bdfda1ded1f4e0dd5a997635ad325a6e119f414a92fe78c86a45cfCLightning:
03e6b1f437d1984a58e4192289e8e0f21e2bbcd863dc43374037e61621abb8d1deThe difference occurs in the hash calculation which affects signature verification.
Root Cause
The issue occurs in the fallback address processing (
decode_ffunction). 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_fieldhandler, 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_fieldhandlerCI 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