From ca9a6b15b5fab72e5874c95f5a6d350ee3c49704 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 15 Jun 2023 15:01:02 +0930 Subject: [PATCH] pay: don't require description for hashdesc invoices (i.e. undeprecate). Since we didn't hash the descriptions properly (see previous commit), we cannot immediately deprecate omitting the descriptions (since you'd have to omit them for backwards compat!). And move the "must have description or hash" test into bolt11.c core. Changelog-Deprecated: `pay` has *undeprecated* paying a description-hash invoice without providing the description. Signed-off-by: Rusty Russell --- common/bolt11.c | 11 +++++++++++ plugins/pay.c | 18 ------------------ tests/test_invoices.py | 4 ---- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/common/bolt11.c b/common/bolt11.c index ce8532971..07134f186 100644 --- a/common/bolt11.c +++ b/common/bolt11.c @@ -893,6 +893,17 @@ struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str, "h: does not match description"); } + /* BOLT #11: + * A writer: + *... + * - MUST include either exactly one `d` or exactly one `h` field. + */ + /* FIXME: It doesn't actually say the reader must check though! */ + if (!have_field[bech32_charset_rev['d']] + && !have_field[bech32_charset_rev['h']]) + return decode_fail(b11, fail, + "must have either 'd' or 'h' field"); + hash_u5_done(&hu5, hash); *sig = tal_dup_arr(ctx, u5, data, data_len, 0); diff --git a/plugins/pay.c b/plugins/pay.c index 9b66a548f..008114684 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1053,24 +1053,6 @@ static struct command_result *json_pay(struct command *cmd, cmd, JSONRPC2_INVALID_PARAMS, "Invalid bolt11:" " sets feature var_onion with no secret"); - - /* BOLT #11: - * A reader: - *... - * - MUST check that the SHA2 256-bit hash in the `h` field - * exactly matches the hashed description. - */ - if (!b11->description && !deprecated_apis) { - if (!b11->description_hash) { - return command_fail(cmd, - JSONRPC2_INVALID_PARAMS, - "Invalid bolt11: missing description"); - } - if (!description) - return command_fail(cmd, - JSONRPC2_INVALID_PARAMS, - "bolt11 uses description_hash, but you did not provide description parameter"); - } } else { b12 = invoice_decode(tmpctx, b11str, strlen(b11str), plugin_feature_set(cmd->plugin), diff --git a/tests/test_invoices.py b/tests/test_invoices.py index 83aa56d2d..9fbd7f2af 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -724,10 +724,6 @@ def test_invoice_deschash(node_factory, chainparams): listinv = only_one(l2.rpc.listinvoices()['invoices']) assert listinv['description'] == 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon' - # To pay it we need to provide the (correct!) description. - with pytest.raises(RpcError, match=r'you did not provide description parameter'): - l1.rpc.pay(inv['bolt11']) - with pytest.raises(RpcError, match=r'does not match description'): l1.rpc.pay(inv['bolt11'], description=listinv['description'][:-1])