mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
common: add check that pico-valued invoices are round numbers.
Otherwise you can ask for a sub-millisatoshi amount, which is dumb and violates the spec. See-also: https://github.com/lightningnetwork/lightning-rfc/pull/736 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Changed: We now reject invoices which ask for sub-millisatoshi amounts
This commit is contained in:
parent
3e9d4de02e
commit
5d2fdfe66b
2 changed files with 18 additions and 0 deletions
|
@ -649,6 +649,17 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
|
|||
* amount required for payment.
|
||||
*/
|
||||
b11->msat = tal(b11, struct amount_msat);
|
||||
/* BOLT-50143e388e16a449a92ed574fc16eb35b51426b9 #11:
|
||||
*
|
||||
* - if multiplier is `p` and the last decimal of `amount` is
|
||||
* not 0:
|
||||
* - MUST fail the payment.
|
||||
*/
|
||||
if (amount * m10 % 10 != 0)
|
||||
return decode_fail(b11, fail,
|
||||
"Invalid sub-millisatoshi amount"
|
||||
" '%sp'", amountstr);
|
||||
|
||||
b11->msat->millisatoshis = amount * m10 / 10; /* Raw: raw amount multiplier calculation */
|
||||
}
|
||||
|
||||
|
|
|
@ -562,6 +562,13 @@ int main(void)
|
|||
assert(!bolt11_decode(tmpctx, "lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg", NULL, &fail));
|
||||
assert(streq(fail, "Invalid amount postfix 'x'"));
|
||||
|
||||
/* BOLT- #11:
|
||||
* > ### Invalid sub-millisatoshi precision.
|
||||
* > lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu7hqtk93pkf7sw55rdv4k9z2vj050rxdr6za9ekfs3nlt5lr89jqpdmxsmlj9urqumg0h9wzpqecw7th56tdms40p2ny9q4ddvjsedzcplva53s
|
||||
*/
|
||||
assert(!bolt11_decode(tmpctx, "lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu7hqtk93pkf7sw55rdv4k9z2vj050rxdr6za9ekfs3nlt5lr89jqpdmxsmlj9urqumg0h9wzpqecw7th56tdms40p2ny9q4ddvjsedzcplva53s", NULL, &fail));
|
||||
assert(streq(fail, "Invalid sub-millisatoshi amount '2500000001p'"));
|
||||
|
||||
/* FIXME: Test the others! */
|
||||
wally_cleanup(0);
|
||||
tal_free(tmpctx);
|
||||
|
|
Loading…
Add table
Reference in a new issue