From: Matt Corallo Date: Sun, 22 Aug 2021 19:36:01 +0000 (+0000) Subject: [invoice] Fix non-recoverable sig handling and bogus SI prefix err X-Git-Tag: v0.0.101~26^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=181cb1103d0a1f21aa1f2e44e2f36a6c68663b2f;p=rust-lightning [invoice] Fix non-recoverable sig handling and bogus SI prefix err This adds two additional tests from the BOLT 11 invalid invoice tests, fixing the two errors that broke them. It fixes a panic on the "nonrecoverable signature" test and makes the error variant more sensible on the bogus SI prefix test. --- diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index 2ed356daf..ac7e7e835 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -77,7 +77,7 @@ mod hrp_sm { } else if ['m', 'u', 'n', 'p'].contains(&read_symbol) { Ok(States::ParseAmountSiPrefix) } else { - Err(super::ParseError::MalformedHRP) + Err(super::ParseError::UnknownSiPrefix) } }, States::ParseAmountSiPrefix => Err(super::ParseError::MalformedHRP), diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index c3805f91d..199fbe79a 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -1059,7 +1059,9 @@ impl Invoice { match self.signed_invoice.recover_payee_pub_key() { Err(secp256k1::Error::InvalidRecoveryId) => return Err(SemanticError::InvalidRecoveryId), - Err(_) => panic!("no other error may occur"), + Err(secp256k1::Error::InvalidSignature) => + return Err(SemanticError::InvalidSignature), + Err(e) => panic!("no other error may occur, got {:?}", e), Ok(_) => {}, } diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index 2da843fd6..807308044 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -163,7 +163,13 @@ fn test_bolt_invalid_invoices() { assert_eq!(Invoice::from_str( "LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny" ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MixedCase)))); + assert_eq!(Invoice::from_str( + "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq" + ), Err(ParseOrSemanticError::SemanticError(SemanticError::InvalidSignature))); assert_eq!(Invoice::from_str( "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh" ), Err(ParseOrSemanticError::ParseError(ParseError::TooShortDataPart))); + assert_eq!(Invoice::from_str( + "lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg" + ), Err(ParseOrSemanticError::ParseError(ParseError::UnknownSiPrefix))); }