From 49ed0a4b9e9a11bade7d84fc7e9a4f8135ee5d67 Mon Sep 17 00:00:00 2001 From: niftynei Date: Fri, 7 Oct 2022 14:13:38 -0500 Subject: [PATCH] psbt: wipe global tx scriptSig/witness data after saved to PSBT The global tx should be "free from sin" (no scriptSig data, no witness stacks). --- bitcoin/psbt.c | 9 +++++++++ bitcoin/test/run-psbt-from-tx.c | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index 6f346b9db..13692c50b 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -90,12 +90,21 @@ struct wally_psbt *new_psbt(const tal_t *ctx, const struct wally_tx *wtx) wtx->inputs[i].script, wtx->inputs[i].script_len); assert(wally_err == WALLY_OK); + + /* Clear out script sig data */ + psbt->tx->inputs[i].script_len = 0; + tal_free(psbt->tx->inputs[i].script); + psbt->tx->inputs[i].script = NULL; } if (wtx->inputs[i].witness) { wally_err = wally_psbt_input_set_final_witness(&psbt->inputs[i], wtx->inputs[i].witness); assert(wally_err == WALLY_OK); + + /* Delete the witness data */ + wally_tx_witness_stack_free(psbt->tx->inputs[i].witness); + psbt->tx->inputs[i].witness = NULL; } } diff --git a/bitcoin/test/run-psbt-from-tx.c b/bitcoin/test/run-psbt-from-tx.c index bbcd1cd52..5aefcb9ed 100644 --- a/bitcoin/test/run-psbt-from-tx.c +++ b/bitcoin/test/run-psbt-from-tx.c @@ -101,9 +101,12 @@ int main(int argc, char *argv[]) tx2 = fromwire_bitcoin_tx(tmpctx, cast_const2(const u8 **, &msg), &len); + assert(tx2 != NULL); - /* FIXME: this should not be null! */ - assert(tx2 == NULL); + /* Witness/scriptsig data is saved down into psbt */ + assert(tx2->psbt->num_inputs == 1); + assert(tx2->psbt->inputs[0].final_scriptsig_len > 0); + assert(tx2->psbt->inputs[0].final_witness != NULL); common_shutdown(); return 0;