lightningd: use BIP86 derivation in p2wpkh_for_keyidx when available
What changed, and why it matters
This change fixes a wallet bug in Core Lightning. When closing a payment channel with a peer that only supports older Bitcoin address formats, the software was deriving the refund address using the wrong key path for modern BIP86 wallets. After a restart, the wallet might not recognize those funds because it looks for keys at the BIP86 path. The patch makes the fallback address use the same derivation method as modern Taproot addresses, so the wallet can always find the funds.
Treat as a bug-fix patch with low-to-moderate operational/financial risk. Users relying on BIP86 wallets should upgrade to avoid potential unrecognizable channel-close outputs. No emergency response is indicated; no remote exploit vector is present.
Security signals we found
Funds-recovery/wallet-recognition bug in channel close fallback path
Incorrect key derivation path for BIP86 wallets
No cryptographic weakness or remote exploit introduced
Evidence from the diff
In p2wpkh_for_keyidx(), used when a peer does not support OPT_SHUTDOWN_ANYSEGWIT and the local node falls back to a P2WPKH shutdown script, the code previously always called bip32_pubkey() regardless of wallet type. For BIP86-based wallets, this produces a public key at a different derivation path than the one the wallet tracks for on-chain discovery (p2tr_for_keyidx uses bip86_pubkey). The patch adds a conditional: if ld->bip86_base is set, derive with bip86_pubkey(); otherwise retain the legacy bip32_pubkey() behavior. This ensures the shutdown P2WPKH output is spendable/recognizable after restart for BIP86 wallets.
Changed components
lightningd/peer_control.cChannel shutdown P2WPKH fallback pathBIP86 wallet key derivationInspect captured patch +6 / −1
diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c
index ebc8cfa7..1e9dfa0d 100644
--- a/lightningd/peer_control.c
+++ b/lightningd/peer_control.c
@@ -203,7 +203,12 @@ u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx)
{
struct pubkey shutdownkey;
- bip32_pubkey(ld, &shutdownkey, keyidx);
+ /* Use BIP86 derivation if wallet has BIP86 base, otherwise use BIP32 */
+ if (ld->bip86_base) {
+ bip86_pubkey(ld, &shutdownkey, keyidx);
+ } else {
+ bip32_pubkey(ld, &shutdownkey, keyidx);
+ }
return scriptpubkey_p2wpkh(ctx, &shutdownkey);
}
Why this scored 31/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.