pytest: create warning if we grind signature shorter than 71 bytes, don't fail.
One in 256 times, we will grind a signature to 70 bytes (or shorter). This breaks our feerate tests. Unfortunately the grinding is deterministic, so there doesn't seem to be a way to avoid it. So we add a log message, and then we skip the feerate test if it happens. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -442,8 +442,11 @@ static struct io_plan *preinit_hsm(struct io_conn *conn,
|
||||
if (tlv->no_preapprove_check)
|
||||
dev_no_preapprove_check = *tlv->no_preapprove_check;
|
||||
|
||||
status_debug("preinit: dev_fail_preapprove = %u, dev_no_preapprove_check = %u",
|
||||
dev_fail_preapprove, dev_no_preapprove_check);
|
||||
if (tlv->warn_on_overgrind)
|
||||
dev_warn_on_overgrind = *tlv->warn_on_overgrind;
|
||||
|
||||
status_debug("preinit: dev_fail_preapprove = %u, dev_no_preapprove_check = %u, dev_warn_on_overgrind = %u",
|
||||
dev_fail_preapprove, dev_no_preapprove_check, dev_warn_on_overgrind);
|
||||
/* We don't send a reply, just read next */
|
||||
return client_read_next(conn, c);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ tlvtype,hsmd_dev_preinit_tlvs,fail_preapprove,1
|
||||
tlvdata,hsmd_dev_preinit_tlvs,fail_preapprove,fail,bool,
|
||||
tlvtype,hsmd_dev_preinit_tlvs,no_preapprove_check,3
|
||||
tlvdata,hsmd_dev_preinit_tlvs,no_preapprove_check,disable,bool,
|
||||
tlvtype,hsmd_dev_preinit_tlvs,warn_on_overgrind,5
|
||||
tlvdata,hsmd_dev_preinit_tlvs,warn_on_overgrind,enable,bool,
|
||||
|
||||
#include <bitcoin/chainparams.h>
|
||||
# Start the HSM.
|
||||
|
||||
|
@@ -40,6 +40,7 @@ bool initialized = false;
|
||||
/* Do we fail all preapprove requests? */
|
||||
bool dev_fail_preapprove = false;
|
||||
bool dev_no_preapprove_check = false;
|
||||
bool dev_warn_on_overgrind = false;
|
||||
|
||||
struct hsmd_client *hsmd_client_new_main(const tal_t *ctx, u64 capabilities,
|
||||
void *extra)
|
||||
@@ -553,6 +554,7 @@ static void sign_our_inputs(struct hsm_utxo **utxos, struct wally_psbt *psbt)
|
||||
for (size_t j = 0; j < psbt->num_inputs; j++) {
|
||||
struct privkey privkey;
|
||||
struct pubkey pubkey;
|
||||
bool needed_sig;
|
||||
|
||||
if (!wally_psbt_input_spends(&psbt->inputs[j],
|
||||
&utxo->outpoint))
|
||||
@@ -590,6 +592,10 @@ static void sign_our_inputs(struct hsm_utxo **utxos, struct wally_psbt *psbt)
|
||||
wally_psbt_signing_cache_enable(psbt, 0);
|
||||
is_cache_enabled = true;
|
||||
}
|
||||
|
||||
/* We watch for pre-taproot variable-length sigs */
|
||||
needed_sig = (psbt->inputs[j].signatures.num_items == 0);
|
||||
|
||||
if (wally_psbt_sign(psbt, privkey.secret.data,
|
||||
sizeof(privkey.secret.data),
|
||||
EC_FLAG_GRIND_R) != WALLY_OK) {
|
||||
@@ -602,6 +608,14 @@ static void sign_our_inputs(struct hsm_utxo **utxos, struct wally_psbt *psbt)
|
||||
j, fmt_pubkey(tmpctx, &pubkey),
|
||||
fmt_wally_psbt(tmpctx, psbt));
|
||||
}
|
||||
if (dev_warn_on_overgrind
|
||||
&& needed_sig
|
||||
&& psbt->inputs[j].signatures.num_items == 1
|
||||
&& psbt->inputs[j].signatures.items[0].value_len < 71) {
|
||||
hsmd_status_fmt(LOG_BROKEN, NULL,
|
||||
"overgrind: short signature length %zu",
|
||||
psbt->inputs[j].signatures.items[0].value_len);
|
||||
}
|
||||
tal_wally_end(psbt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,4 +100,6 @@ extern struct secret *dev_force_bip32_seed;
|
||||
extern bool dev_fail_preapprove;
|
||||
/* If they specify --dev-no-preapprove-check it ends up in here. */
|
||||
extern bool dev_no_preapprove_check;
|
||||
/* If they specify --dev-warn-on-overgrind it ends up in here. */
|
||||
extern bool dev_warn_on_overgrind;
|
||||
#endif /* LIGHTNING_HSMD_LIBHSMD_H */
|
||||
|
||||
Reference in New Issue
Block a user