Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BOLT11 test vectors, strengthen implementation. #3481

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,14 @@ static char *decode_f(struct bolt11 *b11,
fallback = scriptpubkey_witness_raw(b11, version,
f, tal_count(f));
tal_free(f);
} else
} else {
/* Restore version for unknown field! */
(*data)--;
(*data_len)++;
data_length++;
return unknown_field(b11, hu5, data, data_len, 'f',
data_length);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tab vs spaces mix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't fix current code. Will append a whitespace patch though


if (b11->fallbacks == NULL)
b11->fallbacks = tal_arr(b11, const u8 *, 1);
Expand Down
111 changes: 81 additions & 30 deletions common/test/run-bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,21 @@
#include "../features.c"
#include "../node_id.c"
#include "../hash_u5.c"
#include "../wire/fromwire.c"
#include "../wire/towire.c"
#include <ccan/err/err.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <stdio.h>
#include <wally_core.h>

/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_fail */
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
/* Generated stub for fromwire_node_id */
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
/* Generated stub for fromwire_short_channel_id */
void fromwire_short_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_short_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_u16 */
u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u16 called!\n"); abort(); }
/* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
/* Generated stub for towire_node_id */
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
/* Generated stub for towire_short_channel_id */
void towire_short_channel_id(u8 **pptr UNNEEDED,
const struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "towire_short_channel_id called!\n"); abort(); }
/* Generated stub for towire_u16 */
void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
{ fprintf(stderr, "towire_u16 called!\n"); abort(); }
/* Generated stub for towire_u32 */
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
{ fprintf(stderr, "towire_u32 called!\n"); abort(); }
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for type_to_string_ */
const char *type_to_string_(const tal_t *ctx UNNEEDED, const char *typename UNNEEDED,
union printable_types u UNNEEDED)
Expand Down Expand Up @@ -117,8 +96,22 @@ static void test_b11(const char *b11str,
expect_b11->fallbacks[i],
tal_count(expect_b11->fallbacks[i])));

/* FIXME: compare routes. */
assert(tal_count(b11->routes) == tal_count(expect_b11->routes));
for (size_t i = 0; i < tal_count(b11->routes); i++) {
assert(tal_count(b11->routes[i])
== tal_count(expect_b11->routes[i]));
for (size_t j = 0; j < tal_count(b11->routes[i]); j++) {
const struct route_info *r = &b11->routes[i][j],
*er = &expect_b11->routes[i][j];
assert(node_id_eq(&er->pubkey, &r->pubkey));
assert(er->cltv_expiry_delta == r->cltv_expiry_delta);
assert(short_channel_id_eq(&er->short_channel_id,
&r->short_channel_id));
assert(er->fee_base_msat == r->fee_base_msat);
assert(er->fee_proportional_millionths
== r->fee_proportional_millionths);
}
}

expect_extra = list_top(&expect_b11->extra_fields, struct bolt11_field,
list);
Expand Down Expand Up @@ -372,6 +365,64 @@ int main(void)
assert(!bolt11_decode(tmpctx, badstr, NULL, &fail));
assert(streq(fail, "9: unknown feature bit 100"));

/* BOLT-1fbccd30bb503203e4a255de67f9adb504563425 #11:
*
* > ### Please send 0.00967878534 BTC for a list of items within one week, amount in pico-BTC
* > lnbc9678785340p1pwmna7lpp5gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0sd8dgfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khxxqyjw5qcqp2rzjq0gxwkzc8w6323m55m4jyxcjwmy7stt9hwkwe2qxmy8zpsgg7jcuwz87fcqqeuqqqyqqqqlgqqqqn3qq9qn07ytgrxxzad9hc4xt3mawjjt8znfv8xzscs7007v9gh9j569lencxa8xeujzkxs0uamak9aln6ez02uunw6rd2ht2sqe4hz8thcdagpleym0j
*
* Breakdown:
*
* * `lnbc`: prefix, Lightning on bitcoin mainnet
* * `9678785340p`: amount (9678785340 pico-bitcoin = 967878534 milli satoshi)
* * `1`: Bech32 separator
* * `pwmna7l`: timestamp (1572468703)
* * `p`: payment hash.
* * `p5`: `data_length` (`p` = 1, `5` = 20; 1 * 32 + 20 == 52)
* * `gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0s`: payment hash 462264ede7e14047e9b249da94fefc47f41f7d02ee9b091815a5506bc8abf75f
* * `d`: short description
* * `8d`: `data_length` (`8` = 7, `d` = 13; 7 * 32 + 13 == 237)
* * `gfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khx`: 'Blockstream Store: 88.85 USD for Blockstream Ledger Nano S x 1, \"Back In My Day\" Sticker x 2, \"I Got Lightning Working\" Sticker x 2 and 1 more items'
* * `x`: expiry time
* * `qy`: `data_length` (`q` = 0, `y` = 2; 0 * 32 + 4 == 4)
* * `jw5q`: 604800 seconds (`j` = 18, `w` = 14, `5` = 20, `q` = 0; 18 * 32^3 + 14 * 32^2 + 20 * 32 + 0 == 604800)
* * `c`: `min_final_cltv_expiry`
* * `qp`: `data_length` (`q` = 0, `p` = 1; 0 * 32 + 1 == 1)
* * `2`: min_final_cltv_expiry = 10
* * `r`: tagged field: route information
* * `zj`: `data_length` (`z` = 2, `j` = 18; 2 * 32 + 18 == 82)
* * `q0gxwkzc8w6323m55m4jyxcjwmy7stt9hwkwe2qxmy8zpsgg7jcuwz87fcqqeuqqqyqqqqlgqqqqn3qq9q`:
* * pubkey: 03d06758583bb5154774a6eb221b1276c9e82d65bbaceca806d90e20c108f4b1c7
* * short_channel_id: 589390x3312x1
* * fee_base_msat = 1000
* * fee_proportional_millionths = 2500
* * cltv_expiry_delta = 40
* * `n07ytgrxxzad9hc4xt3mawjjt8znfv8xzscs7007v9gh9j569lencxa8xeujzkxs0uamak9aln6ez02uunw6rd2ht2sqe4hz8thcdagp`: signature
* * `leym0j`: Bech32 checksum
*/
msatoshi = AMOUNT_MSAT(967878534);
b11 = new_bolt11(tmpctx, &msatoshi);
b11->chain = chainparams_for_network("bitcoin");
b11->timestamp = 1572468703;
b11->expiry = 604800;
b11->min_final_cltv_expiry = 10;
if (!hex_decode("462264ede7e14047e9b249da94fefc47f41f7d02ee9b091815a5506bc8abf75f",
strlen("462264ede7e14047e9b249da94fefc47f41f7d02ee9b091815a5506bc8abf75f"),
&b11->payment_hash, sizeof(b11->payment_hash)))
abort();
b11->receiver_id = node;
b11->description = "Blockstream Store: 88.85 USD for Blockstream Ledger Nano S x 1, \"Back In My Day\" Sticker x 2, \"I Got Lightning Working\" Sticker x 2 and 1 more items";
b11->routes = tal_arr(tmpctx, struct route_info *, 1);
b11->routes[0] = tal(b11->routes, struct route_info);
if (!node_id_from_hexstr("03d06758583bb5154774a6eb221b1276c9e82d65bbaceca806d90e20c108f4b1c7", strlen("03d06758583bb5154774a6eb221b1276c9e82d65bbaceca806d90e20c108f4b1c7"), &b11->routes[0]->pubkey))
abort();
if (!short_channel_id_from_str("589390x3312x1", strlen("589390x3312x1"),
&b11->routes[0]->short_channel_id))
abort();
b11->routes[0]->fee_base_msat = 1000;
b11->routes[0]->fee_proportional_millionths = 2500;
b11->routes[0]->cltv_expiry_delta = 40;
test_b11("lnbc9678785340p1pwmna7lpp5gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0sd8dgfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khxxqyjw5qcqp2rzjq0gxwkzc8w6323m55m4jyxcjwmy7stt9hwkwe2qxmy8zpsgg7jcuwz87fcqqeuqqqyqqqqlgqqqqn3qq9qn07ytgrxxzad9hc4xt3mawjjt8znfv8xzscs7007v9gh9j569lencxa8xeujzkxs0uamak9aln6ez02uunw6rd2ht2sqe4hz8thcdagpleym0j", b11, NULL);

/* FIXME: Test the others! */
wally_cleanup(0);
tal_free(tmpctx);
Expand Down
7 changes: 4 additions & 3 deletions lightningd/test/run-find_my_abspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED)
/* Generated stub for version */
const char *version(void)
{ fprintf(stderr, "version called!\n"); abort(); }
/* Generated stub for waitblockheight_notify_new_block */
void waitblockheight_notify_new_block(struct lightningd *ld UNNEEDED,
u32 block_height UNNEEDED)
{ fprintf(stderr, "waitblockheight_notify_new_block called!\n"); abort(); }
/* Generated stub for wallet_blocks_heights */
void wallet_blocks_heights(struct wallet *w UNNEEDED, u32 def UNNEEDED, u32 *min UNNEEDED, u32 *max UNNEEDED)
{ fprintf(stderr, "wallet_blocks_heights called!\n"); abort(); }
Expand All @@ -192,9 +196,6 @@ bool wallet_network_check(struct wallet *w UNNEEDED)
/* Generated stub for wallet_new */
struct wallet *wallet_new(struct lightningd *ld UNNEEDED, struct timers *timers UNNEEDED)
{ fprintf(stderr, "wallet_new called!\n"); abort(); }
/* Generated stub for waitblockheight_notify_new_block */
void waitblockheight_notify_new_block(struct lightningd *ld UNNEEDED, u32 blockheight UNNEEDED)
{ fprintf(stderr, "waitblockheight_notify_new_block called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

struct log *crashlog;
Expand Down