Skip to content

Commit

Permalink
descriptor-policy: disallow solved cardinalities other than 1 and 2
Browse files Browse the repository at this point in the history
Point 10 of the policy key requirements
  • Loading branch information
jgriffiths committed Sep 6, 2023
1 parent 0ecb19e commit 13a7fd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/ctest/test_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,11 @@ static const struct descriptor_test {
"sh(multi(1,@0/<0;1>/*,@1/*))",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
WALLY_MINISCRIPT_POLICY, NULL, ""
}, {
"policy errchk - invlid key cardinality",
"pkh(@0/<0;1;2>/*)",
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
WALLY_MINISCRIPT_POLICY, NULL, ""
}
};

Expand Down
9 changes: 6 additions & 3 deletions src/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2613,9 +2613,12 @@ int wally_descriptor_parse(const char *miniscript,
flags, NULL, NULL, &ctx->top_node);
if (ret == WALLY_OK)
ret = node_generation_size(ctx->top_node, &ctx->script_len);
if (ret == WALLY_OK && (flags & WALLY_MINISCRIPT_POLICY) &&
ctx->num_keys != num_substitutions)
ret = WALLY_EINVAL;
if (ret == WALLY_OK && (flags & WALLY_MINISCRIPT_POLICY)) {
if (ctx->num_keys != num_substitutions)
ret = WALLY_EINVAL; /* A non-substituted key was present */
else if (ctx->num_variants > 1 || ctx->num_multipaths > 2)
ret = WALLY_EINVAL; /* Solved cardinality must be 1 or 2 */
}
}
if (ret != WALLY_OK) {
wally_descriptor_free(ctx);
Expand Down

0 comments on commit 13a7fd7

Please sign in to comment.