Remove point32.

The x-only dream is dead.  Remove all trace.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-10-17 11:07:05 +10:30
parent 1cdf21678e
commit 662c6931f3
20 changed files with 8 additions and 226 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -8,7 +8,6 @@
#include <common/fp16.h>
struct node_id;
struct point32;
struct gossmap_node {
/* Offset in memory map for node_announce, or 0. */

View File

@ -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)

View File

@ -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,

View File

@ -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)
{

View File

@ -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);

View File

@ -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;

View File

@ -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),
]

View File

@ -65,10 +65,6 @@ def test_fundamental_types():
'2122232425262728292a2b2c2d2e2f30'
'3132333435363738393a3b3c3d3e3f40',
bytes(range(1, 65))]],
'point32': [['02030405060708090a0b0c0d0e0f10'
'1112131415161718191a1b1c1d1e1f20'
'21',
bytes(range(2, 34))]],
}
untested = set()

View File

@ -328,14 +328,6 @@ def _extra_validator(is_request: bool):
"""
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 _extra_validator(is_request: bool):
"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,

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -15,7 +15,6 @@
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <common/type_to_string.h>
#include <plugins/pay_point32.h>
#include <plugins/libplugin-pay.h>
#include <stdio.h>

View File

@ -1,20 +0,0 @@
#include <bitcoin/pubkey.h>
#include <common/gossmap.h>
#include <common/node_id.h>
#include <plugins/pay_point32.h>
/* 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;
}

View File

@ -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 */

View File

@ -1,68 +0,0 @@
/* Test conversion assumptions used by gossmap_guess_node_id */
#include "config.h"
#include <assert.h>
#include <bitcoin/privkey.h>
#include <common/amount.h>
#include <common/bigsize.h>
#include <common/channel_id.h>
#include <common/setup.h>
#include <stdio.h>
#include <wire/wire.h>
#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();
}

View File

@ -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