Skip to content

Commit 13a7fd7

Browse files
committed
descriptor-policy: disallow solved cardinalities other than 1 and 2
Point 10 of the policy key requirements
1 parent 0ecb19e commit 13a7fd7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ctest/test_descriptor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,11 @@ static const struct descriptor_test {
14661466
"sh(multi(1,@0/<0;1>/*,@1/*))",
14671467
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
14681468
WALLY_MINISCRIPT_POLICY, NULL, ""
1469+
}, {
1470+
"policy errchk - invlid key cardinality",
1471+
"pkh(@0/<0;1;2>/*)",
1472+
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1473+
WALLY_MINISCRIPT_POLICY, NULL, ""
14691474
}
14701475
};
14711476

src/descriptor.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,9 +2613,12 @@ int wally_descriptor_parse(const char *miniscript,
26132613
flags, NULL, NULL, &ctx->top_node);
26142614
if (ret == WALLY_OK)
26152615
ret = node_generation_size(ctx->top_node, &ctx->script_len);
2616-
if (ret == WALLY_OK && (flags & WALLY_MINISCRIPT_POLICY) &&
2617-
ctx->num_keys != num_substitutions)
2618-
ret = WALLY_EINVAL;
2616+
if (ret == WALLY_OK && (flags & WALLY_MINISCRIPT_POLICY)) {
2617+
if (ctx->num_keys != num_substitutions)
2618+
ret = WALLY_EINVAL; /* A non-substituted key was present */
2619+
else if (ctx->num_variants > 1 || ctx->num_multipaths > 2)
2620+
ret = WALLY_EINVAL; /* Solved cardinality must be 1 or 2 */
2621+
}
26192622
}
26202623
if (ret != WALLY_OK) {
26212624
wally_descriptor_free(ctx);

0 commit comments

Comments
 (0)