Skip to content

Commit 04e66f1

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 7230ef4 commit 04e66f1

File tree

3 files changed

+551
-25
lines changed

3 files changed

+551
-25
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7983,6 +7983,8 @@ where
79837983
),
79847984
})
79857985
.and_then(|signing_session| {
7986+
signing_session
7987+
.verify_interactive_tx_signatures(&self.context.secp_ctx, &witnesses)?;
79867988
signing_session
79877989
.provide_holder_witnesses(self.context.channel_id, witnesses)
79887990
.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
@@ -5908,19 +5908,32 @@ where
59085908
/// counterparty's signature(s) the funding transaction will automatically be broadcast via the
59095909
/// [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
59105910
///
5911-
/// `SIGHASH_ALL` MUST be used for all signatures when providing signatures.
5912-
///
5913-
/// <div class="warning">
5914-
/// WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
5915-
/// will prevent the funding transaction from being relayed on the bitcoin network and hence being
5916-
/// confirmed.
5917-
/// </div>
5911+
/// `SIGHASH_ALL` MUST be used for all signatures when providing signatures, otherwise your
5912+
/// funds can be held hostage!
5913+
///
5914+
/// LDK checks the following:
5915+
/// * Each input spends an output that is one of P2WPKH, P2WSH, or P2TR.
5916+
/// These were already checked by LDK when the inputs to be contributed were provided.
5917+
/// * All signatures use the `SIGHASH_ALL` sighash type.
5918+
/// * P2WPKH and P2TR key path spends are valid (verifies signatures)
5919+
///
5920+
/// NOTE:
5921+
/// * When checking P2WSH spends, LDK tries to decode 70-72 byte witness elements as ECDSA
5922+
/// signatures with a sighash flag. If the internal DER-decoding fails, then LDK just
5923+
/// assumes it wasn't a signature and carries with checks. If the element can be decoded
5924+
/// as an ECDSA signature, the the sighash flag must be `SIGHASH_ALL`.
5925+
/// * When checking P2TR script-path spends, LDK assumes all elements of exactly 65 bytes
5926+
/// with the last byte matching any valid sighash flag byte are schnorr signatures and checks
5927+
/// that the sighash type is `SIGHASH_ALL`. If the last byte is not any valid sighash flag, the
5928+
/// element is assumed not to be a signature and is ignored. Elements of 64 bytes are not
5929+
/// checked because if they were schnorr signatures then they would implicitly be `SIGHASH_DEFAULT`
5930+
/// which is an alias of `SIGHASH_ALL`.
59185931
///
59195932
/// Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
59205933
/// `counterparty_node_id` is provided.
59215934
///
59225935
/// Returns [`APIMisuseError`] when a channel is not in a state where it is expecting funding
5923-
/// signatures.
5936+
/// signatures or if any of the checks described above fail.
59245937
///
59255938
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
59265939
/// [`APIMisuseError`]: APIError::APIMisuseError

0 commit comments

Comments
 (0)