Skip to content

Commit 0c63d01

Browse files
committed
BOLT12: don't allow zero-amount offers.
And enhance some of our quotes to use `...` at the start to link them. As they were, we didn't notice when a new requirement appeared in the middle. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 00ff0a0 commit 0c63d01

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CCANDIR := ccan
3333

3434
# Where we keep the BOLT RFCs
3535
BOLTDIR := ../bolts/
36-
DEFAULT_BOLTVERSION := 7153bed9705d7493065d9b818d25b282ef0a7c5e
36+
DEFAULT_BOLTVERSION := 311119388a46dfa859da3d2eda0ca836cfc5f078
3737
# Can be overridden on cmdline.
3838
BOLTVERSION := $(DEFAULT_BOLTVERSION)
3939

‎common/bolt12.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,17 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
227227
}
228228

229229
/* BOLT #12:
230-
*
230+
*...
231+
* - if `offer_amount` is set and is not greater than zero:
232+
* - MUST NOT respond to the offer.
233+
*/
234+
if (offer->offer_amount && *offer->offer_amount == 0) {
235+
*fail = tal_strdup(ctx, "Offer contains a zero amount");
236+
return tal_free(offer);
237+
}
238+
239+
/* BOLT #12:
240+
*...
231241
* - if `offer_currency` is set and `offer_amount` is not set:
232242
* - MUST NOT respond to the offer.
233243
*/
@@ -237,7 +247,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
237247
}
238248

239249
/* BOLT #12:
240-
*
250+
*...
241251
* - if neither `offer_issuer_id` nor `offer_paths` are set:
242252
* - MUST NOT respond to the offer.
243253
*/
@@ -247,6 +257,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
247257
}
248258

249259
/* BOLT #12:
260+
*...
250261
* - if `num_hops` is 0 in any `blinded_path` in `offer_paths`:
251262
* - MUST NOT respond to the offer.
252263
*/

‎common/test/run-bolt12-encode-test.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ int main(int argc, char *argv[])
429429
/* BOLT #12:
430430
* - if `offer_amount` is set and `offer_description` is not set:
431431
* - MUST NOT respond to the offer.
432+
* - if `offer_amount` is set and is not greater than zero:
433+
* - MUST NOT respond to the offer.
432434
* - if `offer_currency` is set and `offer_amount` is not set:
433435
* - MUST NOT respond to the offer.
434436
* - if neither `offer_issuer_id` nor `offer_paths` are set:
@@ -438,8 +440,18 @@ int main(int argc, char *argv[])
438440
print_invalid_offer(offer, "Missing offer_description and offer_amount");
439441
offer->offer_description = tal_utf8(tmpctx, "Test vectors");
440442

443+
offer->offer_amount = tal(offer, u64);
444+
*offer->offer_amount = 0;
445+
print_invalid_offer(offer, "Zero offer_amount");
446+
offer->offer_amount = tal_free(offer->offer_amount);
447+
441448
offer->offer_currency = tal_utf8(offer, "USD");
442449
print_invalid_offer(offer, "Missing offer_amount with offer_currency");
450+
451+
offer->offer_amount = tal(offer, u64);
452+
*offer->offer_amount = 0;
453+
print_invalid_offer(offer, "Zero offer_amount with currency");
454+
offer->offer_amount = tal_free(offer->offer_amount);
443455
offer->offer_currency = NULL;
444456

445457
offer->offer_issuer_id = NULL;

‎common/test/run-bolt12-format-string-test.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ int main(int argc, char *argv[])
128128
* - SHOULD omit `offer_chains`, implying that bitcoin is only chain.
129129
* - if a specific minimum `offer_amount` is required for successful payment:
130130
* - MUST set `offer_amount` to the amount expected (per item).
131+
* - MUST set `offer_amount` greater than zero.
131132
* - if the currency for `offer_amount` is that of all entries in `chains`:
132133
* - MUST specify `offer_amount` in multiples of the minimum lightning-payable unit
133134
* (e.g. milli-satoshis for bitcoin).

‎devtools/bolt12-cli.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static bool print_offer_amount(const struct bitcoin_blkid *chains,
9595
/* BOLT #12:
9696
* - if a specific minimum `offer_amount` is required for successful payment:
9797
* - MUST set `offer_amount` to the amount expected (per item).
98+
* - MUST set `offer_amount` greater than zero.
9899
* - if the currency for `offer_amount` is that of all entries in `chains`:
99100
* - MUST specify `offer_amount` in multiples of the minimum lightning-payable unit
100101
* (e.g. milli-satoshis for bitcoin).
@@ -150,6 +151,10 @@ static bool print_offer_amount(const struct bitcoin_blkid *chains,
150151
currency);
151152
}
152153

154+
if (amount == 0) {
155+
printf(" *** INVALID zero offer_amount");
156+
ok = false;
157+
}
153158
return ok;
154159
}
155160

0 commit comments

Comments
 (0)