Skip to content

Commit

Permalink
global: update BOLT12 quotes.
Browse files Browse the repository at this point in the history
This is a final sweep to match the current BOLT12 text:

	1563d13999d342680140c693de0b9d65aa522372 ("More bolt12 test vectors.")

Only two code changes, to change the order of checks to match the bolt,
and to give a warning on decode if a path is empty.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jul 23, 2024
1 parent afedc0a commit d1e83aa
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion common/test/run-bolt12-encode-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int main(int argc, char *argv[])
/* BOLT-offers #12:
* - if it includes `offer_paths`:
* - SHOULD ignore any invoice_request which does not use the path.
* - MAY set `offer_issuer_id` to the node's public key to request the invoice from.
* - MAY set `offer_issuer_id`.
* - otherwise:
* - MUST set `offer_issuer_id` to the node's public key to request the invoice from.
*/
Expand Down
11 changes: 7 additions & 4 deletions common/test/run-bolt12-format-string-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ int main(int argc, char *argv[])
offer = tlv_offer_new(tmpctx);
/* BOLT-offers #12:
* A writer of an offer:
* - MUST NOT set any tlv fields greater or equal to 80, or tlv field 0.
* - MUST set `offer_issuer_id` to the node's public key to request the invoice from.
* - MUST set `offer_description` to a complete description of the purpose
* of the payment.
* - MUST NOT set any TLV fields outside the inclusive ranges: 1 to 79 and 1000000000 to 1999999999.
* - if the chain for the invoice is not solely bitcoin:
* - MUST specify `offer_chains` the offer is valid for.
* - otherwise:
Expand All @@ -134,9 +131,12 @@ int main(int argc, char *argv[])
* - MUST specify `offer_currency` `iso4217` as an ISO 4712 three-letter code.
* - MUST specify `offer_amount` in the currency unit adjusted by the ISO 4712
* exponent (e.g. USD cents).
* - MUST set `offer_description` to a complete description of the purpose
* of the payment.
* - otherwise:
* - MUST NOT set `offer_amount`
* - MUST NOT set `offer_currency`
* - MAY set `offer_description`
* - MAY set `offer_metadata` for its own use.
* - if it supports bolt12 offer features:
* - MUST set `offer_features`.`features` to the bitmap of bolt12 features.
Expand All @@ -151,6 +151,9 @@ int main(int argc, char *argv[])
* - MAY include `offer_paths`.
* - if it includes `offer_paths`:
* - SHOULD ignore any invoice_request which does not use the path.
* - MAY set `offer_issuer_id`.
* - otherwise:
* - MUST set `offer_issuer_id` to the node's public key to request the invoice from.
* - if it sets `offer_issuer`:
* - SHOULD set it to identify the issuer of the invoice clearly.
* - if it includes a domain name:
Expand Down
9 changes: 6 additions & 3 deletions devtools/bolt12-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ static u64 get_offer_type(const char *name)
* * [`tu64`:`max`]
* 1. type: 22 (`offer_issuer_id`)
* 2. data:
* * [`point`:`node_id`]
* * [`point`:`id`]
*/
{ "offer_chains", 2 },
{ "offer_metadata", 4 },
Expand Down Expand Up @@ -510,7 +510,7 @@ static u64 get_offer_type(const char *name)
* * [`tu64`:`max`]
* 1. type: 22 (`offer_issuer_id`)
* 2. data:
* * [`point`:`node_id`]
* * [`point`:`id`]
* 1. type: 80 (`invreq_chain`)
* 2. data:
* * [`chain_hash`:`chain`]
Expand Down Expand Up @@ -583,7 +583,7 @@ static u64 get_offer_type(const char *name)
* * [`tu64`:`max`]
* 1. type: 22 (`offer_issuer_id`)
* 2. data:
* * [`point`:`node_id`]
* * [`point`:`id`]
* 1. type: 80 (`invreq_chain`)
* 2. data:
* * [`chain_hash`:`chain`]
Expand All @@ -602,6 +602,9 @@ static u64 get_offer_type(const char *name)
* 1. type: 89 (`invreq_payer_note`)
* 2. data:
* * [`...*utf8`:`note`]
* 1. type: 90 (`invreq_paths`)
* 2. data:
* * [`...*blinded_path`:`paths`]
* 1. type: 160 (`invoice_paths`)
* 2. data:
* * [`...*blinded_path`:`paths`]
Expand Down
7 changes: 7 additions & 0 deletions doc/schemas/lightning-decode.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@
}
}
},
"warning_empty_blinded_path": {
"added": "v24.08",
"type": "string",
"description": [
"The blinded path has 0 hops."
]
},
"offer_node_id": {
"type": "pubkey",
"deprecated": [
Expand Down
15 changes: 9 additions & 6 deletions plugins/fetchinvoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ static struct command_result *handle_invreq_response(struct command *cmd,
}

/* BOLT-offers #12:
* - if `offer_node_id` or `offer_paths` are present (invoice_request for an offer):
* - MUST reject the invoice if `invoice_node_id` is not equal to the public key it sent the `invoice_request` to.
* - if `offer_issuer_id` is present (invoice_request for an offer):
* - MUST reject the invoice if `invoice_node_id` is not equal to `offer_issuer_id`
* - otherwise, if `offer_paths` is present (invoice_request for an offer without id):
* - MUST reject the invoice if `invoice_node_id` is not equal to the final
* `blinded_node_id` it sent the `invoice_request` to.
*/
if (!inv->invoice_node_id || !pubkey_eq(inv->offer_issuer_id, sent->issuer_key)) {
badfield = "invoice_node_id";
Expand Down Expand Up @@ -560,7 +563,7 @@ static struct command_result *try_establish(struct command *cmd,
target = first.pubkey;
/* BOLT-offers #12:
* - if `offer_issuer_id` is present (invoice_request for an offer):
* - MUST reject the invoice if `invoice_node_id` is not equal `offer_issuer_id`
* - MUST reject the invoice if `invoice_node_id` is not equal to `offer_issuer_id`
* - otherwise, if `offer_paths` is present (invoice_request for an offer without id):
* - MUST reject the invoice if `invoice_node_id` is not equal to the final `blinded_node_id` it sent the `invoice_request` to.
*/
Expand Down Expand Up @@ -1172,7 +1175,7 @@ static struct command_result *param_invreq(struct command *cmd,
* The reader:
* - MUST fail the request if `invreq_payer_id` or `invreq_metadata`
* are not present.
* - MUST fail the request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999.
* - MUST fail the request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999
* - if `invreq_features` contains unknown _odd_ bits that are
* non-zero:
* - MUST ignore the bit.
Expand Down Expand Up @@ -1229,7 +1232,7 @@ static struct command_result *param_invreq(struct command *cmd,
}

/* BOLT-offers #12:
* - otherwise (no `offer_node_id` or `offer_paths`, not a response to our offer):
* - otherwise (no `offer_issuer_id` or `offer_paths`, not a response to our offer):
* - MUST fail the request if any of the following are present:
* - `offer_chains`, `offer_features` or `offer_quantity_max`.
* - MUST fail the request if `invreq_amount` is not present.
Expand Down Expand Up @@ -1339,7 +1342,7 @@ struct command_result *json_sendinvoice(struct command *cmd,

/* BOLT-offers #12:
* - if `offer_issuer_id` is present:
* - MUST set `invoice_node_id` to `offer_issuer_id`.
* - MUST set `invoice_node_id` to the `offer_issuer_id`
* - otherwise, if `offer_paths` is present:
* - MUST set `invoice_node_id` to the final `blinded_node_id` on the path it received the `invoice_request`
* - otherwise:
Expand Down
14 changes: 14 additions & 0 deletions plugins/offers.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,19 @@ static bool json_add_blinded_paths(struct json_stream *js,
return false;
}

/* BOLT-offers #12:
* - if `num_hops` is 0 in any `blinded_path` in `offer_paths`:
* - MUST NOT respond to the offer.
*/
for (size_t i = 0; i < tal_count(paths); i++) {
if (tal_count(paths[i]->path) == 0) {
json_add_str_fmt(js, "warning_empty_blinded_path",
"blinded path %zu has 0 hops",
i);
return false;
}
}

return true;
}

Expand Down Expand Up @@ -1011,6 +1024,7 @@ static void json_add_b12_invoice(struct json_stream *js,
/* BOLT-offers #12:
* - MUST reject the invoice if `invoice_paths` is not present
* or is empty.
* - MUST reject the invoice if `num_hops` is 0 in any `blinded_path` in `invoice_paths`.
* - MUST reject the invoice if `invoice_blindedpay` is not present.
* - MUST reject the invoice if `invoice_blindedpay` does not contain
* exactly one `blinded_payinfo` per `invoice_paths`.`blinded_path`.
Expand Down
17 changes: 6 additions & 11 deletions plugins/offers_inv_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,11 @@ static struct command_result *listinvreqs_done(struct command *cmd,
* - if the invoice is a response to an `invoice_request`:
* - MUST reject the invoice if all fields in ranges 0 to 159 and 1000000000 to 2999999999 (inclusive) do not exactly match the `invoice_request`.
* - if `offer_issuer_id` is present (invoice_request for an offer):
* - MUST reject the invoice if `invoice_node_id` is not equal to `offer_issuer_id`.
* - MUST reject the invoice if `invoice_node_id` is not equal to `offer_issuer_id`
* - otherwise, if `offer_paths` is present (invoice_request for an offer without id):
* - MUST reject the invoice if `invoice_node_id` is not equal to the final `blinded_node_id` it sent the `invoice_request` to.
* - otherwise (invoice_request without an offer):
* - MAY reject the invoice if it cannot confirm that `invoice_node_id` is correct, out-of-band.
*
* - otherwise: (a invoice presented without being requested, eg. scanned by user):
*/

/* Since the invreq_id hashes all fields in those ranges, we know it matches */
Expand Down Expand Up @@ -317,26 +315,23 @@ struct command_result *handle_invoice(struct command *cmd,
* A reader of an invoice:
*...
* - MUST reject the invoice if `invoice_paths` is not present or is empty.
* - MUST reject the invoice if `num_hops` is 0 in any `blinded_path` in `invoice_paths`.
* - MUST reject the invoice if `invoice_blindedpay` is not present.
* - MUST reject the invoice if `invoice_blindedpay` does not contain exactly one `blinded_payinfo` per `invoice_paths`.`blinded_path`.
*/
if (!inv->inv->invoice_paths)
return fail_inv(cmd, inv, "Missing invoice_paths");
for (size_t i = 0; i < tal_count(inv->inv->invoice_paths); i++) {
if (tal_count(inv->inv->invoice_paths[i]->path) == 0)
return fail_inv(cmd, inv, "Empty path in invoice_paths");
}
if (!inv->inv->invoice_blindedpay)
return fail_inv(cmd, inv, "Missing invoice_blindedpay");
if (tal_count(inv->inv->invoice_blindedpay)
!= tal_count(inv->inv->invoice_paths))
return fail_inv(cmd, inv,
"Mismatch between invoice_blindedpay and invoice_paths");

/* BOLT-offers #12:
* - MUST reject the invoice if `num_hops` is 0 in any `blinded_path` in `invoice_paths`.
*/
for (size_t i = 0; i < tal_count(inv->inv->invoice_paths); i++) {
if (tal_count(inv->inv->invoice_paths[i]->path) == 0)
return fail_inv(cmd, inv, "Empty path in invoice_paths");
}

/* BOLT-offers #12:
* A reader of an invoice:
*...
Expand Down
2 changes: 1 addition & 1 deletion plugins/offers_invreq_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ static struct command_result *listoffers_done(struct command *cmd,

/* BOLT-offers #12:
* - if `offer_issuer_id` is present:
* - MUST set `invoice_node_id` to `offer_issuer_id`.
* - MUST set `invoice_node_id` to the `offer_issuer_id`
*/
/* FIXME: We always provide an offer_issuer_id! */
ir->inv->invoice_node_id = ir->inv->offer_issuer_id;
Expand Down
2 changes: 1 addition & 1 deletion plugins/offers_offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ struct command_result *json_invoicerequest(struct command *cmd,
/* BOLT-offers #12:
* - otherwise (not responding to an offer):
*...
* - MUST set `invreq_payer_id` as it would set `offer_issuer_id` for an offer.
* - MUST set `invreq_payer_id` (as it would set `offer_issuer_id` for an offer).
*/
/* FIXME: Allow invoicerequests using aliases! */
invreq->invreq_payer_id = tal_dup(invreq, struct pubkey, &id);
Expand Down

0 comments on commit d1e83aa

Please sign in to comment.