Skip to content

Commit 13835c0

Browse files
committed
Detect underflows in build_closing_transaction
In `build_closing_transaction`, we check that `value_to_holder` and `value_to_counterparty`, which are signed, are not lower than the dust limit. However, in doing this check, we convert them to signed integers, which could result in an underflow and a failed detection. This scenario should not be reachable, but here we add debug_asserts to positive ensure that scenario isn't hit.
1 parent fe1cf69 commit 13835c0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15011501
// The `next_funding_txid` field allows peers to finalize the signing steps of an interactive
15021502
// transaction construction, or safely abort that transaction if it was not signed by one of the
15031503
// peers, who has thus already removed it from its state.
1504-
//
1504+
//
15051505
// If we've sent `commtiment_signed` for an interactively constructed transaction
15061506
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
15071507
// to the txid of that interactive transaction, else we MUST NOT set it.
@@ -4368,10 +4368,12 @@ impl<SP: Deref> Channel<SP> where
43684368
total_fee_satoshis += (-value_to_counterparty) as u64;
43694369
}
43704370

4371+
debug_assert!(value_to_counterparty >= 0);
43714372
if skip_remote_output || value_to_counterparty as u64 <= self.context.holder_dust_limit_satoshis {
43724373
value_to_counterparty = 0;
43734374
}
43744375

4376+
debug_assert!(value_to_holder >= 0);
43754377
if value_to_holder as u64 <= self.context.holder_dust_limit_satoshis {
43764378
value_to_holder = 0;
43774379
}

0 commit comments

Comments
 (0)