From 1874976761d7f387df60d9c3ffe1baf29f332b22 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 17 Oct 2022 11:07:05 +1030 Subject: [PATCH] Remove point32. The x-only dream is dead. Remove all trace. Signed-off-by: Rusty Russell --- bitcoin/pubkey.c | 37 ---------- bitcoin/pubkey.h | 17 ----- common/gossmap.h | 1 - common/json_stream.c | 12 ---- common/json_stream.h | 6 -- common/node_id.c | 10 --- common/node_id.h | 4 -- common/type_to_string.h | 1 - .../pyln/proto/message/fundamental_types.py | 1 - .../tests/test_fundamental_types.py | 4 -- contrib/pyln-testing/pyln/testing/fixtures.py | 9 --- devtools/print_wire.c | 1 - devtools/print_wire.h | 1 - hsmd/libhsmd.c | 19 +----- plugins/Makefile | 4 +- plugins/pay.c | 1 - plugins/pay_point32.c | 20 ------ plugins/pay_point32.h | 12 ---- plugins/test/run-gossmap_guess_node_id.c | 68 ------------------- wire/extracted_bolt12_01_recurrence.patch | 6 +- 20 files changed, 8 insertions(+), 226 deletions(-) delete mode 100644 plugins/pay_point32.c delete mode 100644 plugins/pay_point32.h delete mode 100644 plugins/test/run-gossmap_guess_node_id.c diff --git a/bitcoin/pubkey.c b/bitcoin/pubkey.c index 90b30350fb09..b97379838b0d 100644 --- a/bitcoin/pubkey.c +++ b/bitcoin/pubkey.c @@ -125,40 +125,3 @@ void towire_pubkey(u8 **pptr, const struct pubkey *pubkey) towire(pptr, output, outputlen); } - -void fromwire_point32(const u8 **cursor, size_t *max, struct point32 *point32) -{ - u8 raw[33]; - struct pubkey pk; - - raw[0] = SECP256K1_TAG_PUBKEY_EVEN; - if (!fromwire(cursor, max, raw + 1, sizeof(raw) - 1)) - return; - - if (!pubkey_from_der(raw, sizeof(raw), &pk)) { - SUPERVERBOSE("not a valid point"); - fromwire_fail(cursor, max); - } else - point32->pubkey = pk.pubkey; -} - -void towire_point32(u8 **pptr, const struct point32 *point32) -{ - u8 output[33]; - struct pubkey pk; - - pk.pubkey = point32->pubkey; - pubkey_to_der(output, &pk); - towire(pptr, output + 1, sizeof(output) - 1); -} - -static char *point32_to_hexstr(const tal_t *ctx, const struct point32 *point32) -{ - u8 output[33]; - struct pubkey pk; - - pk.pubkey = point32->pubkey; - pubkey_to_der(output, &pk); - return tal_hexstr(ctx, output + 1, sizeof(output) - 1); -} -REGISTER_TYPE_TO_STRING(point32, point32_to_hexstr); diff --git a/bitcoin/pubkey.h b/bitcoin/pubkey.h index c5d4ffc6d2ab..f3231a8ba10f 100644 --- a/bitcoin/pubkey.h +++ b/bitcoin/pubkey.h @@ -19,14 +19,6 @@ struct pubkey { /* Define pubkey_eq (no padding) */ STRUCTEQ_DEF(pubkey, 0, pubkey.data); -/* FIXME: This is for the deprecated offers: it's represented x-only there */ -struct point32 { - /* Unpacked pubkey (as used by libsecp256k1 internally) */ - secp256k1_pubkey pubkey; -}; -/* Define point32_eq (no padding) */ -STRUCTEQ_DEF(point32, 0, pubkey.data); - /* Convert from hex string of DER (scriptPubKey from validateaddress) */ bool pubkey_from_hexstr(const char *derstr, size_t derlen, struct pubkey *key); @@ -64,13 +56,4 @@ void pubkey_to_hash160(const struct pubkey *pk, struct ripemd160 *hash); void towire_pubkey(u8 **pptr, const struct pubkey *pubkey); void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey); -/* FIXME: Old spec uses pubkey32 */ -#define pubkey32 point32 -#define towire_pubkey32 towire_point32 -#define fromwire_pubkey32 fromwire_point32 - -/* marshal/unmarshal functions */ -void towire_point32(u8 **pptr, const struct point32 *pubkey); -void fromwire_point32(const u8 **cursor, size_t *max, struct point32 *pubkey); - #endif /* LIGHTNING_BITCOIN_PUBKEY_H */ diff --git a/common/gossmap.h b/common/gossmap.h index 17348adadf74..5bda03c6e5bf 100644 --- a/common/gossmap.h +++ b/common/gossmap.h @@ -8,7 +8,6 @@ #include struct node_id; -struct point32; struct gossmap_node { /* Offset in memory map for node_announce, or 0. */ diff --git a/common/json_stream.c b/common/json_stream.c index ec1cfe7a16e7..7263c5e3c3f7 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -415,18 +415,6 @@ void json_add_pubkey(struct json_stream *response, json_add_hex(response, fieldname, der, sizeof(der)); } -void json_add_point32(struct json_stream *response, - const char *fieldname, - const struct point32 *key) -{ - struct pubkey pk; - u8 der[PUBKEY_CMPR_LEN]; - - pk.pubkey = key->pubkey; - pubkey_to_der(der, &pk); - json_add_hex(response, fieldname, der + 1, sizeof(der) - 1); -} - void json_add_bip340sig(struct json_stream *response, const char *fieldname, const struct bip340sig *sig) diff --git a/common/json_stream.h b/common/json_stream.h index 7b0601e82956..22786ce26bcb 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -19,7 +19,6 @@ struct io_conn; struct log; struct json_escape; struct pubkey; -struct point32; struct bip340sig; struct secret; struct node_id; @@ -271,11 +270,6 @@ void json_add_pubkey(struct json_stream *response, const char *fieldname, const struct pubkey *key); -/* '"fieldname" : "89abcdef..."' or "89abcdef..." if fieldname is NULL */ -void json_add_point32(struct json_stream *response, - const char *fieldname, - const struct point32 *key); - /* '"fieldname" : "89abcdef..."' or "89abcdef..." if fieldname is NULL */ void json_add_bip340sig(struct json_stream *response, const char *fieldname, diff --git a/common/node_id.c b/common/node_id.c index 1582d0981c18..1d1a1955f946 100644 --- a/common/node_id.c +++ b/common/node_id.c @@ -25,16 +25,6 @@ bool pubkey_from_node_id(struct pubkey *key, const struct node_id *id) sizeof(id->k)); } -WARN_UNUSED_RESULT -bool point32_from_node_id(struct point32 *key, const struct node_id *id) -{ - struct pubkey k; - if (!pubkey_from_node_id(&k, id)) - return false; - key->pubkey = k.pubkey; - return true; -} - /* It's valid if we can convert to a real pubkey. */ bool node_id_valid(const struct node_id *id) { diff --git a/common/node_id.h b/common/node_id.h index 5f9fbb1ff456..1f23c9d335fc 100644 --- a/common/node_id.h +++ b/common/node_id.h @@ -24,10 +24,6 @@ void node_id_from_pubkey(struct node_id *id, const struct pubkey *key); WARN_UNUSED_RESULT bool pubkey_from_node_id(struct pubkey *key, const struct node_id *id); -/* Returns false if not a valid pubkey: relatively expensive */ -WARN_UNUSED_RESULT -bool point32_from_node_id(struct point32 *key, const struct node_id *id); - /* Convert to hex string of SEC1 encoding. */ char *node_id_to_hexstr(const tal_t *ctx, const struct node_id *id); diff --git a/common/type_to_string.h b/common/type_to_string.h index 171ac476a843..deb297eefe4e 100644 --- a/common/type_to_string.h +++ b/common/type_to_string.h @@ -7,7 +7,6 @@ /* This must match the type_to_string_ cases. */ union printable_types { const struct pubkey *pubkey; - const struct point32 *point32; const struct node_id *node_id; const struct bitcoin_txid *bitcoin_txid; const struct bitcoin_blkid *bitcoin_blkid; diff --git a/contrib/pyln-proto/pyln/proto/message/fundamental_types.py b/contrib/pyln-proto/pyln/proto/message/fundamental_types.py index ac807e5e9c43..75aa4d640a61 100644 --- a/contrib/pyln-proto/pyln/proto/message/fundamental_types.py +++ b/contrib/pyln-proto/pyln/proto/message/fundamental_types.py @@ -297,7 +297,6 @@ def fundamental_types() -> List[FieldType]: # Extra types added in offers draft: IntegerType('utf8', 1, 'B'), FundamentalHexType('bip340sig', 64), - FundamentalHexType('point32', 32), ] diff --git a/contrib/pyln-proto/tests/test_fundamental_types.py b/contrib/pyln-proto/tests/test_fundamental_types.py index 85e98d8104ae..1c22f3a21596 100644 --- a/contrib/pyln-proto/tests/test_fundamental_types.py +++ b/contrib/pyln-proto/tests/test_fundamental_types.py @@ -65,10 +65,6 @@ def test_fundamental_types(): '2122232425262728292a2b2c2d2e2f30' '3132333435363738393a3b3c3d3e3f40', bytes(range(1, 65))]], - 'point32': [['02030405060708090a0b0c0d0e0f10' - '1112131415161718191a1b1c1d1e1f20' - '21', - bytes(range(2, 34))]], } untested = set() diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index 48ea599df488..795b67ecf246 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -328,14 +328,6 @@ def is_32byte_hex(self, instance): """ return self.is_type(instance, "hex") and len(instance) == 64 - def is_point32(checker, instance): - """x-only BIP-340 public key""" - if not checker.is_type(instance, "hex"): - return False - if len(instance) != 64: - return False - return True - def is_signature(checker, instance): """DER encoded secp256k1 ECDSA signature""" if not checker.is_type(instance, "hex"): @@ -414,7 +406,6 @@ def is_msat_or_any(checker, instance): "txid": is_txid, "signature": is_signature, "bip340sig": is_bip340sig, - "point32": is_point32, "short_channel_id": is_short_channel_id, "short_channel_id_dir": is_short_channel_id_dir, "outpoint": is_outpoint, diff --git a/devtools/print_wire.c b/devtools/print_wire.c index 742b72de6e32..9b1792f1525b 100644 --- a/devtools/print_wire.c +++ b/devtools/print_wire.c @@ -321,7 +321,6 @@ PRINTWIRE_STRUCT_TYPE_TO_STRING(bitcoin_blkid) PRINTWIRE_STRUCT_TYPE_TO_STRING(bitcoin_txid) PRINTWIRE_STRUCT_TYPE_TO_STRING(channel_id) PRINTWIRE_STRUCT_TYPE_TO_STRING(node_id) -PRINTWIRE_STRUCT_TYPE_TO_STRING(point32) PRINTWIRE_STRUCT_TYPE_TO_STRING(preimage) PRINTWIRE_STRUCT_TYPE_TO_STRING(pubkey) PRINTWIRE_STRUCT_TYPE_TO_STRING(sha256) diff --git a/devtools/print_wire.h b/devtools/print_wire.h index 3165e0e03abc..74607d1a550c 100644 --- a/devtools/print_wire.h +++ b/devtools/print_wire.h @@ -35,7 +35,6 @@ bool printwire_bitcoin_txid(const char *fieldname, const u8 **cursor, size_t *pl bool printwire_channel_id(const char *fieldname, const u8 **cursor, size_t *plen); bool printwire_amount_sat(const char *fieldname, const u8 **cursor, size_t *plen); bool printwire_amount_msat(const char *fieldname, const u8 **cursor, size_t *plen); -bool printwire_point32(const char *fieldname, const u8 **cursor, size_t *plen); bool printwire_preimage(const char *fieldname, const u8 **cursor, size_t *plen); bool printwire_pubkey(const char *fieldname, const u8 **cursor, size_t *plen); bool printwire_node_id(const char *fieldname, const u8 **cursor, size_t *plen); diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index 38a9b25f29be..107909dda3ae 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -222,29 +222,16 @@ static void node_key(struct privkey *node_privkey, struct pubkey *node_id) #endif } -/*~ This returns the secret and/or public x-only key for this node. */ -static void node_schnorrkey(secp256k1_keypair *node_keypair, - struct point32 *node_id32) +/*~ This returns the secret key for this node. */ +static void node_schnorrkey(secp256k1_keypair *node_keypair) { - secp256k1_keypair unused_kp; struct privkey node_privkey; - if (!node_keypair) - node_keypair = &unused_kp; - node_key(&node_privkey, NULL); if (secp256k1_keypair_create(secp256k1_ctx, node_keypair, node_privkey.secret.data) != 1) hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR, "Failed to derive keypair"); - - if (node_id32) { - if (secp256k1_keypair_pub(secp256k1_ctx, - &node_id32->pubkey, - node_keypair) != 1) - hsmd_status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Failed to derive keypair pub"); - } } /*~ This secret is the basis for all per-channel secrets: the per-channel seeds @@ -633,7 +620,7 @@ static u8 *handle_sign_bolt12(struct hsmd_client *c, const u8 *msg_in) sighash_from_merkle(messagename, fieldname, &merkle, &sha); if (!publictweak) { - node_schnorrkey(&kp, NULL); + node_schnorrkey(&kp); } else { /* If we're tweaking key, we use bolt12 key */ struct privkey tweakedkey; diff --git a/plugins/Makefile b/plugins/Makefile index b05936ae45b0..d6d7f3bec06a 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -1,5 +1,5 @@ -PLUGIN_PAY_SRC := plugins/pay.c plugins/pay_point32.c -PLUGIN_PAY_HEADER := plugins/pay_point32.h +PLUGIN_PAY_SRC := plugins/pay.c +PLUGIN_PAY_HEADER := PLUGIN_PAY_OBJS := $(PLUGIN_PAY_SRC:.c=.o) PLUGIN_AUTOCLEAN_SRC := plugins/autoclean.c diff --git a/plugins/pay.c b/plugins/pay.c index e1dafb64c089..55ddba0ef6bd 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include diff --git a/plugins/pay_point32.c b/plugins/pay_point32.c deleted file mode 100644 index 5884cf311375..000000000000 --- a/plugins/pay_point32.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include -#include - -/* There are two 33-byte pubkeys possible: choose the one which appears - * in the graph (otherwise payment will fail anyway). */ -void gossmap_guess_node_id(const struct gossmap *map, - const struct point32 *point32, - struct node_id *id) -{ - struct pubkey pk; - pk.pubkey = point32->pubkey; - node_id_from_pubkey(id, &pk); - - /* If we don't find this, let's assume it's the alternate. */ - if (!gossmap_find_node(map, id)) - id->k[0] |= 1; -} - diff --git a/plugins/pay_point32.h b/plugins/pay_point32.h deleted file mode 100644 index 1cc5cc43f99c..000000000000 --- a/plugins/pay_point32.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LIGHTNING_PLUGINS_PAY_POINT32_H -#define LIGHTNING_PLUGINS_PAY_POINT32_H - -struct gossmap; -struct point32; -struct node_id; - -void gossmap_guess_node_id(const struct gossmap *map, - const struct point32 *point32, - struct node_id *id); - -#endif /* LIGHTNING_PLUGINS_PAY_POINT32_H */ diff --git a/plugins/test/run-gossmap_guess_node_id.c b/plugins/test/run-gossmap_guess_node_id.c deleted file mode 100644 index 5c4a7c88eff1..000000000000 --- a/plugins/test/run-gossmap_guess_node_id.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Test conversion assumptions used by gossmap_guess_node_id */ -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - #include "../pay_point32.c" - -/* AUTOGENERATED MOCKS START */ -/* Generated stub for fromwire_bigsize */ -bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) -{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); } -/* Generated stub for fromwire_channel_id */ -bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, - struct channel_id *channel_id UNNEEDED) -{ fprintf(stderr, "fromwire_channel_id 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 gossmap_find_node */ -struct gossmap_node *gossmap_find_node(const struct gossmap *map UNNEEDED, - const struct node_id *id UNNEEDED) -{ fprintf(stderr, "gossmap_find_node called!\n"); abort(); } -/* Generated stub for node_id_from_pubkey */ -void node_id_from_pubkey(struct node_id *id UNNEEDED, const struct pubkey *key UNNEEDED) -{ fprintf(stderr, "node_id_from_pubkey called!\n"); abort(); } -/* Generated stub for towire_bigsize */ -void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED) -{ fprintf(stderr, "towire_bigsize called!\n"); abort(); } -/* Generated stub for towire_channel_id */ -void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) -{ fprintf(stderr, "towire_channel_id 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(); } -/* AUTOGENERATED MOCKS END */ - -int main(int argc, char *argv[]) -{ - common_setup(argv[0]); - - for (size_t i = 1; i < 255; i++) { - struct privkey priv; - secp256k1_keypair keypair; - secp256k1_pubkey pubkey; - secp256k1_xonly_pubkey xpubkey; - u8 output32[32]; - u8 output33[33]; - size_t len = sizeof(output33); - - memset(&priv, i, sizeof(priv)); - assert(secp256k1_keypair_create(secp256k1_ctx, &keypair, priv.secret.data) == 1); - assert(secp256k1_keypair_pub(secp256k1_ctx, &pubkey, &keypair) == 1); - assert(secp256k1_keypair_xonly_pub(secp256k1_ctx, &xpubkey, NULL, &keypair) == 1); - - assert(secp256k1_xonly_pubkey_serialize(secp256k1_ctx, output32, &xpubkey) == 1); - assert(secp256k1_ec_pubkey_serialize(secp256k1_ctx, output33, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); - assert(memcmp(output32, output33 + 1, sizeof(output32)) == 0); - assert(output33[0] == SECP256K1_TAG_PUBKEY_EVEN - || output33[0] == SECP256K1_TAG_PUBKEY_ODD); - } - common_shutdown(); -} diff --git a/wire/extracted_bolt12_01_recurrence.patch b/wire/extracted_bolt12_01_recurrence.patch index f0d524e86b67..5615856f1cfe 100644 --- a/wire/extracted_bolt12_01_recurrence.patch +++ b/wire/extracted_bolt12_01_recurrence.patch @@ -19,7 +19,7 @@ index 726c3c0a1..a53ca3cdf 100644 +tlvdata,offer,recurrence_base,start_any_period,byte, +tlvdata,offer,recurrence_base,basetime,tu64, tlvtype,offer,node_id,30 - tlvdata,offer,node_id,node_id,point32, + tlvdata,offer,node_id,node_id,pubkey, tlvtype,offer,send_invoice,54 @@ -40,6 +54,10 @@ tlvtype,invoice_request,features,12 tlvdata,invoice_request,features,features,byte,... @@ -30,7 +30,7 @@ index 726c3c0a1..a53ca3cdf 100644 +tlvtype,invoice_request,recurrence_start,68 +tlvdata,invoice_request,recurrence_start,period_offset,tu32, tlvtype,invoice_request,payer_key,38 - tlvdata,invoice_request,payer_key,key,point32, + tlvdata,invoice_request,payer_key,key,pubkey, tlvtype,invoice_request,payer_note,39 @@ -74,6 +94,12 @@ tlvtype,invoice,quantity,32 tlvdata,invoice,quantity,quantity,tu64, @@ -43,5 +43,5 @@ index 726c3c0a1..a53ca3cdf 100644 +tlvtype,invoice,recurrence_basetime,64 +tlvdata,invoice,recurrence_basetime,basetime,tu64, tlvtype,invoice,payer_key,38 - tlvdata,invoice,payer_key,key,point32, + tlvdata,invoice,payer_key,key,pubkey, tlvtype,invoice,payer_note,39