From 52e29b301217692d25f5a29453db96386a4d1b92 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 12 Mar 2025 21:29:10 +1300 Subject: [PATCH 1/3] wally: update libwally to 1.4.0 Changelog-Changed: Update libwally to 1.4.0 Signed-off-by: Jon Griffiths --- external/libwally-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libwally-core b/external/libwally-core index 11e1bf6d60a1..12f5ac4ccf0e 160000 --- a/external/libwally-core +++ b/external/libwally-core @@ -1 +1 @@ -Subproject commit 11e1bf6d60a13e82e1eeda307a776b3defa0a1d3 +Subproject commit 12f5ac4ccf0e24df90f764db4c516a7ab7b74ad3 From 9247ec94a5b2b4c44ebc39b914c61e0a10db326e Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 12 Mar 2025 21:40:14 +1300 Subject: [PATCH 2/3] psbt: avoid duplicating the input string when parsing from base64 Changelog-None Signed-off-by: Jon Griffiths --- bitcoin/psbt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index a1e19c401b19..f42261d89e53 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -761,10 +761,9 @@ struct wally_psbt *psbt_from_b64(const tal_t *ctx, size_t b64len) { struct wally_psbt *psbt; - char *str = tal_strndup(tmpctx, b64, b64len); tal_wally_start(); - if (wally_psbt_from_base64(str, /* flags */ 0, &psbt) == WALLY_OK) + if (wally_psbt_from_base64_n(b64, b64len, /* flags */ 0, &psbt) == WALLY_OK) tal_add_destructor(psbt, psbt_destroy); else psbt = NULL; From beffd0214927c87a6816d683ad6c24eaca2ae493 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 12 Mar 2025 21:53:47 +1300 Subject: [PATCH 3/3] hsmd: enable caching of sub-hashes when signing our PSBT inputs Enabling the cache makes signing significantly faster for segwit inputs, particularly taproot which was designed with caching in mind. Changelog-None Signed-off-by: Jon Griffiths --- hsmd/libhsmd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index d5ed6969a8ac..d5abcc750e1e 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -547,6 +547,7 @@ static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey, * add a partial sig for each */ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) { + bool is_cache_enabled = false; for (size_t i = 0; i < tal_count(utxos); i++) { struct utxo *utxo = utxos[i]; for (size_t j = 0; j < psbt->num_inputs; j++) { @@ -584,6 +585,11 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) utxo->amount); } tal_wally_start(); + if (!is_cache_enabled) { + /* Enable caching signature sub-hashes */ + wally_psbt_signing_cache_enable(psbt, 0); + is_cache_enabled = true; + } if (wally_psbt_sign(psbt, privkey.secret.data, sizeof(privkey.secret.data), EC_FLAG_GRIND_R) != WALLY_OK) {