Merge pull request #11065 from SomberNight/202610_lnsymmetry_followups
What changed, and why it matters
This commit is a follow-up cleanup for Lightning Network (LN) channel configuration handling. It makes some stored fields optional, adds a warning comment about not storing a private key for certain channel types, and makes a database upgrade more robust by inlining a constant and adding a clearer error message if an old channel is missing required data. There is no direct fix for an active exploit or remote vulnerability in the diff itself.
Treat as routine maintenance/hardening. Review whether any existing code path actually stores local_payment_basepoint as a private key for static-remotekey channels; the comment suggests this must not happen. No urgent patch deployment is indicated by this commit alone, but users with old development channels should follow the provided downgrade/close guidance.
Security signals we found
Comment added warning that storing local_payment_basepoint as a private key for static-remotekey channels would, combined with xpub, expose the full on-chain wallet due to non-hardened BIP32 derivations.
Database migration made more self-contained by inlining DERIVED_LOCAL_BASEPOINTS to reduce future breakage.
Missing channel_seed now raises a clear WalletFileException instead of potentially failing silently or with a less informative error.
Stored LN fields made nullable, likely to accommodate incomplete backup/restored channel states.
Evidence from the diff
The patch modifies lnutil.py to allow current_commitment_signature, current_per_commitment_point, and next_per_commitment_point to be None in ChannelConfig, and adds a comment clarifying that for OPTION_STATIC_REMOTEKEY channels the local_payment_basepoint must not be a private key because it corresponds to a wallet change address derived via non-hardened BIP32, so leaking it plus the xpub would compromise the on-chain wallet. In wallet_db.py it adds a docstring about self-contained migrations, removes an import of DERIVED_LOCAL_BASEPOINTS, inlines that dict inside _convert_version_74, and adds a guard that raises WalletFileException if channel_seed is missing during upgrade. The changes are defensive and improve migration robustness and documentation, but do not patch a concrete remote-attack vector.
Changed components
electrum/lnutil.pyelectrum/wallet_db.pyLightning Network channel configuration serializationWallet database upgrade path version 74Inspect captured patch +28 / −5
### electrum/lnutil.py
@@ -155,13 +155,13 @@ class ChannelConfig(StoredObject):
announcement_bitcoin_sig: bytes
# signatures for this side's latest ctx and its htlc txs: for LOCAL, the ones the
# remote sent us; for REMOTE, the ones we sent them.
- current_commitment_signature: bytes
+ current_commitment_signature: bytes | None
current_htlc_signatures: bytes
# per-commitment points of this side's oldest unrevoked ctx, and of the next one.
# ours are derivable from the channel seed; we keep them so that both configs can be
# described, and sent to a peer that backs up our channel, in the same way.
- current_per_commitment_point: bytes
- next_per_commitment_point: bytes
+ current_per_commitment_point: bytes | None
+ next_per_commitment_point: bytes | None
def __post_init__(self):
# keypairs are stored as dicts, and bytes as hex
@@ -509,6 +509,8 @@ def to_bytes(self) -> bytes:
else:
assert len(self.local_payment_basepoint) == 33 # pubkey
assert self.channel_type == ChannelType.OPTION_STATIC_REMOTEKEY
+ # note: for SRK chans, this must NOT be a privkey, as it corresponds to a change addr of the wallet,
+ # and hence (combined with xpub) would give access to full onchain wallet (as we use non-hardened bip32 derivs).
vds.write_bytes(self.local_payment_basepoint, 33)
vds.write_bytes(self.multisig_funding_privkey, 32)
return bytes(vds.input)
### electrum/wallet_db.py
@@ -132,6 +132,16 @@ class WalletFileExceptionVersion51(WalletFileException): pass
class WalletDBUpgrader(Logger):
+ """
+ note: each DB upgrade (migration) should be as self-contained as practical.
+ The more a given convert_version_* depends on from outside the module,
+ the more likely future code changes break that specific DB upgrade.
+ - example:
+ invoices.py might have a global dict pr_expiration_values = {10*60: _('10 minutes'), 60*60: _('1 hour'), ...}.
+ Such a dict could change in future code, so if a given DB upgrade needs to reference it,
+ it is more robust to inline and duplicate it inside the migration code.
+ """
+
def __init__(self, data: dict):
Logger.__init__(self)
self.data = data
@@ -1523,7 +1533,7 @@ def _convert_version_74(self):
and that has the same fields for LOCAL and for REMOTE.
"""
from .bip32 import BIP32Node
- from .lnutil import (DERIVED_LOCAL_BASEPOINTS, LnKeyFamily, generate_keypair,
+ from .lnutil import (LnKeyFamily, generate_keypair,
derive_payment_basepoint, get_per_commitment_point_from_seed)
if not self._is_upgrade_method_needed(73, 73):
return
@@ -1541,8 +1551,19 @@ def check(channel_id: str, name: str, derived: bytes, stored: str) -> None:
for channel_id, c in self.data.get('channels', {}).items():
local_config = c['local_config']
remote_config = c['remote_config']
- channel_seed = local_config.pop('channel_seed')
+ channel_seed = local_config.pop('channel_seed', None)
+ if channel_seed is None:
+ raise WalletFileException(
+ f"Cannot upgrade this wallet: it contains a LN channel ({channel_id}) that lacks a channel_seed. "
+ f"This can only happen for channels created from unreleased development git commits (before 2020 April, before 4.0). "
+ f"You must check out the '4.8.2' tag, and close+delete this channel."
+ )
node = BIP32Node.from_rootseed(bfh(channel_seed), xtype='standard')
+ DERIVED_LOCAL_BASEPOINTS = {
+ 'htlc_basepoint': LnKeyFamily.HTLC_BASE,
+ 'delayed_basepoint': LnKeyFamily.DELAY_BASE,
+ 'revocation_basepoint': LnKeyFamily.REVOCATION_BASE,
+ }
for name, key_family in DERIVED_LOCAL_BASEPOINTS.items():
keypair = generate_keypair(node, key_family)
check(channel_id, name, keypair.privkey, local_config[name].pop('privkey'))Why this scored 23/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.