Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/ctest/test_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ static const struct descriptor_test {
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - combo - any parent",
"pk(combo(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798))",
"sh(combo(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - combo - multi-child",
Expand Down Expand Up @@ -1275,7 +1275,7 @@ static const struct descriptor_test {
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - addr - any parent",
"pk(addr(bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3))",
"sh(addr(bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - raw - multi-child",
Expand All @@ -1289,7 +1289,7 @@ static const struct descriptor_test {
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - raw - any parent",
"pk(raw(000102030405060708090a0b0c0d0e0f))",
"sh(raw(000102030405060708090a0b0c0d0e0f))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - empty rawtr",
Expand All @@ -1301,12 +1301,16 @@ static const struct descriptor_test {
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - any parent",
"pk(rawtr(x_only))",
"sh(rawtr(x_only))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - uncompressed key",
"rawtr(uncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - explicit public key",
"rawtr(pk(key_1))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - rawtr - invalid public key",
"rawtr(uncompresseduncompressed)",
Expand All @@ -1321,12 +1325,16 @@ static const struct descriptor_test {
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - any parent",
"pk(tr(x_only))",
"sh(tr(x_only))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - uncompressed key",
"tr(uncompressed)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - explicit public key",
"tr(pk(key_1))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, 0, NULL, ""
},{
"descriptor - tr - invalid public key",
"tr(uncompresseduncompressed)",
Expand Down
18 changes: 9 additions & 9 deletions src/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ static bool is_identifer_char(char c)
static bool is_policy_start_char(char c) { return c == '@'; }
static bool is_policy_identifer_char(char c) { return c >= '0' && c <= '9'; }

static int canonicalize(const char *descriptor,
const struct wally_map *vars_in, uint32_t flags,
char **output, size_t *num_substitutions)
static int canonicalize_impl(const char *descriptor,
const struct wally_map *vars_in, uint32_t flags,
char **output, size_t *num_substitutions)
{
const size_t VAR_MAX_NAME_LEN = 16;
is_identifer_fn is_id_start = is_identifer_char, is_id_char = is_identifer_char;
Expand Down Expand Up @@ -696,7 +696,7 @@ static int verify_raw(ms_ctx *ctx, ms_node *node)

static int verify_raw_tr(ms_ctx *ctx, ms_node *node)
{
if (node->child->builtin || !(node->child->kind & KIND_KEY) ||
if (node->parent || node->child->builtin || !(node->child->kind & KIND_KEY) ||
node_has_uncompressed_key(ctx, node))
return WALLY_EINVAL;
node->type_properties = builtin_get(node)->type_properties;
Expand All @@ -708,7 +708,7 @@ static int verify_tr(ms_ctx *ctx, ms_node *node)
const uint32_t child_count = node_get_child_count(node);
if (child_count != 1u)
return WALLY_EINVAL; /* FIXME: Support script paths */
if (node->child->builtin || !(node->child->kind & KIND_KEY) ||
if (node->parent || node->child->builtin || !(node->child->kind & KIND_KEY) ||
node_has_uncompressed_key(ctx, node))
return WALLY_EINVAL;
node->type_properties = builtin_get(node)->type_properties;
Expand Down Expand Up @@ -1422,13 +1422,13 @@ static int generate_tr(ms_ctx *ctx, ms_node *node,
{
unsigned char tweaked[EC_PUBLIC_KEY_LEN];
unsigned char pubkey[EC_PUBLIC_KEY_UNCOMPRESSED_LEN + 1];
size_t pubkey_len;
size_t pubkey_len = 0;
int ret;

/* Generate a push of the x-only public key of our child */
const bool force_xonly = true;
ret = generate_pk_k_impl(ctx, node, pubkey, sizeof(pubkey), force_xonly, &pubkey_len);
if (pubkey_len != EC_XONLY_PUBLIC_KEY_LEN + 1)
if (ret != WALLY_OK || pubkey_len != EC_XONLY_PUBLIC_KEY_LEN + 1)
return WALLY_EINVAL; /* Should be PUSH_32 [x-only pubkey] */

/* Tweak it into a compressed pubkey */
Expand Down Expand Up @@ -2754,8 +2754,8 @@ int wally_descriptor_parse(const char *miniscript,
ctx->num_multipaths = 1;
ret = wally_map_init(vars_in ? vars_in->num_items : 1, NULL, &ctx->keys);
if (ret == WALLY_OK)
ret = canonicalize(miniscript, vars_in, flags & MS_FLAGS_CANONICALIZE,
&ctx->src, &num_substitutions);
ret = canonicalize_impl(miniscript, vars_in, flags & MS_FLAGS_CANONICALIZE,
&ctx->src, &num_substitutions);
if (ret == WALLY_OK) {
ctx->src_len = strlen(ctx->src);
ctx->features = WALLY_MS_IS_DESCRIPTOR; /* Un-set if miniscript found */
Expand Down
Loading