Repository navigation
Gate 0-conf splices with counterparty inputs behind splice_minimum_depth - #32
Open
martinsaposnic wants to merge 1 commit into
Open
martinsaposnic wants to merge 1 commit into
martinsaposnic wants to merge 1 commit into
Conversation
splice_minimum_depth only applied when the counterparty initiated the splice. When we initiate, the counterparty can still add its own inputs via splice_ack + tx_add_input. On a 0-conf channel we then sent splice_locked at once, so the peer could spend its new balance through us and double-spend its inputs so the splice tx never confirms. Apply the override whenever the counterparty added inputs to the negotiated splice tx (or initiated it). Splices built only from our own inputs, like the LSPS4 top-up splice-in, still lock at 0-conf. Also, channels persisted without splice_minimum_depth (opened before the setting existed, or while it was unset) read it back as None, so the protection never applied to them. Take the value from the live config when the ChannelManager loads each channel. Tests use a test-only hook to make the acceptor contribute inputs, since LDK 0.2 cannot do that yet but the protocol allows it.
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.
Problem
splice_minimum_depth(#20) only applied when the counterparty initiated the splice. When the LSP initiates (LSPS4 top-up splice-in), the client can still add its own inputs: it answerssplice_ackwith a non-zerofunding_contribution_satoshisand sendstx_add_input. LDK accepts that. On a 0-conf channel the LSP then sendssplice_lockedright aftertx_signatures.Attack
Upstream LDK (v0.2.7 and main) has no guard here: any splice on a 0-conf channel locks at 0 conf. Upstream treats 0-conf peers as trusted. We don't.
Second problem: channels persisted without
splice_minimum_depth(opened before #20, or while unset) read it back asNone, so even client-initiated splices on those channels locked at 0 conf.Proof
New tests in
lightning/src/ln/splicing_tests.rs:test_splice_minimum_depth_for_self_initiated_with_counterparty_inputstest_splice_minimum_depth_applies_to_channels_persisted_without_itLDK 0.2 cannot contribute as splice acceptor, so a test-only hook (
TEST_SPLICE_ACCEPTOR_CONTRIBUTION,cfg(test)) makes node B add inputs, like a malicious peer would.Before fix:
After fix: all 4
test_splice_minimum_depth*tests pass.Fix
on_tx_signatures_exchange: apply the override when the counterparty initiated or added any non-shared input (remote_inputs_count() > 0). If the signing session is somehow missing, apply it (fail safe).ChannelManagerread: set each channel'ssplice_minimum_depthfrom the live config on load.Tradeoffs
splice_locked, so applying the depth to every splice would add about an hour to every top-up. Not done.splice_minimum_depthconfs. LDK clients can't add inputs today, so honest clients see no change.Not fixed here (known gap)
Even with only LSP inputs, the client can try to race the splice tx by broadcasting its latest old-funding commitment (it spends the same old funding output). That needs separate analysis.
Test runs
cargo test -p lightning splic: 25 passed, 1 failed. The failure,test_splice_locked_conveyed_after_reestablish_signature_retransmission, also fails on the baselsp-0.2.7(bfc1b29) without this change.cargo test -p lightning-liquidity lsps4: 35 passedcargo test -p lightning-liquidity --test lsps4_integration_tests: 6 passedcargo check --workspace: okRUSTFLAGS="--cfg=c_bindings" cargo check -p lightning: ok