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).
This commit is contained in:
niftynei 2022-10-07 14:13:38 -05:00 committed by neil saitug
parent 1c5edc14a5
commit 49ed0a4b9e
2 changed files with 14 additions and 2 deletions

View file

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

View file

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