From: Matt Corallo Date: Sun, 22 Aug 2021 19:54:08 +0000 (+0000) Subject: Check if invoices contain unknown required features X-Git-Tag: v0.0.101~26^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a4a54ed9dfd8e6c725c2fdc5961cfe6b815fa958;p=rust-lightning Check if invoices contain unknown required features This adds the final missing BOLT 11 failure test, checking for unknown required feature flags before accepting an invoice. --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index bcb15245d..75aac5491 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -1052,7 +1052,9 @@ impl Invoice { None if has_payment_secret => Err(SemanticError::InvalidFeatures), None => Ok(()), Some(TaggedField::Features(features)) => { - if features.supports_payment_secret() && has_payment_secret { + if features.requires_unknown_bits() { + Err(SemanticError::InvalidFeatures) + } else if features.supports_payment_secret() && has_payment_secret { Ok(()) } else if has_payment_secret { Err(SemanticError::InvalidFeatures) diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index c2f82b099..94e75cbc4 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -154,6 +154,9 @@ fn deserialize() { #[test] fn test_bolt_invalid_invoices() { // Tests the BOLT 11 invalid invoice test vectors + assert_eq!(Invoice::from_str( + "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqpqsqq40wa3khl49yue3zsgm26jrepqr2eghqlx86rttutve3ugd05em86nsefzh4pfurpd9ek9w2vp95zxqnfe2u7ckudyahsa52q66tgzcp6t2dyk" + ), Err(ParseOrSemanticError::SemanticError(SemanticError::InvalidFeatures))); assert_eq!(Invoice::from_str( "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt" ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::InvalidChecksum)))); diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index e78fa3d50..c0eb8f68a 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -548,7 +548,9 @@ impl Features { &self.flags } - pub(crate) fn requires_unknown_bits(&self) -> bool { + /// Returns true if this `Features` object contains unknown feature flags which are set as + /// "required". + pub fn requires_unknown_bits(&self) -> bool { // Bitwise AND-ing with all even bits set except for known features will select required // unknown features. let byte_count = T::KNOWN_FEATURE_MASK.len();