Skip to content

Commit 07e3526

Browse files
committed
Verify the holder provided valid witnesses and uses SIGHASH_ALL
LDK checks the following: * Each input spends an output that is one of P2WPKH, P2WSH, or P2TR. These were already checked by LDK when the inputs to be contributed were provided. * All signatures use the `SIGHASH_ALL` sighash type. * P2WPKH and P2TR key path spends are valid (verifies signatures) NOTE: * When checking P2WSH spends, LDK tries to decode 70-72 byte witness elements as ECDSA signatures with a sighash flag. If the internal DER-decoding fails, then LDK just assumes it wasn't a signature and carries with checks. If the element can be decoded as an ECDSA signature, the the sighash flag must be `SIGHASH_ALL`. * When checking P2TR script-path spends, LDK assumes all elements of exactly 65 bytes with the last byte matching any valid sighash flag byte are schnorr signatures and checks that the sighash type is `SIGHASH_ALL`. If the last byte is not any valid sighash flag, the element is assumed not to be a signature and is ignored. Elements of 64 bytes are not checked because if they were schnorr signatures then they would implicitly be `SIGHASH_DEFAULT` which is an alias of `SIGHASH_ALL`.
1 parent ef50e1e commit 07e3526

File tree

3 files changed

+549
-25
lines changed

3 files changed

+549
-25
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7737,6 +7737,8 @@ where
77377737
),
77387738
})
77397739
.and_then(|signing_session| {
7740+
signing_session
7741+
.verify_interactive_tx_signatures(&self.context.secp_ctx, &witnesses)?;
77407742
signing_session
77417743
.provide_holder_witnesses(self.context.channel_id, witnesses)
77427744
.map_err(|err| APIError::APIMisuseError { err })

lightning/src/ln/channelmanager.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5900,19 +5900,32 @@ where
59005900
/// counterparty's signature(s) the funding transaction will automatically be broadcast via the
59015901
/// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
59025902
///
5903-
/// `SIGHASH_ALL` MUST be used for all signatures when providing signatures.
5904-
///
5905-
/// <div class="warning">
5906-
/// WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
5907-
/// will prevent the funding transaction from being relayed on the bitcoin network and hence being
5908-
/// confirmed.
5909-
/// </div>
5903+
/// `SIGHASH_ALL` MUST be used for all signatures when providing signatures, otherwise your
5904+
/// funds can be held hostage!
5905+
///
5906+
/// LDK checks the following:
5907+
/// * Each input spends an output that is one of P2WPKH, P2WSH, or P2TR.
5908+
/// These were already checked by LDK when the inputs to be contributed were provided.
5909+
/// * All signatures use the `SIGHASH_ALL` sighash type.
5910+
/// * P2WPKH and P2TR key path spends are valid (verifies signatures)
5911+
///
5912+
/// NOTE:
5913+
/// * When checking P2WSH spends, LDK tries to decode 70-72 byte witness elements as ECDSA
5914+
/// signatures with a sighash flag. If the internal DER-decoding fails, then LDK just
5915+
/// assumes it wasn't a signature and carries with checks. If the element can be decoded
5916+
/// as an ECDSA signature, the the sighash flag must be `SIGHASH_ALL`.
5917+
/// * When checking P2TR script-path spends, LDK assumes all elements of exactly 65 bytes
5918+
/// with the last byte matching any valid sighash flag byte are schnorr signatures and checks
5919+
/// that the sighash type is `SIGHASH_ALL`. If the last byte is not any valid sighash flag, the
5920+
/// element is assumed not to be a signature and is ignored. Elements of 64 bytes are not
5921+
/// checked because if they were schnorr signatures then they would implicitly be `SIGHASH_DEFAULT`
5922+
/// which is an alias of `SIGHASH_ALL`.
59105923
///
59115924
/// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
59125925
/// `counterparty_node_id` is provided.
59135926
///
59145927
/// Returns [`APIMisuseError`] when a channel is not in a state where it is expecting funding
5915-
/// signatures.
5928+
/// signatures or if any of the checks described above fail.
59165929
///
59175930
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
59185931
/// [`APIMisuseError`]: APIError::APIMisuseError

0 commit comments

Comments
 (0)