Skip to content

Commit

Permalink
Allow missing PSBT_IN_NON_WITNESS_UTXO if we have PSBT_IN_WITNESS_UTXO
Browse files Browse the repository at this point in the history
Fixes ([ElementsProject#6764])
Changelog-Fixed: Allow missing PSBT_IN_NON_WITNESS_UTXO if we have PSBT_IN_WITNESS_UTXO
  • Loading branch information
ksedgwic committed Oct 11, 2023
1 parent 1a46b37 commit 3ce0b9a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions common/psbt_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,24 @@ bool psbt_has_required_fields(struct wally_psbt *psbt)
if (!psbt_get_serial_id(&input->unknowns, &serial_id))
return false;

/* Required because we send the full tx over the wire now */
if (!input->utxo)
return false;
/* Only insist on PSBT_IN_NON_WITNESS_UTXO (.utxo) if
* PSBT_IN_WITNESS_UTXO (.witness_utxo) is not present
* because PSBT_IN_NON_WITNESS_UTXO uses a lot of
* memory */
if (!input->witness_utxo) {
/* Required because we send the full tx over the wire now */
if (!input->utxo)
return false;

/* If is P2SH, redeemscript must be present */
assert(psbt->inputs[i].index < input->utxo->num_outputs);
const u8 *outscript =
wally_tx_output_get_script(tmpctx,
&input->utxo->outputs[psbt->inputs[i].index]);
redeem_script = wally_map_get_integer(&psbt->inputs[i].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04);
if (is_p2sh(outscript, NULL) && (!redeem_script || redeem_script->value_len == 0))
return false;
/* If is P2SH, redeemscript must be present */
assert(psbt->inputs[i].index < input->utxo->num_outputs);
const u8 *outscript =
wally_tx_output_get_script(tmpctx,
&input->utxo->outputs[psbt->inputs[i].index]);
redeem_script = wally_map_get_integer(&psbt->inputs[i].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04);
if (is_p2sh(outscript, NULL) && (!redeem_script || redeem_script->value_len == 0))
return false;
}
}

for (size_t i = 0; i < psbt->num_outputs; i++) {
Expand Down

0 comments on commit 3ce0b9a

Please sign in to comment.