diff --git a/bitcoin/test/run-bitcoin_block_from_hex.c b/bitcoin/test/run-bitcoin_block_from_hex.c new file mode 100644 index 000000000..18a8fd3a0 --- /dev/null +++ b/bitcoin/test/run-bitcoin_block_from_hex.c @@ -0,0 +1,98 @@ +#include "../block.c" +#include "../pullpush.c" +#include "../shadouble.c" +#include "../tx.c" +#include "../varint.c" +#include + +static const char block[] = + "00a09265c15bea24321eecadb27ddf660035ac1f2b450ec03b973e17310f000" + "0000000008a0ee58ded5de949325ebc99583e3ca84f96a6597465c611685413" + "f50f0ead7eafdc6a5c00013f1a3580194903010000000001010000000000000" + "000000000000000000000000000000000000000000000000000ffffffff2703" + "9985161a4d696e656420627920416e74506f6f6c2094000103208efc8ad9030" + "00000101f0100ffffffff02d2545402000000001976a9144afc312d452c9c49" + "9fb8662728b19ac0cd3ea68888ac0000000000000000266a24aa21a9ed08b1d" + "c37da139ccd00803738db33e05331819736b3336352dc6e2fa74f1fd67b0120" + "000000000000000000000000000000000000000000000000000000000000000" + "00000000001000000019b1a8eaec64d596296c3abe9af09cce1dc09996a9ad0" + "84aaef0e4f79eb13f1e400000000fd5e0100483045022100b16d81821baf80d" + "6af47afea73cbd3f013bf4905c87ba896ed6e545dd00edd3a0220043262bf51" + "fe21b22b74a3ed148396077da75969e76b5fd647cda138f323634d014830450" + "22100a2b86c9e21b5b8ff0b185e42274bfe1ef6c8d4ec6e43c174bfdac360b6" + "8ac2b80220440a60482cfccd5c384c7d62e16e03a86295224b3ef82fb6f7d29" + "42657a4b330014cc95241048aa0d470b7a9328889c84ef0291ed30346986e22" + "558e80c3ae06199391eae21308a00cdcfb34febc0ea9c80dfd16b01f26c7ec6" + "7593cb8ab474aca8fa1d7029d4104cf54956634c4d0bdaf00e6b1871c089b7a" + "892d0fecc077f03b91e8d4d146861b0a4fdd237891a9819c878984d4b123f6f" + "e92d9bbc05873a1bb4fe510145bf369410471843c33b2971e4944c73d4500ab" + "d6f61f7edf9ec919c408cbe12a6c9132d2cb8ebed8253322760d5ec6081165e" + "0ab68900683de503f1544f03816d47fec699a53aeffffffff02707712000000" + "00001976a9147e1d98594b7b8417ed905904bad4d0de0217ee0288acc9a20a0" + "20000000017a9145629021f7668d4ec310ac5e99701a6d6cf95eb8f87000000" + "0003000000046113feede7973b484e4b8605d4f8cf2d498c98cef1a30898eb2" + "5e0958805031c000000006a47304402207afc3e15fc3c3657981cd4e0cf8afc" + "2c62bf37efa7f92eef669d1b4ec0701c93022057bbcb4bb3b5b7b7341d708e8" + "bf62975013f658c29fcd22482307b4ee8e223b3012103585914f7d7e37df12b" + "df0171503922c86ea2c9f09d4f20c40660a74c883687adffffffff6d2663970" + "ee08fbbf1dd9a30ba71ef1bc196cba2b9f6a19db1af4c7995003e8500000000" + "6b483045022100906fd4411926dca316ba7127e7072bd0691481883811856ff" + "81e4f9c526ec08e022005afc833c37cec7b87c58a8eec66704a0ed277f8e497" + "f7512b9cefae3d50d3db012103585914f7d7e37df12bdf0171503922c86ea2c" + "9f09d4f20c40660a74c883687adffffffff8356393fa3711040b67f221f1246" + "4ea09a770381130b4070bf8514307decba18010000006a47304402200657e98" + "4c480a37e2d73534d8314e2a73d315cb2934ad47a84d1ca9f5304332702206b" + "212bb3ec549c39dca2f5e7ba5f8ba6020f5d4a975433a2334ceb8ff2f040590" + "12103585914f7d7e37df12bdf0171503922c86ea2c9f09d4f20c40660a74c88" + "3687adffffffffca9dd5661fc8caf4e5e75aa218c29a004a1d18a6461c493ef" + "7c29e9cb77b54c9010000006b483045022100da7635fdaa91d5c293915802b4" + "d02a044cd64548b8c23bfaaeec47d25d6039df022053927423c4d29c9a30458" + "a837b6715ff50a3a2f5e97268cf606d9a52a30fa486012103585914f7d7e37d" + "f12bdf0171503922c86ea2c9f09d4f20c40660a74c883687adffffffff02404" + "20f00000000001976a914a2fdc4acc57254d6922607cd02b4826bb458528288" + "ac0eb82500000000001976a914e05655a7d90b01ba874d81beff57ee09610ca" + "3ce88ac00000000"; + +STRUCTEQ_DEF(sha256_double, 0, sha); + +int main(void) +{ + struct bitcoin_blkid prev; + struct sha256_double merkle; + struct bitcoin_txid txid, expected_txid; + struct bitcoin_block *b; + + setup_locale(); + b = bitcoin_block_from_hex(NULL, block, strlen(block)); + + assert(b); + assert(b->hdr.version == CPU_TO_LE32(0x6592a000)); + bitcoin_blkid_from_hex("0000000000000f31173e973bc00e452b1fac350066df7db2adec1e3224ea5bc1", strlen("0000000000000f31173e973bc00e452b1fac350066df7db2adec1e3224ea5bc1"), &prev); + assert(bitcoin_blkid_eq(&prev, &b->hdr.prev_hash)); + hex_decode("8a0ee58ded5de949325ebc99583e3ca84f96a6597465c611685413f50f0ead7e", strlen("8a0ee58ded5de949325ebc99583e3ca84f96a6597465c611685413f50f0ead7e"), &merkle, sizeof(merkle)); + assert(sha256_double_eq(&merkle, &b->hdr.merkle_hash)); + assert(b->hdr.timestamp == CPU_TO_LE32(1550507183)); + assert(b->hdr.nonce == CPU_TO_LE32(1226407989)); + + assert(tal_count(b->tx) == 3); + bitcoin_txid(b->tx[0], &txid); + bitcoin_txid_from_hex("14d86acd2158acd1f59ab77ab251e3f5073db905a7b2aed25d3ba7780c3d790c", + strlen("14d86acd2158acd1f59ab77ab251e3f5073db905a7b2aed25d3ba7780c3d790c"), + &expected_txid); + assert(bitcoin_txid_eq(&txid, &expected_txid)); + + bitcoin_txid(b->tx[1], &txid); + bitcoin_txid_from_hex("c261a53121cc9841f843e2e6e0cff337e4f3c5eee788c982a0bffe771ce69919", + strlen("c261a53121cc9841f843e2e6e0cff337e4f3c5eee788c982a0bffe771ce69919"), + &expected_txid); + assert(bitcoin_txid_eq(&txid, &expected_txid)); + + bitcoin_txid(b->tx[2], &txid); + bitcoin_txid_from_hex("80cea306607b708a03a1854520729da884e4317b7b51f3d4a622f88176f5e034", + strlen("80cea306607b708a03a1854520729da884e4317b7b51f3d4a622f88176f5e034"), + &expected_txid); + assert(bitcoin_txid_eq(&txid, &expected_txid)); + + tal_free(b); + return 0; +} diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 6b7e2bda9..e7534474a 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -345,7 +345,8 @@ int main(void) const struct chainparams *chainparams = chainparams_for_network("bitcoin"); wally_init(0); - secp256k1_ctx = wally_get_secp_context(); + /* FIXME: https://github.com/ElementsProject/libwally-core/issues/95 */ + secp256k1_ctx = (secp256k1_context *)wally_get_secp_context(); setup_tmpctx(); feerate_per_kw = tal_arr(tmpctx, u32, NUM_SIDES); diff --git a/common/daemon.c b/common/daemon.c index fc93c1793..194c15c1f 100644 --- a/common/daemon.c +++ b/common/daemon.c @@ -149,7 +149,8 @@ void daemon_setup(const char *argv0, /* We handle write returning errors! */ signal(SIGPIPE, SIG_IGN); wally_init(0); - secp256k1_ctx = wally_get_secp_context(); + /* FIXME: https://github.com/ElementsProject/libwally-core/issues/95 */ + secp256k1_ctx = (secp256k1_context *)wally_get_secp_context(); setup_tmpctx(); io_poll_override(daemon_poll); diff --git a/common/sphinx.c b/common/sphinx.c index 03b226340..40ed4c2a0 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -216,7 +216,8 @@ static bool create_shared_secret( const u8 *sessionkey) { - if (secp256k1_ecdh(secp256k1_ctx, secret, &pubkey->pubkey, sessionkey) + if (secp256k1_ecdh(secp256k1_ctx, secret, &pubkey->pubkey, sessionkey, + NULL, NULL) != 1) return false; return true; diff --git a/common/test/run-bolt11.c b/common/test/run-bolt11.c index 97ecfe971..992fffbcf 100644 --- a/common/test/run-bolt11.c +++ b/common/test/run-bolt11.c @@ -130,7 +130,8 @@ int main(void) const char *badstr; wally_init(0); - secp256k1_ctx = wally_get_secp_context(); + /* FIXME: https://github.com/ElementsProject/libwally-core/issues/95 */ + secp256k1_ctx = (secp256k1_context *)wally_get_secp_context(); setup_tmpctx(); /* BOLT #11: diff --git a/common/test/run-derive_basepoints.c b/common/test/run-derive_basepoints.c index 0a4d8a0b3..7de3a119f 100644 --- a/common/test/run-derive_basepoints.c +++ b/common/test/run-derive_basepoints.c @@ -55,7 +55,8 @@ int main(void) struct info *baseline, *info; wally_init(0); - secp256k1_ctx = wally_get_secp_context(); + /* FIXME: https://github.com/ElementsProject/libwally-core/issues/95 */ + secp256k1_ctx = (secp256k1_context *)wally_get_secp_context(); baseline = new_info(ctx); assert(derive_basepoints(&baseline->seed, &baseline->funding_pubkey, &baseline->basepoints, diff --git a/common/test/run-features.c b/common/test/run-features.c index 8c33f4b80..16330fa90 100644 --- a/common/test/run-features.c +++ b/common/test/run-features.c @@ -15,7 +15,8 @@ int main(void) setup_locale(); wally_init(0); - secp256k1_ctx = wally_get_secp_context(); + /* FIXME: https://github.com/ElementsProject/libwally-core/issues/95 */ + secp256k1_ctx = (secp256k1_context *)wally_get_secp_context(); setup_tmpctx(); bits = tal_arr(tmpctx, u8, 0); diff --git a/connectd/handshake.c b/connectd/handshake.c index 63788de84..bdda3f415 100644 --- a/connectd/handshake.c +++ b/connectd/handshake.c @@ -547,7 +547,7 @@ static struct io_plan *act_two_initiator2(struct io_conn *conn, * 5. `es = ECDH(s.priv, re)` */ if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->re.pubkey, - h->e.priv.secret.data)) + h->e.priv.secret.data, NULL, NULL)) return handshake_failed(conn, h); SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss))); @@ -638,7 +638,8 @@ static struct io_plan *act_one_initiator(struct io_conn *conn, */ h->ss = tal(h, struct secret); if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, - &h->their_id.pubkey, h->e.priv.secret.data)) + &h->their_id.pubkey, h->e.priv.secret.data, + NULL, NULL)) return handshake_failed(conn, h); SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss->data, sizeof(h->ss->data))); @@ -739,7 +740,7 @@ static struct io_plan *act_three_responder2(struct io_conn *conn, * * where `e` is the responder's original ephemeral key */ if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->their_id.pubkey, - h->e.priv.secret.data)) + h->e.priv.secret.data, NULL, NULL)) return handshake_failed(conn, h); SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss))); @@ -814,7 +815,7 @@ static struct io_plan *act_two_responder(struct io_conn *conn, * during Act One */ if (!secp256k1_ecdh(secp256k1_ctx, h->ss->data, &h->re.pubkey, - h->e.priv.secret.data)) + h->e.priv.secret.data, NULL, NULL)) return handshake_failed(conn, h); SUPERVERBOSE("# ss=0x%s", tal_hexstr(tmpctx, h->ss, sizeof(*h->ss))); diff --git a/connectd/test/run-initiator-success.c b/connectd/test/run-initiator-success.c index eddd1ea05..28892dfa0 100644 --- a/connectd/test/run-initiator-success.c +++ b/connectd/test/run-initiator-success.c @@ -194,7 +194,7 @@ struct secret *hsm_do_ecdh(const tal_t *ctx, const struct pubkey *point) { struct secret *ss = tal(ctx, struct secret); if (secp256k1_ecdh(secp256k1_ctx, ss->data, &point->pubkey, - ls_priv.secret.data) != 1) + ls_priv.secret.data, NULL, NULL) != 1) return tal_free(ss); return ss; } diff --git a/connectd/test/run-responder-success.c b/connectd/test/run-responder-success.c index 8f2f3c9fe..f96760a37 100644 --- a/connectd/test/run-responder-success.c +++ b/connectd/test/run-responder-success.c @@ -191,7 +191,7 @@ struct secret *hsm_do_ecdh(const tal_t *ctx, const struct pubkey *point) { struct secret *ss = tal(ctx, struct secret); if (secp256k1_ecdh(secp256k1_ctx, ss->data, &point->pubkey, - ls_priv.secret.data) != 1) + ls_priv.secret.data, NULL, NULL) != 1) return tal_free(ss); return ss; } diff --git a/devtools/gossipwith.c b/devtools/gossipwith.c index 2c0b74490..f55edc286 100644 --- a/devtools/gossipwith.c +++ b/devtools/gossipwith.c @@ -77,7 +77,7 @@ struct secret *hsm_do_ecdh(const tal_t *ctx, const struct pubkey *point) { struct secret *ss = tal(ctx, struct secret); if (secp256k1_ecdh(secp256k1_ctx, ss->data, &point->pubkey, - notsosecret.data) != 1) + notsosecret.data, NULL, NULL) != 1) return tal_free(ss); return ss; } diff --git a/external/libwally-core b/external/libwally-core index c51bca337..f27740564 160000 --- a/external/libwally-core +++ b/external/libwally-core @@ -1 +1 @@ -Subproject commit c51bca3379545e1aaaa78a25cc2b73e589a6ad79 +Subproject commit f27740564955e9a63d2946bdb0099622c0977b6e diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index ae4cf23b0..924fc476c 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -582,7 +582,7 @@ static struct io_plan *handle_ecdh(struct io_conn *conn, * we kill them for bad randomness (~1 in 2^127 if ss.data is random) */ node_key(&privkey, NULL); if (secp256k1_ecdh(secp256k1_ctx, ss.data, &point.pubkey, - privkey.secret.data) != 1) { + privkey.secret.data, NULL, NULL) != 1) { return bad_req_fmt(conn, c, msg_in, "secp256k1_ecdh fail"); } diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 2bc1c855d..117cdc2f4 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -1187,7 +1187,8 @@ int main(void) setup_tmpctx(); wally_init(0); - secp256k1_ctx = wally_get_secp_context(); + /* FIXME: https://github.com/ElementsProject/libwally-core/issues/95 */ + secp256k1_ctx = (secp256k1_context *)wally_get_secp_context(); ld = tal(tmpctx, struct lightningd); ld->config = test_config;