diff --git a/src/descriptor.c b/src/descriptor.c index 7c92aa121..6df46ebfd 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -4370,6 +4370,11 @@ static int ensure_unique_key_set(const ms_ctx *ctx, const unsigned char *pubkeys bool across_multipaths) { const uint32_t num_multipaths = ctx->num_multipaths; + size_t key_offset = 0, key_len = EC_PUBLIC_KEY_LEN; + if (ctx->features & (WALLY_MS_IS_TAPROOT|WALLY_MS_IS_TAPSCRIPT)) { + key_offset = 1; + key_len = EC_XONLY_PUBLIC_KEY_LEN; + } for (size_t i = 0; i < num_indices; ++i) { for (size_t j = i + 1; j < num_indices; ++j) { @@ -4379,8 +4384,9 @@ static int ensure_unique_key_set(const ms_ctx *ctx, const unsigned char *pubkeys const uint32_t m_end = across_multipaths ? num_multipaths : m_i + 1; for (uint32_t m_j = m_start; m_j < m_end; ++m_j) { - if (!memcmp(lhs, get_derived_pubkey(ctx, pubkeys, m_j, indices[j]), - EC_PUBLIC_KEY_LEN)) + if (!memcmp(lhs + key_offset, + get_derived_pubkey(ctx, pubkeys, m_j, indices[j]) + key_offset, + key_len)) return WALLY_EINVAL; /* Duplicate key found */ } } diff --git a/src/psbt.c b/src/psbt.c index 1626b008d..a297206fd 100644 --- a/src/psbt.c +++ b/src/psbt.c @@ -3889,7 +3889,8 @@ static int combine_output(struct wally_psbt_output *dst, if (ret == WALLY_OK && PSET_BLINDING_STATE_REQUIRED(dst_state) && PSET_BLINDING_STATE_REQUIRED(src_state)) { /* Both outputs require blinding */ - if (!dst->blinder_index || dst->blinder_index != src->blinder_index || + if (!dst->has_blinder_index || !src->has_blinder_index || + dst->blinder_index != src->blinder_index || !map_find_equal_integer(&dst->pset_fields, &src->pset_fields, PSET_OUT_BLINDING_PUBKEY)) ret = WALLY_EINVAL; /* Blinding index/pubkey do not match */ @@ -3898,7 +3899,7 @@ static int combine_output(struct wally_psbt_output *dst, if (ret == WALLY_OK && PSET_BLINDING_STATE_FULL(src_state)) { /* The source is fully blinded, either copy or verify the fields */ uint32_t ft; - for (ft = PSET_OUT_VALUE_COMMITMENT; ret == WALLY_OK && ft <= PSET_OUT_ASSET_SURJECTION_PROOF; ++ft) { + for (ft = PSET_OUT_VALUE_COMMITMENT; ret == WALLY_OK && ft <= PSET_OUT_ECDH_PUBKEY; ++ft) { if (!(PSET_OUT_BLINDING_FIELDS & PSET_FT(ft))) continue; if (PSET_BLINDING_STATE_FULL(dst_state)) { @@ -3913,6 +3914,29 @@ static int combine_output(struct wally_psbt_output *dst, from->value, from->value_len); } } + /* The explicit proofs go with the commitments: take the source's + * if we copied its commitments, or if we have none of our own */ + for (ft = PSET_OUT_BLIND_VALUE_PROOF; ret == WALLY_OK && ft <= PSET_OUT_BLIND_ASSET_PROOF; ++ft) { + if (PSET_BLINDING_STATE_FULL(dst_state)) + ret = combine_map_item(&dst->pset_fields, &src->pset_fields, ft); + else { + const struct wally_map_item *from; + from = wally_map_get_integer(&src->pset_fields, ft); + if (from) + ret = wally_map_replace_integer(&dst->pset_fields, ft, + from->value, from->value_len); + else + ret = wally_map_remove_integer(&dst->pset_fields, ft); + } + } + if (ret == WALLY_OK && !PSET_BLINDING_STATE_REQUIRED(dst_state)) { + /* We copied the blinding pubkey: its blinder index goes with it */ + if (!dst->has_blinder_index) { + dst->blinder_index = src->blinder_index; + dst->has_blinder_index = src->has_blinder_index; + } else if (src->has_blinder_index && dst->blinder_index != src->blinder_index) + ret = WALLY_EINVAL; /* Blinding index does not match */ + } } } #endif /* BUILD_ELEMENTS */ diff --git a/src/transaction.c b/src/transaction.c index 2dbce3171..a143eb3ae 100644 --- a/src/transaction.c +++ b/src/transaction.c @@ -971,11 +971,16 @@ int wally_tx_elements_output_commitment_free( #ifdef BUILD_ELEMENTS if (output) { output->features &= ~WALLY_TX_IS_ELEMENTS; - clear_and_free(output->asset, output->asset_len); - clear_and_free(output->value, output->value_len); - clear_and_free(output->nonce, output->nonce_len); - clear_and_free(output->surjectionproof, output->surjectionproof_len); - clear_and_free(output->rangeproof, output->rangeproof_len); + +#define FREE_PTR_AND_LEN(name) clear_and_free(output->name, output->name ## _len); \ + output->name = NULL; output->name ## _len = 0 + + FREE_PTR_AND_LEN(asset); + FREE_PTR_AND_LEN(value); + FREE_PTR_AND_LEN(nonce); + FREE_PTR_AND_LEN(surjectionproof); + FREE_PTR_AND_LEN(rangeproof); +#undef FREE_PTR_AND_LEN } #endif /* BUILD_ELEMENTS */ return WALLY_OK;