Skip to content

Commit 944f266

Browse files
committed
psbt: use control block verification call internally
1 parent 7ecf1fa commit 944f266

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/psbt.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,22 +2217,15 @@ static int pull_taproot_leaf_signature(const unsigned char **cursor, size_t *max
22172217
return map_add(leaf_sigs, xonly_hash, 64u, val, val_len, false, false);
22182218
}
22192219

2220-
static bool is_valid_control_block_len(size_t ctrl_len)
2221-
{
2222-
return ctrl_len >= 33u && ctrl_len <= 33u + 128u * 32u &&
2223-
((ctrl_len - 33u) % 32u) == 0;
2224-
}
2225-
22262220
static int pull_taproot_leaf_script(const unsigned char **cursor, size_t *max,
22272221
const unsigned char **key, size_t *key_len,
22282222
struct wally_map *leaf_scripts)
22292223
{
2230-
/* TODO: use taproot constants here */
22312224
const unsigned char *ctrl, *val;
22322225
size_t ctrl_len = *key_len, val_len;
22332226

22342227
ctrl = pull_skip(key, key_len, ctrl_len);
2235-
if (!ctrl || !is_valid_control_block_len(ctrl_len))
2228+
if (wally_bip341_control_block_verify(ctrl, ctrl_len) != WALLY_OK)
22362229
return WALLY_EINVAL;
22372230
subfield_nomore_end(cursor, max, *key, *key_len);
22382231

@@ -2987,7 +2980,8 @@ static int push_taproot_leaf_scripts(unsigned char **cursor, size_t *max, size_t
29872980
for (i = 0; i < leaf_scripts->num_items; ++i) {
29882981
const struct wally_map_item *item = leaf_scripts->items + i;
29892982

2990-
if (!is_valid_control_block_len(item->key_len) || !item->value_len)
2983+
if (wally_bip341_control_block_verify(item->key, item->key_len) != WALLY_OK ||
2984+
!item->value_len)
29912985
return WALLY_EINVAL;
29922986

29932987
push_key(cursor, max, ft, false, item->key, item->key_len);

0 commit comments

Comments
 (0)