Narrow check_spend_remote_htlc input/output count check.
authorMatt Corallo <git@bluematt.me>
Wed, 26 Sep 2018 14:48:30 +0000 (10:48 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Sep 2018 15:06:28 +0000 (11:06 -0400)
This fixes a crash found by fuzztester where a 0-output tx causes a
[] panic (though this shouldn't happen in the real-world as
0-output txn should never be able to be mined).

src/ln/channelmonitor.rs

index f3c5c89f6e67cbc1c0e175b75439729385212d33..4b72a3cb69d1c3436048d050c649c3ee1fae350b 100644 (file)
@@ -1011,7 +1011,9 @@ impl ChannelMonitor {
 
        /// Attempst to claim a remote HTLC-Success/HTLC-Timeout s outputs using the revocation key
        fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64) -> Option<Transaction> {
-               let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
+               if tx.input.len() != 1 || tx.output.len() != 1 {
+                       return None;
+               }
 
                macro_rules! ignore_error {
                        ( $thing : expr ) => {
@@ -1039,6 +1041,7 @@ impl ChannelMonitor {
                };
                let redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.their_to_self_delay.unwrap(), &delayed_key);
                let revokeable_p2wsh = redeemscript.to_v0_p2wsh();
+               let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
 
                let mut inputs = Vec::new();
                let mut amount = 0;