Skip to content

Commit

Permalink
have towire_wally_psbt and fromwire_wally_psbt set safe psbt version
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs authored and rustyrussell committed Apr 11, 2023
1 parent 650443e commit e30f2cb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,24 @@ struct wally_psbt *psbt_from_bytes(const tal_t *ctx, const u8 *bytes,

void towire_wally_psbt(u8 **pptr, const struct wally_psbt *psbt)
{
struct wally_psbt *psbt_copy;

/* Let's include the PSBT bytes */
size_t bytes_written;
const u8 *pbt_bytes = psbt_get_bytes(NULL, psbt, &bytes_written);
const u8 *psbt_bytes = psbt_get_bytes(NULL, psbt, &bytes_written);

/* When sending to other processes, set to v0 for compat */
psbt_copy = psbt_from_bytes(NULL, psbt_bytes, bytes_written);
tal_free(psbt_bytes);
if (!is_elements(chainparams))
psbt_set_version(psbt_copy, 0);

const u8 *psbt_bytes_copy = psbt_get_bytes(NULL, psbt_copy, &bytes_written);

towire_u32(pptr, bytes_written);
towire_u8_array(pptr, pbt_bytes, bytes_written);
tal_free(pbt_bytes);
towire_u8_array(pptr, psbt_bytes_copy, bytes_written);
tal_free(psbt_bytes_copy);
tal_free(psbt_copy);
}

struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx,
Expand Down Expand Up @@ -773,6 +785,9 @@ struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx,
tal_free(tmpbuf);
#endif

/* Internally we always operate on v2 */
psbt_set_version(psbt, 2);

return psbt;
}

Expand Down

0 comments on commit e30f2cb

Please sign in to comment.