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

Signet update (stolen from PR #4068) #4078

Merged
merged 4 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ const struct chainparams networks[] = {
.bip32_privkey_version = BIP32_VER_TEST_PRIVATE},
.is_elements = false},
{.network_name = "signet",
.bip173_name = "sb",
.bip173_name = "tb",
.bip70_name = "signet",
.genesis_blockhash = {{{.u.u8 = {0xce, 0xbd, 0x8f, 0x6e, 0x69, 0x77, 0x30, 0xb7, 0x4c, 0x70, 0x9c, 0xdd, 0x1e, 0x6a, 0xba, 0xaf, 0x2a, 0xfc, 0x98, 0xbf, 0x4c, 0xff, 0xb2, 0x39, 0xf3, 0xdb, 0x44, 0x27, 0x64, 0x29, 0x00, 0x00}}}},
// 00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6
.genesis_blockhash = {{{.u.u8 = {0xf6, 0x1e, 0xee, 0x3b, 0x63, 0xa3, 0x80,
0xa4, 0x77, 0xa0, 0x63, 0xaf, 0x32, 0xb2,
0xbb, 0xc9, 0x7c, 0x9f, 0xf9, 0xf0, 0x1f,
0x2c, 0x42, 0x25, 0xe9, 0x73, 0x98, 0x81,
0x08, 0x00, 0x00, 0x00}}}},
.rpc_port = 38332,
.cli = "bitcoin-cli",
.cli_args = "-signet",
Expand All @@ -91,8 +96,8 @@ const struct chainparams networks[] = {
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
.when_lightning_became_cool = 1,
.p2pkh_version = 125,
.p2sh_version = 87,
.p2pkh_version = 111,
.p2sh_version = 196,
.testnet = true,
.bip32_key_version = {.bip32_pubkey_version = BIP32_VER_SIGT_PUBLIC, .bip32_privkey_version = BIP32_VER_SIGT_PRIVATE},
.is_elements = false,
Expand Down
22 changes: 18 additions & 4 deletions common/bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ struct bolt11 *new_bolt11(const tal_t *ctx,
/* Decodes and checks signature; returns NULL on error. */
struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
const struct feature_set *our_features,
const char *description, char **fail)
const char *description,
const struct chainparams *must_be_chain,
char **fail)
{
char *hrp, *amountstr, *prefix;
u5 *data;
Expand Down Expand Up @@ -602,9 +604,21 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
return decode_fail(b11, fail,
"Prefix '%s' does not start with ln", prefix);

b11->chain = chainparams_by_bip173(prefix + 2);
if (!b11->chain)
return decode_fail(b11, fail, "Unknown chain %s", prefix + 2);
/* Signet chose to use prefix 'tb', just like testnet. So we tread
* carefully here: */
if (must_be_chain) {
if (streq(prefix + 2, must_be_chain->bip173_name))
b11->chain = must_be_chain;
else
return decode_fail(b11, fail, "Prefix %s is not for %s",
prefix + 2,
must_be_chain->network_name);
} else {
b11->chain = chainparams_by_bip173(prefix + 2);
if (!b11->chain)
return decode_fail(b11, fail, "Unknown chain %s",
prefix + 2);
}

/* BOLT #11:
*
Expand Down
6 changes: 5 additions & 1 deletion common/bolt11.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ struct bolt11 {
/* Decodes and checks signature; returns NULL on error; description is
* (optional) out-of-band description of payment, for `h` field.
* fset is NULL to accept any features (usually not desirable!).
*
* if @must_be_chain is not NULL, fails unless it's this chain.
*/
struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
const struct feature_set *our_features,
const char *description, char **fail);
const char *description,
const struct chainparams *must_be_chain,
char **fail);

/* Initialize an empty bolt11 struct with optional amount */
struct bolt11 *new_bolt11(const tal_t *ctx,
Expand Down
2 changes: 1 addition & 1 deletion common/json_tok.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ struct command_result *param_feerate_val(struct command *cmd,
*
* This processes the address and returns a string if it is a Bech32
* address specified by BIP173. The string is set whether it is
* testnet ("tb"), mainnet ("bc"), regtest ("bcrt"), or signet ("sb")
* testnet or signet (both "tb"), mainnet ("bc"), regtest ("bcrt")
* It does not check, witness version and program size restrictions.
*
* Out: witness_version: Pointer to an int that will be updated to contain
Expand Down
27 changes: 14 additions & 13 deletions common/test/run-bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static void test_b11(const char *b11str,
char *reproduce;
struct bolt11_field *b11_extra, *expect_extra;

b11 = bolt11_decode(tmpctx, b11str, NULL, hashed_desc, &fail);
b11 = bolt11_decode(tmpctx, b11str, NULL, hashed_desc,
expect_b11->chain, &fail);
if (!b11)
errx(1, "%s:%u:%s", __FILE__, __LINE__, fail);

Expand Down Expand Up @@ -266,7 +267,7 @@ int main(void)

for (size_t i = 0; i <= strlen(badstr); i++) {
if (bolt11_decode(tmpctx, tal_strndup(tmpctx, badstr, i),
NULL, NULL, &fail))
NULL, NULL, NULL, &fail))
abort();
assert(strstr(fail, "Bad bech32")
|| strstr(fail, "Invoices must start with ln"));
Expand Down Expand Up @@ -462,19 +463,19 @@ int main(void)
/* Empty set of allowed bits, ensures this fails! */
fset = tal(tmpctx, struct feature_set);
fset->bits[BOLT11_FEATURE] = tal_arr(fset, u8, 0);
assert(!bolt11_decode(tmpctx, badstr, fset, NULL, &fail));
assert(!bolt11_decode(tmpctx, badstr, fset, NULL, NULL, &fail));
assert(streq(fail, "9: unknown feature bit 100"));

/* We'd actually allow this if we either (1) don't check, or (2) accept that feature in
* either compulsory or optional forms. */
assert(bolt11_decode(tmpctx, badstr, NULL, NULL, &fail));
assert(bolt11_decode(tmpctx, badstr, NULL, NULL, NULL, &fail));

set_feature_bit(&fset->bits[BOLT11_FEATURE], 100);
assert(bolt11_decode(tmpctx, badstr, fset, NULL,&fail));
assert(bolt11_decode(tmpctx, badstr, fset, NULL, NULL, &fail));

clear_feature_bit(fset->bits[BOLT11_FEATURE], 100);
set_feature_bit(&fset->bits[BOLT11_FEATURE], 101);
assert(bolt11_decode(tmpctx, badstr, fset, NULL, &fail));
assert(bolt11_decode(tmpctx, badstr, fset, NULL, NULL, &fail));

/* FIXME: quoting description in here causes a spurious mismatch! */
/* BOLT #11:
Expand Down Expand Up @@ -540,48 +541,48 @@ int main(void)
* > ### Bech32 checksum is invalid.
* > lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt
*/
assert(!bolt11_decode(tmpctx, "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt", NULL, NULL, NULL, &fail));
assert(streq(fail, "Bad bech32 string"));

/* BOLT #11:
* > ### Malformed bech32 string (no 1)
* > pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny
*/
assert(!bolt11_decode(tmpctx, "pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny", NULL, NULL, NULL, &fail));
assert(streq(fail, "Bad bech32 string"));

/* BOLT #11:
* > ### Malformed bech32 string (mixed case)
* > LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny
*/
assert(!bolt11_decode(tmpctx, "LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny", NULL, NULL, NULL, &fail));
assert(streq(fail, "Bad bech32 string"));

/* BOLT #11:
* > ### Signature is not recoverable.
* > lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq
*/
assert(!bolt11_decode(tmpctx, "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq", NULL, NULL, NULL, &fail));
assert(streq(fail, "signature recovery failed"));

/* BOLT #11:
* > ### String is too short.
* > lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh
*/
assert(!bolt11_decode(tmpctx, "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh", NULL, NULL, NULL, &fail));

/* BOLT #11:
* > ### Invalid multiplier
* > lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg
*/
assert(!bolt11_decode(tmpctx, "lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg", NULL, NULL, NULL, &fail));
assert(streq(fail, "Invalid amount postfix 'x'"));

/* BOLT #11:
* > ### Invalid sub-millisatoshi precision.
* > lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu7hqtk93pkf7sw55rdv4k9z2vj050rxdr6za9ekfs3nlt5lr89jqpdmxsmlj9urqumg0h9wzpqecw7th56tdms40p2ny9q4ddvjsedzcplva53s
*/
assert(!bolt11_decode(tmpctx, "lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu7hqtk93pkf7sw55rdv4k9z2vj050rxdr6za9ekfs3nlt5lr89jqpdmxsmlj9urqumg0h9wzpqecw7th56tdms40p2ny9q4ddvjsedzcplva53s", NULL, NULL, &fail));
assert(!bolt11_decode(tmpctx, "lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu7hqtk93pkf7sw55rdv4k9z2vj050rxdr6za9ekfs3nlt5lr89jqpdmxsmlj9urqumg0h9wzpqecw7th56tdms40p2ny9q4ddvjsedzcplva53s", NULL, NULL, NULL, &fail));
assert(streq(fail, "Invalid sub-millisatoshi amount '2500000001p'"));

/* FIXME: Test the others! */
Expand Down
2 changes: 1 addition & 1 deletion devtools/bolt11-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main(int argc, char *argv[])
errx(ERROR_USAGE, "Need argument\n%s",
opt_usage(argv[0], NULL));

b11 = bolt11_decode(ctx, argv[2], NULL, description, &fail);
b11 = bolt11_decode(ctx, argv[2], NULL, description, NULL, &fail);
if (!b11)
errx(ERROR_BAD_DECODE, "%s", fail);

Expand Down
3 changes: 2 additions & 1 deletion lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,8 @@ static struct command_result *json_decodepay(struct command *cmd,
NULL))
return command_param_failed();

b11 = bolt11_decode(cmd, str, cmd->ld->our_features, desc, &fail);
b11 = bolt11_decode(cmd, str, cmd->ld->our_features, desc, NULL,
&fail);

if (!b11) {
return command_fail(cmd, LIGHTNINGD, "Invalid bolt11: %s", fail);
Expand Down
3 changes: 2 additions & 1 deletion lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,8 @@ static struct command_result *json_listsendpays(struct command *cmd,
struct bolt11 *b11;
char *fail;

b11 = bolt11_decode(cmd, b11str, cmd->ld->our_features, NULL, &fail);
b11 = bolt11_decode(cmd, b11str, cmd->ld->our_features, NULL,
chainparams, &fail);
if (!b11) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Invalid bolt11: %s", fail);
Expand Down
4 changes: 3 additions & 1 deletion lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ void bitcoind_getutxout_(struct bitcoind *bitcoind UNNEEDED,
/* Generated stub for bolt11_decode */
struct bolt11 *bolt11_decode(const tal_t *ctx UNNEEDED, const char *str UNNEEDED,
const struct feature_set *our_features UNNEEDED,
const char *description UNNEEDED, char **fail UNNEEDED)
const char *description UNNEEDED,
const struct chainparams *must_be_chain UNNEEDED,
char **fail UNNEEDED)
{ fprintf(stderr, "bolt11_decode called!\n"); abort(); }
/* Generated stub for bolt11_encode_ */
char *bolt11_encode_(const tal_t *ctx UNNEEDED,
Expand Down
4 changes: 2 additions & 2 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ static struct command_result *json_pay(struct command *cmd,
return command_param_failed();

b11 = bolt11_decode(cmd, b11str, plugin_feature_set(cmd->plugin),
NULL, &fail);
NULL, chainparams, &fail);
if (!b11) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Invalid bolt11: %s", fail);
Expand Down Expand Up @@ -1983,7 +1983,7 @@ static struct command_result *json_paymod(struct command *cmd,
return command_param_failed();

b11 = bolt11_decode(cmd, b11str, plugin_feature_set(cmd->plugin),
NULL, &fail);
NULL, chainparams, &fail);
if (!b11)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Invalid bolt11: %s", fail);
Expand Down