Skip to content

Commit fb85710

Browse files
committed
[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.
1 parent 400accf commit fb85710

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lightning-invoice/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod hrp_sm {
7777
} else if ['m', 'u', 'n', 'p'].contains(&read_symbol) {
7878
Ok(States::ParseAmountSiPrefix)
7979
} else {
80-
Err(super::ParseError::MalformedHRP)
80+
Err(super::ParseError::UnknownSiPrefix)
8181
}
8282
},
8383
States::ParseAmountSiPrefix => Err(super::ParseError::MalformedHRP),

lightning-invoice/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,9 @@ impl Invoice {
10591059
match self.signed_invoice.recover_payee_pub_key() {
10601060
Err(secp256k1::Error::InvalidRecoveryId) =>
10611061
return Err(SemanticError::InvalidRecoveryId),
1062-
Err(_) => panic!("no other error may occur"),
1062+
Err(secp256k1::Error::InvalidSignature) =>
1063+
return Err(SemanticError::InvalidSignature),
1064+
Err(e) => panic!("no other error may occur, got {:?}", e),
10631065
Ok(_) => {},
10641066
}
10651067

lightning-invoice/tests/ser_de.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ fn test_bolt_invaoid_invoices() {
163163
assert_eq!(Invoice::from_str(
164164
"LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny"
165165
), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MixedCase))));
166+
assert_eq!(Invoice::from_str(
167+
"lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq"
168+
), Err(ParseOrSemanticError::SemanticError(SemanticError::InvalidSignature)));
166169
assert_eq!(Invoice::from_str(
167170
"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh"
168171
), Err(ParseOrSemanticError::ParseError(ParseError::TooShortDataPart)));
172+
assert_eq!(Invoice::from_str(
173+
"lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg"
174+
), Err(ParseOrSemanticError::ParseError(ParseError::UnknownSiPrefix)));
169175
}

0 commit comments

Comments
 (0)