AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 58 Bitcoin

lnsweep: safer maybe_reveal_preimage_for_htlc, add "is_preimage_public"

Public commit record

What the developer wrote

Authored by SomberNight

73/100 · Adequate
lnsweep: safer maybe_reveal_preimage_for_htlc, add "is_preimage_public"

"When should we reveal preimages onchain?"
This commit tries to simplify the thinking by making the observation:
- we can reveal preimages (actually in any context) if they are already public
- a preimage is public if any other lightning node knows it besides us
- if we learn the preimage from another LN node, it is public
- if we send update_fulfill_htlc, it becomes public
- if we see a preimage onchain, it is public

- in lnsweep._maybe_reveal_preimage_for_htlc:
- partial mpp check is not relevant if preimage is already public
- let's just always do KeepWatchingTXO, for sanity/safety

Co-authored-by: ThomasV <thomasv@electrum.org>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit hardens how Electrum decides when to reveal secret payment proof values (called preimages) on the Bitcoin blockchain during Lightning channel force-closes. Previously, the wallet might have revealed a preimage too early if a multi-part payment was incomplete, which could let a sender pay less than the invoice asked for. The change tracks whether a preimage is already 'public' (known to other nodes or seen on-chain) and only reveals it on-chain when it is safe. It also makes sure Electrum keeps watching the relevant transaction output until the timeout, even if it cannot reveal the preimage yet.

Recommended action

Review the new `is_preimage_public` assumptions carefully, especially edge cases where a preimage becomes public through indirect means (e.g., forwarded payments, trampoline routing, or swap server behavior). Ensure the DB migration handles corrupted or unexpected `lightning_preimages` entries gracefully. Consider adding tests that simulate a force-close during an incomplete MPP to verify the preimage is not revealed prematurely and that `KeepWatchingTXO` eventually triggers redemption once the MPP completes or the preimage becomes public.

Security signals we found

01

Preimage revelation logic changed to avoid exposing partial MPP preimages on-chain

02

New public/private preimage state tracked in wallet database

03

Database schema migration added (seed_version 67 -> 68)

04

Sweep logic now returns KeepWatchingTXO instead of None when preimage cannot yet be revealed

05

Multiple call sites updated to mark preimages as public when shared with another LN node or observed on-chain

Risk score

Why this scored 58/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 7/10
Evidence quality 3/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.