Added test for testing sciptpubkey of closing message per bolt 2 spec
authorSchalk van Heerden <swvheerden@gmail.com>
Thu, 20 Sep 2018 08:16:20 +0000 (10:16 +0200)
committerSchalk van Heerden <swvheerden@gmail.com>
Fri, 21 Sep 2018 08:20:44 +0000 (10:20 +0200)
src/ln/channel.rs

index b207baa9fe9c08162197f1896cff81709fd84b24..83698f1172632ffc8903e4ee7cdb1091867e429f 100644 (file)
@@ -2012,7 +2012,12 @@ impl Channel {
                if self.channel_outbound && msg.scriptpubkey.len() > 34 {
                        return Err(HandleError{err: "Got shutdown_scriptpubkey of absurd length from remote peer", action: None});
                }
-               //TODO: Check shutdown_scriptpubkey form as BOLT says we must? WHYYY
+
+               //Check shutdown_scriptpubkey form as BOLT says we must
+               if !(msg.scriptpubkey.is_p2pkh()) && !(msg.scriptpubkey.is_p2sh())
+                       && !(msg.scriptpubkey.is_v0_p2wpkh()) && !(msg.scriptpubkey.is_v0_p2wsh()){
+                       return Err(HandleError{err: "Got an invalid scriptpubkey from remote peer", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })});
+               }
 
                if self.their_shutdown_scriptpubkey.is_some() {
                        if Some(&msg.scriptpubkey) != self.their_shutdown_scriptpubkey.as_ref() {
@@ -2098,7 +2103,7 @@ impl Channel {
                if !self.pending_inbound_htlcs.is_empty() || !self.pending_outbound_htlcs.is_empty() {
                        return Err(HandleError{err: "Remote end sent us a closing_signed while there were still pending HTLCs", action: None});
                }
-               if msg.fee_satoshis > 21000000 * 10000000 {
+               if msg.fee_satoshis > 21000000 * 10000000 { //this is required to stop potential overflow in build_closing_transaction
                        return Err(HandleError{err: "Remote tried to send us a closing tx with > 21 million BTC fee", action: None});
                }