From a21abe2b5ab67228a820cde7ce9b1c59970ca75d Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 30 Jul 2021 16:03:01 -0500 Subject: [PATCH] f - Accept only non-v0 witness programs --- lightning/src/ln/script.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index c2987f739..589c3f311 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -10,6 +10,7 @@ use bitcoin::secp256k1::key::PublicKey; use ln::features::InitFeatures; use std::convert::TryFrom; +use core::num::NonZeroU8; /// A script pubkey for shutting down a channel as defined by [BOLT #2]. /// @@ -60,7 +61,8 @@ impl ShutdownScript { /// # Panics /// /// This function may panic if given a segwit program with an invalid length. - pub fn new_witness_program(version: u5, program: &[u8]) -> Self { + pub fn new_witness_program(version: NonZeroU8, program: &[u8]) -> Self { + let version = u5::try_from_u8(version.get()).expect("Invalid segwit version"); let script = Script::new_witness_program(version, program); Self::try_from(script).expect("Invalid segwit program") } -- 2.39.5