Repository navigation
[3/3] aux revocation: breach-to-confirmation revocation flow - #11112
GeorgeTsagk wants to merge 15 commits into
Conversation
db471fa to
af50f4a
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
🔴 PR Severity: CRITICAL
🔴 Critical (17 files)
🟠 High (1 file)
🟢 Low (test-only / docs, excluded from counts)
AnalysisThis PR is a large, security-sensitive change touching several CRITICAL-tier subsystems simultaneously: Given the scope (breach arbitration, commitment/resolution logic, and revocation wire messages), this warrants careful expert review of the channel state machine and on-chain resolution paths, particularly around the new/modified aux-signer and contract-resolver logic. To override, add a |
af50f4a to
707dfdb
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
707dfdb to
c16f334
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
c16f334 to
e8d8da9
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
|
@gijswijs: review reminder |
3 similar comments
|
@gijswijs: review reminder |
|
@gijswijs: review reminder |
|
@gijswijs: review reminder |
0a43bf8 to
a5cf89b
Compare
|
@gijswijs: review reminder |
a5cf89b to
2069f10
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
|
@gijswijs: review reminder |
3 similar comments
|
@gijswijs: review reminder |
|
@gijswijs: review reminder |
|
@gijswijs: review reminder |
948d44f to
202db0f
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
dd1a9a4 to
b1a6262
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
b1a6262 to
3188f00
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
|
@litbot-9000: review reminder |
3188f00 to
2175b9a
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
The RevokeAndAck message gains a CustomRecords field, encoded and decoded with the standard ParseAndExtractCustomRecords/MergeAndEncode helpers. The field is additive and backward-compatible on the wire: peers that send no records produce byte-identical encodings to before this change, and unknown odd records are tolerated on receive. The following commits use this field to carry revocation AuxSigs for aux/custom (taproot asset) channels; a vanilla lnd channel never populates it.
When an aux/custom (taproot asset) channel revokes a commitment that was built with DeterministicHTLCs, the revoking party now signs the second-level HTLC virtual transaction of every non-dust HTLC on the commitment being revoked, and ships the signatures to the peer inside the RevokeAndAck message's custom records. This hands the honest party the asset-level puzzle piece it needs at breach time: if the cheater later broadcasts the revoked commitment and takes an HTLC to the second level, the breached party holds the cheater's half of the asset witness for that transition. An HTLC has exactly one second-level path on the commitment of the party that revokes it: the success tx for an HTLC it received, the timeout tx for one it offered. That is the path that is signed. Changes: - Sender: signLocalHtlcAuxSigs derives the second-level tx of each non-dust HTLC on the revoked commitment and submits a sign job to the aux signer. The signatures are packed as one TLV stream per HTLC, tagged with the HTLC's index and direction. The index alone does not identify an HTLC: both parties count the HTLCs they offer from zero, so a commitment regularly carries an incoming and an outgoing HTLC with the same index. One entry is packed per non-dust HTLC even when the signer produces no signature for it (a BTC-only HTLC), in lockstep with the BTC-level signatures. A signing failure fails the revocation as a whole, before any state is advanced: the peer requires the sigs, so a sig-less RevokeAndAck would just fail the channel on their side. - Receiver: ReceiveRevocation verifies the received aux sigs against the revoked commitment's key ring BEFORE the revocation is accepted and the tail advances, then injects the sigs into the remote commitment's HTLC custom records so they are persisted in the revocation log for breach-time consumption. Presence is enforced, mirroring the aux sig count check on CommitSig: an entry is required for every non-dust HTLC on the revoked commitment (a peer cannot strip our breach protection by withholding the records), and entries for unknown or dust HTLCs are rejected. A verify job is handed to the aux signer for every non-dust HTLC, with or without a sig, as only the aux signer knows whether the HTLC carries aux outputs and therefore owes one. Whatever the peer put under our storage record type on its own UpdateAddHTLC is dropped before the sigs are injected, so only verified sigs reach the revocation log. - Decoding: the blob comes from the peer and is decoded accordingly. The declared entry count never sizes an allocation, every entry must consume exactly the length it declares, an HTLC may appear only once and nothing may follow the last entry. - Retransmission: the packed sig blob is persisted in a new optional TLV field on the channel info, written atomically with the commitment advance in UpdateCommitment, and re-attached when the RevokeAndAck is retransmitted on channel reestablish. Only the latest revocation can ever be owed, so a single overwritten slot suffices. If the write fails the previous blob stays in memory. - BaseAuxJob gains the WhoseCommit and HtlcTimeout fields needed to describe a sign job for our own commitment to the aux signer. The gate is factored into a single predicate, exchangesRevocationAuxSigs, used by both hooks and (defense in depth) inside the sign and verify functions themselves. It requires an explicit HasTapscriptRoot() on the channel type, and that the commitment being revoked records SigHashDefault in its own blob. Both peers hold that record for the same commitment, so they agree on which revocations carry the signatures even while the sighash type used for new commitments is changing. A vanilla lnd channel never signs, attaches, reads, or verifies these records and its RevokeAndAck is byte-identical to before this change.
Coverage for the revocation AuxSig exchange introduced in the previous commits: - lnwire codec: encode/decode round trips for RevokeAndAck with and without custom records, including a byte-for-byte assertion that the no-records encoding is identical to the legacy wire format. - TLV blob: pack/unpack round trips, including the same HTLC index in both directions, and rejection of corrupt and hostile blobs: truncation, garbage, duplicate entries, trailing bytes, undeclared entries, lengths beyond the blob, cut-off records, missing or invalid index and direction records. A declared entry count in the billions must not make the decoder allocate for it. - Custom-channel-only gating: a non-custom taproot channel with an aux signer that pushes SigHashDefault attaches nothing and ignores stray records. The gate follows the sighash recorded for the commitment being revoked, not the one new commitments use. - Happy path over a funded tapscript-root channel pair: one sig for every non-dust HTLC, the dust decision made with the dust limit of the commitment's owner, the sig matched to the right verify job, and the verified sig persisted into the revocation log entry of the revoked commitment. - Same HTLC index in both directions: each HTLC is signed once for its own path, gets its own entry, and keeps its own sig through verification and persistence. - BTC-only HTLCs: sig-less lockstep entries are attached, and accepted once the aux signer has been asked about them. - Rejection before the remote chain tail advances: unverifiable sigs, malformed blob, missing sig for a non-dust HTLC, a sig tagged with the wrong direction, withheld blob, a sig withheld from its entry, the sig of another HTLC, an extra entry for an unknown HTLC index or for the other direction, and entries for HTLCs that are dust for both parties or for the signer only. - A custom record the peer planted under our storage type never reaches the revocation log. - Sign-time failure: an aux signer error fails RevokeCurrentCommitment before any state advances, for both batch-level and per-job errors. - Retransmission: after a restart, with the channel rebuilt from disk, a retransmitted RevokeAndAck carries the original aux sigs without signing again, and the peer verifies and accepts them.
…tput convertToSecondLevelRevoke set the sign descriptor's TapTweak to a slice over the breached output's own secondLevelTapTweak array. updateBreachInfo compacts the breachedOutputs slice in place once an output has been swept, so the struct values shift while the slice keeps pointing at the old slot, which now holds another output's tweak. Every second-level justice sweep built after that point is signed with the wrong tweak, fails script validation, and the second-level HTLC output stays unswept until restart. Copy the tweak into its own backing array instead. The test reproduces the sequence: two HTLC outputs morph to the second level, the commitment output is swept and removed, and the remaining outputs must still sign with their own tweak.
Pass the breach height through the call chain from NewBreachRetribution to createHtlcRetribution, and include it in the ResolutionReq for HTLC outputs via CommitTxBlockHeight. This is required for taproot-assets to properly reanchor asset proofs when sweeping revoked HTLCs. The reanchorAssetOutputs function needs the block height to fetch the block containing the breach commitment transaction and construct valid proofs for the sweep. Without this, the CommitTxBlockHeight defaults to 0, causing tapd to look for the commitment tx in the genesis block and fail with: "commit tx not found in block". See: lightninglabs/taproot-assets@815021fd (tapchannel: add reanchorAssetOutputs for proof reanchoring)
Second-level HTLC auxiliary leaves need to be computed at runtime from the channel state, key ring, and commitment transaction, rather than being stored in the commitment blob. Extend the FetchLeavesFromRevocation interface method to accept these additional parameters so that implementers can derive the leaves on the fly.
When an HTLC is taken to the second level — whether during a breach or during a regular force close — the aux contract resolver needs to re-resolve the contract with the actual second-level transaction once it confirms. Preserve the original ResolutionReq as a template: - in HtlcRetribution, so the breach arbiter can re-resolve with a different witness type - on IncomingHtlcResolution / OutgoingHtlcResolution, so the htlc success and timeout resolvers can do the same once their pre-signed second-level tx confirms Also add SecondLevelTx and SecondLevelTxBlockHeight fields to ResolutionReq so the resolver can re-anchor proofs to the second-level transaction rather than the commitment transaction. Populate HtlcAmt in the resolution request so the resolver has the HTLC value available. Add a NewSecondLevelResolveReq helper that reconstructs the ResolutionReq at re-resolve time, re-deriving the commitment key ring from RevocationProducer.AtIndex(LocalCommitment.CommitHeight) so the plumbing does not have to round-trip the key ring through the briefcase.
When constructing HtlcRetribution for a breached commitment, extract the remote party's asset-level HTLC signature from the revocation log's CustomBlob and populate AuxSigDesc on the ResolutionReq. This allows the aux subsystem to construct valid asset witnesses for the commitment → second-level proof transition, making breach-recovered assets fully spendable.
Wire the revocation AuxSigs (delivered via RevokeAndAck and persisted in the revocation log) into the breach retribution. createHtlcRetribution extracts the remote party's revocation aux sig from the custom records of the breached HTLC (auxSigDescFromHTLCBlob) and hands it to the aux resolver via AuxSigDesc, so the resolver holds the remote half of the asset witness for the second-level path the HTLC has on the revoked commitment. Only the revocation sig qualifies. The CommitSig aux sig that can sit in the same records covers the second-level HTLC of our own commitment, which is a different transaction, so a state that was revoked without revocation aux sigs reports no sig at all. The resolution request of a breached HTLC now states the direction of the HTLC (HtlcIncoming). The witness type of a second-level revocation covers both directions, and HTLC IDs are per-offerer counters that both start at zero, so without it the aux resolver cannot tell an incoming HTLC from an outgoing one with the same ID. A failure of the aux resolver for one HTLC no longer fails the whole retribution. Nothing retries a breach handoff that errors out, so one HTLC the resolver cannot handle would leave the commitment outputs and every other HTLC of the revoked state unpunished. The HTLC is instead handed over without a blob and swept for its BTC value.
Teach the breach arbiter to handle the breach of an aux (custom) channel whose HTLCs are taken to the second level, and to tell the aux sweeper about the justice transaction that confirms. Second-level outputs: - findSecondLevelOutputIndex locates the second-level output of an aux channel HTLC by script match rather than by SpenderInputIndex, which diverges from the output index when the spending tx carries other inputs. Several HTLCs can share a second-level script, so outputs that already belong to another breached output are skipped, and the output at the index of the spending input is preferred. Regular channels keep using SpenderInputIndex. - convertToSecondLevelRevoke re-resolves the aux blob against the confirmed second-level tx through the AuxContractResolver, using the resolution request template preserved at breach detection. Everything is worked out before the breached output is touched. If the output cannot be located, the breached output is dropped without being counted as claimed. If the aux resolver fails, the output is still converted and swept for its BTC value, without the blob that was resolved for the commitment output. - With an aux output, the BTC sweep output of a justice tx is only added above the dust limit. Below it the remaining BTC goes to fees, and the reported fee is what the tx really pays. A justice tx whose inputs cannot fund the aux output is rejected. Without an aux output the tx is built exactly as before. Aux sweeper notification: Previously the breach arbiter called NotifyBroadcast on the aux sweeper when the spendAll justice tx was first broadcast. That fires too early and for one variant only: the aux sweeper imports proofs on broadcast, but the variant that ends up confirming may be a different one, built in a later rebuild cycle. A justiceTxTracker now records every justice tx variant created for the breach and reports the one that confirms, exactly once and with all of its inputs, which it collects from the spends that report the tx. A notification the aux sweeper fails to take is retried on every block, and the breach is only cleaned up after it went through. The notification options are carried by a new AuxNotifyOpts struct on AuxSweeper.NotifyBroadcast: SkipBroadcast (the tx is already confirmed), ConfirmHeight (a height hint for the confirmation) and LookupInputProofs (the inputs include second-level outputs, whose proofs were imported after their blob was resolved). All of this is gated on aux resolution data being present, so the breach of a regular channel is handled exactly as before. AuxResolver is wired into BreachConfig from server.go.
The retribution store only persists what it takes to sweep the BTC of a breached channel. For an aux channel that is not enough to pick a breach up again after a restart: - The aux resolution blobs of the breached HTLCs and their resolution request templates are built at breach detection from the revocation log, which is gone once the channel is closed. Without them an HTLC is swept without its aux value, and one that is taken to the second level is handled like the HTLC of a regular channel. - The justice transactions built after a restart pay to a new address with a new fee. A justice tx that was broadcast before the restart and confirms afterwards is therefore not recognized, and the aux sweeper is never told about it. Store the HTLC blobs in the taproot briefcase next to the commitment blobs. Store the request templates, split into the part all HTLCs share and the per-HTLC remainder, and the metadata of every justice tx created for the breach in a new aux retribution bucket. The retribution loop records its justice txs before publishing them and seeds its tracker from the store. After a restart the spends are replayed from the breach on, so the confirmed justice tx is reported to the aux sweeper again, with the inputs as they are resolved then. Nothing is written to the new bucket for regular channels.
Under DeterministicHTLCs the pre-signed second-level HTLC tx is published verbatim by the sweeper, without going through the aux sweeper's NotifyBroadcast hook, so the aux sweeper never imports the second-level proof transition into its archive and the upcoming output sweep would fail to fetch its input proof. Before offering the second-level output to the sweeper, give the aux resolver a chance to import the confirmed second-level tx into its proof archive by re-resolving the contract against it. The fast path clones the ResolveReq preserved on the htlcResolution at force-close time and only swaps the second-level context (SecondLevelInfo). The slow path (resolvers recovered from a briefcase checkpoint, where the in-memory ResolveReq is gone) reconstructs the request from historical channel state via NewSecondLevelResolveReq. The whole path is gated on isSigHashDefault(): only a pre-signed SigHashDefault second-level tx confirms exactly as we hold it. On an aux channel whose second-level txs are signed with SINGLE|ANYONECANPAY the sweeper rebuilds the tx, so the blob resolved at force close time is kept, as before. The gate also guarantees that this never executes for a non-custom channel, although the AuxResolver is a daemon-global option that is present on every resolver.
The direct signing path was taught to apply the revocation (double) and HTLC-index (single) tweaks together in 8125286, but the PSBT path used by remote signers still returned after the first tweak unknown it encountered, silently dropping the other one. A watch-only node with a remote signer would then derive a wrong signing key for second-level HTLC signing on aux channels, where both tweaks are attached. Mirror the combined derivation (double first, then single) and cover all tweak combinations and unknown orderings with a test.
2175b9a to
ccaeef4
Compare
Points the lnd module and its submodules at the companion series on the GeorgeTsagk/lnd fork: 1. lightningnetwork/lnd#11094, deterministic second-level HTLCs 2. lightningnetwork/lnd#11111, revocation AuxSigs in RevokeAndAck 3. lightningnetwork/lnd#11112, breach-to-confirmation revocation flow The pin is at the tip of part 3, which contains all three. It also adapts the call sites that the new aux interfaces touch. This is temporary and has to be dropped once the lnd series lands.
This is the final part of the HTLC revocation series for aux/custom (taproot asset) channels, stacked on #11094 and #11111. Only the last twelve commits are new here.
It connects the pieces from the previous two PRs into the end-to-end breach lifecycle: with deterministic second-level HTLCs (part 1) and the revocation AuxSigs handed over in RevokeAndAck (part 2), the breach machinery can now punish a revoked commitment on an asset channel no matter which path the cheater takes, while keeping the asset proof chain intact.
The commits are grouped into four arcs:
Breach context (lnwallet):
FetchLeavesFromRevocationgains the channel state parameters needed to derive the revoked commitment's leaves.AuxSigDescpopulated from the revocation log, carrying the dual-path sigs from part 2.Confirmed-only aux notification (sweep + contractcourt):
AuxNotifyOpts(confirm height, input-proof lookup, independent skip flags), so the asset side never finalizes proofs for transactions that lost the pinning race. Tests included.Justice machinery (contractcourt):
Convergence:
As with the previous parts, every aux path is gated on the channel type carrying a tapscript root; lnd's own breach-retribution and force-close itests pass unchanged, and the full custom channel itest suite (force close, HTLC force close, MPP, group tranches, breach, coop close) passes against this tip together with the companion taproot-assets branch.
Previous PR: #11111