Skip to content

Commit

Permalink
BOLT12: remove -offers from bolt12 quotes, update them.
Browse files Browse the repository at this point in the history
Typo fixes and wording changes.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jan 28, 2025
1 parent f68f893 commit 06545b1
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 234 deletions.
63 changes: 31 additions & 32 deletions common/bolt12.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ bool bolt12_chains_match(const struct bitcoin_blkid *chains,
size_t max_num_chains,
const struct chainparams *must_be_chain)
{
/* BOLT-offers #12:
/* BOLT #12:
* - if the chain for the invoice is not solely bitcoin:
* - MUST specify `offer_chains` the offer is valid for.
* - otherwise:
* - MAY omit `offer_chains`, implying that bitcoin is only chain.
* - SHOULD omit `offer_chains`, implying that bitcoin is only chain.
*/
/* BOLT-offers #12:
/* BOLT #12:
* A reader of an offer:
*...
* - if `offer_chains` is not set:
Expand Down Expand Up @@ -194,7 +194,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
if (*fail)
return tal_free(offer);

/* BOLT-offers #12:
/* BOLT #12:
* A reader of an offer:
* - if the offer contains any TLV fields outside the inclusive ranges: 1 to 79 and 1000000000 to 1999999999:
* - MUST NOT respond to the offer.
Expand All @@ -214,7 +214,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
return tal_free(offer);
}

/* BOLT-offers #12:
/* BOLT #12:
*
* - if `offer_amount` is set and `offer_description` is not set:
* - MUST NOT respond to the offer.
Expand All @@ -224,7 +224,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
return tal_free(offer);
}

/* BOLT-offers #12:
/* BOLT #12:
*
* - if neither `offer_issuer_id` nor `offer_paths` are set:
* - MUST NOT respond to the offer.
Expand All @@ -234,7 +234,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
return tal_free(offer);
}

/* BOLT-offers #12:
/* BOLT #12:
* - if `num_hops` is 0 in any `blinded_path` in `offer_paths`:
* - MUST NOT respond to the offer.
*/
Expand Down Expand Up @@ -287,10 +287,10 @@ struct tlv_invoice_request *invrequest_decode(const tal_t *ctx,
if (*fail)
return tal_free(invrequest);

/* BOLT-offers #12:
/* BOLT #12:
* The reader:
*...
* - MUST fail the request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999
* - MUST reject the invoice request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999
*/
badf = any_field_outside_range(invrequest->fields, true,
0, 159,
Expand All @@ -302,9 +302,9 @@ struct tlv_invoice_request *invrequest_decode(const tal_t *ctx,
return tal_free(invrequest);
}

/* BOLT-offers #12:
/* BOLT #12:
* - if `num_hops` is 0 in any `blinded_path` in `invreq_paths`:
* - MUST fail the request.
* - MUST reject the invoice request.
*/
for (size_t i = 0; i < tal_count(invrequest->invreq_paths); i++) {
if (tal_count(invrequest->invreq_paths[i]->path) == 0) {
Expand Down Expand Up @@ -346,12 +346,11 @@ struct tlv_invoice *invoice_decode_minimal(const tal_t *ctx,
return NULL;
}

/* BOLT-offers #12:
/* BOLT #12:
* - if `invreq_chain` is not present:
* - MUST fail the request if bitcoin is not a supported chain.
* - otherwise:
* - MUST fail the request if `invreq_chain`.`chain` is not a
* supported chain.
* - MUST reject the invoice if bitcoin is not a supported chain.
* - otherwise:
* - MUST reject the invoice if `invreq_chain`.`chain` is not a supported chain.
* - if `invoice_features` contains unknown _odd_ bits that are non-zero:
* - MUST ignore the bit.
* - if `invoice_features` contains unknown _even_ bits that are non-zero:
Expand Down Expand Up @@ -412,7 +411,7 @@ static u64 time_change(u64 prevstart, u32 number,
u64 offer_period_start(u64 basetime, size_t n,
const struct recurrence *recur)
{
/* BOLT-offers-recurrence #12:
/* BOLT-recurrence #12:
* 1. A `time_unit` defining 0 (seconds), 1 (days), 2 (months),
* 3 (years).
*/
Expand All @@ -437,13 +436,13 @@ void offer_period_paywindow(const struct recurrence *recurrence,
u64 basetime, u64 period_idx,
u64 *start, u64 *end)
{
/* BOLT-offers-recurrence #12:
/* BOLT-recurrence #12:
* - if the offer contains `recurrence_paywindow`:
*/
if (recurrence_paywindow) {
u64 pstart = offer_period_start(basetime, period_idx,
recurrence);
/* BOLT-offers-recurrence #12:
/* BOLT-recurrence #12:
* - if the offer has a `recurrence_basetime` or the
* `recurrence_counter` is non-zero:
* - SHOULD NOT send an `invreq` for a period prior to
Expand All @@ -461,7 +460,7 @@ void offer_period_paywindow(const struct recurrence *recurrence,
&& recurrence_paywindow->seconds_after < 60)
*end = pstart + 60;
} else {
/* BOLT-offers-recurrence #12:
/* BOLT-recurrence #12:
* - otherwise:
* - SHOULD NOT send an `invreq` with
* `recurrence_counter` is non-zero for a period whose
Expand All @@ -473,7 +472,7 @@ void offer_period_paywindow(const struct recurrence *recurrence,
*start = offer_period_start(basetime, period_idx-1,
recurrence);

/* BOLT-offers-recurrence #12:
/* BOLT-recurrence #12:
* - SHOULD NOT send an `invreq` for a period which
* has already passed.
*/
Expand Down Expand Up @@ -502,7 +501,7 @@ struct tlv_invoice *invoice_decode(const tal_t *ctx,
if (*fail)
return tal_free(invoice);

/* BOLT-offers #12:
/* BOLT #12:
* A reader of an invoice:
* - MUST reject the invoice if `invoice_amount` is not present.
* - MUST reject the invoice if `invoice_created_at` is not present.
Expand All @@ -526,15 +525,15 @@ struct tlv_invoice *invoice_decode(const tal_t *ctx,
return tal_free(invoice);
}

/* BOLT-offers #12:
/* BOLT #12:
* - MUST reject the invoice if `invoice_paths` is not present or is
* empty. */
if (tal_count(invoice->invoice_paths) == 0) {
*fail = tal_strdup(ctx, "missing/empty invoice_paths");
return tal_free(invoice);
}

/* BOLT-offers #12:
/* BOLT #12:
* - MUST reject the invoice if `num_hops` is 0 in any
* `blinded_path` in `invoice_paths`.
*/
Expand All @@ -546,7 +545,7 @@ struct tlv_invoice *invoice_decode(const tal_t *ctx,
return tal_free(invoice);
}

/* BOLT-offers #12:
/* BOLT #12:
* - 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 All @@ -565,7 +564,7 @@ u64 invoice_expiry(const struct tlv_invoice *invoice)
{
u64 expiry;

/* BOLT-offers #12:
/* BOLT #12:
* - if `invoice_relative_expiry` is present:
* - MUST reject the invoice if the current time since 1970-01-01 UTC
* is greater than `invoice_created_at` plus `seconds_from_creation`.
Expand Down Expand Up @@ -639,7 +638,7 @@ static void calc_offer(const u8 *tlvstream, struct sha256 *id)
size_t start1, len1, start2, len2;
struct sha256_ctx ctx;

/* BOLT-offers #12:
/* BOLT #12:
* A writer of an offer:
* - MUST NOT set any TLV fields outside the inclusive ranges: 1 to 79 and 1000000000 to 1999999999.
*/
Expand Down Expand Up @@ -681,7 +680,7 @@ static void calc_invreq(const u8 *tlvstream, struct sha256 *id)
size_t start1, len1, start2, len2;
struct sha256_ctx ctx;

/* BOLT-offers #12:
/* BOLT #12:
* The writer:
*...
* - MUST NOT set any non-signature TLV fields outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999
Expand Down Expand Up @@ -712,7 +711,7 @@ void invoice_invreq_id(const struct tlv_invoice *invoice, struct sha256 *id)
}


/* BOLT-offers #12:
/* BOLT #12:
* ## Requirements for Invoice Requests
*
* The writer:
Expand Down Expand Up @@ -744,11 +743,11 @@ struct tlv_invoice *invoice_for_invreq(const tal_t *ctx,

towire_tlv_invoice_request(&wire, invreq);

/* BOLT-offers #12:
/* BOLT #12:
* A writer of an invoice:
*...
* - if the invoice is in response to an `invoice_request`:
* - MUST copy all non-signature fields from the `invoice_request` (including
* - MUST copy all non-signature fields from the invoice request (including
* unknown fields).
*/
len1 = tlv_span(wire, 0, 159, &start1);
Expand All @@ -765,7 +764,7 @@ struct tlv_invoice *invoice_for_invreq(const tal_t *ctx,

bool is_bolt12_signature_field(u64 typenum)
{
/* BOLT-offers #12:
/* BOLT #12:
* Each form is signed using one or more *signature TLV elements*: TLV
* types 240 through 1000 (inclusive). */
return typenum >= 240 && typenum <= 1000;
Expand Down
4 changes: 2 additions & 2 deletions common/bolt12.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

struct feature_set;

/* BOLT-offers #12:
/* BOLT #12:
* - if `invoice_relative_expiry` is present:
* - MUST reject the invoice if the current time since 1970-01-01 UTC
* is greater than `invoice_created_at` plus `seconds_from_creation`.
Expand Down Expand Up @@ -161,7 +161,7 @@ struct tlv_invoice_request *invoice_request_for_offer(const tal_t *ctx,
struct tlv_invoice *invoice_for_invreq(const tal_t *ctx,
const struct tlv_invoice_request *invreq);

/* BOLT-offers #12:
/* BOLT #12:
* Each form is signed using one or more *signature TLV elements*: TLV
* types 240 through 1000 (inclusive). */
bool is_bolt12_signature_field(u64 typenum);
Expand Down
10 changes: 5 additions & 5 deletions common/bolt12_merkle.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define SUPERVERBOSE(...)
#endif

/* BOLT-offers #12:
/* BOLT #12:
* Each form is signed using one or more *signature TLV elements*: TLV
* types 240 through 1000 (inclusive).
*/
Expand Down Expand Up @@ -39,7 +39,7 @@ static void sha256_update_tlvfield(struct sha256_ctx *ctx,
sha256_update(ctx, field->value, field->length);
}

/* BOLT-offers #12:
/* BOLT #12:
* Thus we define H(`tag`,`msg`) as SHA256(SHA256(`tag`) || SHA256(`tag`) || `msg`)*/
/* Create a sha256_ctx which has the tag part done. */
static void h_simpletag_ctx(struct sha256_ctx *sctx, const char *tag)
Expand All @@ -55,7 +55,7 @@ static void h_simpletag_ctx(struct sha256_ctx *sctx, const char *tag)
}


/* BOLT-offers #12:
/* BOLT #12:
* The Merkle tree's leaves are, in TLV-ascending order for each tlv:
* 1. The H("LnLeaf",tlv).
* 2. The H("LnNonce"||first-tlv,tlv-type) where first-tlv is the numerically-first TLV entry in the stream, and tlv-type is the "type" field (1-9 bytes) of the current tlv.
Expand Down Expand Up @@ -108,7 +108,7 @@ static void calc_lnleaf(const struct tlv_field *field, struct sha256 *hash)
SUPERVERBOSE(") -> %s\n", fmt_sha256(tmpctx, hash));
}

/* BOLT-offers #12:
/* BOLT #12:
* The Merkle tree inner nodes are H("LnBranch", lesser-SHA256||greater-SHA256)
*/
static struct sha256 *merkle_pair(const tal_t *ctx,
Expand Down Expand Up @@ -193,7 +193,7 @@ void merkle_tlv(const struct tlv_field *fields, struct sha256 *merkle)
tal_free(arr);
}

/* BOLT-offers #12:
/* BOLT #12:
* All signatures are created as per
* [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki)
* and tagged as recommended there. Thus we define H(`tag`,`msg`) as
Expand Down
6 changes: 3 additions & 3 deletions common/iso4217.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "config.h"
#include <wire/wire.h>

/* BOLT-offers #12:
/* BOLT #12:
*
* - 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
* - MUST specify `offer_currency` `iso4217` as an ISO 4217 three-letter code.
* - MUST specify `offer_amount` in the currency unit adjusted by the ISO 4217
* exponent (e.g. USD cents).
*/
struct iso4217_name_and_divisor {
Expand Down
2 changes: 1 addition & 1 deletion common/onion_message_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static bool decrypt_forwarding_onionmsg(const struct pubkey *path_key,
if (encmsg->path_id)
return false;

/* BOLT-offers #4:
/* BOLT #4:
* - if it is not the final node according to the onion encryption:
*...
* - if `next_node_id` is present:
Expand Down
15 changes: 10 additions & 5 deletions common/test/run-bolt12-encode-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ int main(int argc, char *argv[])
print_valid_offer(offer, "with blinded path via Bob (0x424242...), path_key 020202...",
"path is [id=02020202..., enc=0x00*16], [id=02020202..., enc=0x11*8]", NULL);

/* BOLT-offers #12:
/* BOLT #12:
* - 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.
Expand Down Expand Up @@ -386,7 +385,7 @@ int main(int argc, char *argv[])
"Malformed: invalid offer_issuer_id");

/* Now these are simply invalid, not bad encodings */
/* BOLT-offers #12:
/* BOLT #12:
* A reader of an offer:
* - if the offer contains any TLV fields outside the inclusive ranges: 1 to 79 and 1000000000 to 1999999999:
* - MUST NOT respond to the offer.
Expand Down Expand Up @@ -416,24 +415,30 @@ int main(int argc, char *argv[])

offer->offer_features = tal_arr(offer, u8, 0);
set_feature_bit(&offer->offer_features, 22);
/* BOLT-offers #12:
/* BOLT #12:
* - if `offer_features` contains unknown _even_ bits that are non-zero:
* - MUST NOT respond to the offer.
* - SHOULD indicate the unknown bit to the user.
*/
print_invalid_offer(offer, "Contains unknown feature 22");
offer->offer_features = NULL;

/* BOLT-offers #12:
/* BOLT #12:
* - if `offer_amount` is set and `offer_description` is not set:
* - MUST NOT respond to the offer.
* - if `offer_currency` is set and `offer_amount` is not set:
* - MUST NOT respond to the offer.
* - if neither `offer_issuer_id` nor `offer_paths` are set:
* - MUST NOT respond to the offer.
*/
offer->offer_description = NULL;
print_invalid_offer(offer, "Missing offer_description and offer_amount");
offer->offer_description = tal_utf8(tmpctx, "Test vectors");

offer->offer_currency = tal_utf8(offer, "USD");
print_invalid_offer(offer, "Missing offer_amount with offer_currency");
offer->offer_currency = NULL;

offer->offer_issuer_id = NULL;
print_invalid_offer(offer, "Missing offer_issuer_id and no offer_path");

Expand Down
Loading

0 comments on commit 06545b1

Please sign in to comment.