[invoice] Fix non-recoverable sig handling and bogus SI prefix err
authorMatt Corallo <git@bluematt.me>
Sun, 22 Aug 2021 19:36:01 +0000 (19:36 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 31 Aug 2021 21:29:51 +0000 (21:29 +0000)
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.

lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/tests/ser_de.rs

index 2ed356dafb8d3959b0c43cebed8ccdc161e69f39..ac7e7e835e08d07d3a7f4af38d590d48dc4f0f0b 100644 (file)
@@ -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),
index c3805f91d51636e41529d1104ae20245d469031d..199fbe79a7e90062dfe1ad5b9358294562640570 100644 (file)
@@ -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(_) => {},
                }
 
index 2da843fd60950c594fe3493ef15be1b9568c58e2..807308044d2e064125d7e0028560256a4031d5e3 100644 (file)
@@ -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)));
 }