Skip to content

Commit ef7220b

Browse files
committed
descriptor-policy: rename flag to disambiguate from miniscript policy
1 parent f298a44 commit ef7220b

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

include/wally_descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct wally_descriptor;
1515
#define WALLY_MINISCRIPT_TAPSCRIPT 0x01 /** Tapscript, use x-only pubkeys */
1616
#define WALLY_MINISCRIPT_ONLY 0x02 /** Only allow miniscript (not descriptor) expressions */
1717
#define WALLY_MINISCRIPT_REQUIRE_CHECKSUM 0x04 /** Require a checksum to be present */
18-
#define WALLY_MINISCRIPT_POLICY 0x08 /** Only allow policy @n variable substitution */
18+
#define WALLY_MINISCRIPT_POLICY_TEMPLATE 0x08 /** Only allow policy templates with @n BIP32 keys */
1919
#define WALLY_MINISCRIPT_DEPTH_MASK 0xffff0000 /** Mask for limiting maximum depth */
2020
#define WALLY_MINISCRIPT_DEPTH_SHIFT 16 /** Shift to convert maximum depth to flags */
2121

src/ctest/test_descriptor.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -990,25 +990,25 @@ static const struct descriptor_test {
990990
}, {
991991
"policy - single asterisk",
992992
"pkh(@0/*)", // Becomes "pkh(mainnet_xpub/*)" i.e. the test case above this
993-
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY,
993+
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY_TEMPLATE,
994994
"76a914bb57ca9e62c7084081edc68d2cbc9524a523784288ac",
995995
"cp8r8rlg"
996996
}, {
997997
"policy - double asterisk",
998998
"pkh(@0/**)", // Becomes "pkh(mainnet_xpub/<0;1>/*)"
999-
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY,
999+
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY_TEMPLATE,
10001000
"76a9143099ad49dfdd021bf3748f7f858e0d1fa0b4f6f888ac",
10011001
"ydnzkve4"
10021002
}, {
10031003
"policy - multi-path",
10041004
"pkh(@0/<0;1>/*)", // Becomes "pkh(mainnet_xpub/<0;1>/*)"
1005-
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY,
1005+
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY_TEMPLATE,
10061006
"76a9143099ad49dfdd021bf3748f7f858e0d1fa0b4f6f888ac",
10071007
"ydnzkve4"
10081008
}, {
10091009
"policy - previous key reference",
10101010
"sh(multi(1,@0/**,@1/**,@0/**))", /* For testing: expresssion isn't sensible */
1011-
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY,
1011+
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL, WALLY_MINISCRIPT_POLICY_TEMPLATE,
10121012
"a91415b7de59bd65038744e3214a521d9d4443dc78c287",
10131013
"xwdj6ucy"
10141014
},
@@ -1425,57 +1425,57 @@ static const struct descriptor_test {
14251425
"policy errchk - no key expression",
14261426
"raw()",
14271427
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1428-
WALLY_MINISCRIPT_POLICY, NULL, ""
1428+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14291429
}, {
14301430
"policy errchk - key with path",
14311431
"pkh(@0/0/*)",
14321432
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1433-
WALLY_MINISCRIPT_POLICY, NULL, ""
1433+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14341434
}, {
14351435
"policy errchk - missing key postfix",
14361436
"pkh(@0)",
14371437
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1438-
WALLY_MINISCRIPT_POLICY, NULL, ""
1438+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14391439
}, {
14401440
"policy errchk - terminal key postfix",
14411441
"@0",
14421442
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1443-
WALLY_MINISCRIPT_POLICY, NULL, ""
1443+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14441444
}, {
14451445
"policy errchk - missing key number",
14461446
"@",
14471447
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1448-
WALLY_MINISCRIPT_POLICY, NULL, ""
1448+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14491449
}, {
14501450
"policy errchk - mis-ordered keys",
14511451
"sh(multi(1,@1/**,@0/**))",
14521452
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1453-
WALLY_MINISCRIPT_POLICY, NULL, ""
1453+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14541454
}, {
14551455
"policy errchk - non-policy keys",
14561456
"sh(multi(1,@0/**,xpub6AHA9hZDN11k2ijHMeS5QqHx2KP9aMBRhTDqANMnwVtdyw2TDYRmF8PjpvwUFcL1Et8Hj59S3gTSMcUQ5gAqTz3Wd8EsMTmF3DChhqPQBnU))",
14571457
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1458-
WALLY_MINISCRIPT_POLICY, NULL, ""
1458+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14591459
}, {
14601460
"policy errchk - mismatched key cardinalities (1)",
14611461
"sh(multi(1,@0/**,@1/*))",
14621462
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1463-
WALLY_MINISCRIPT_POLICY, NULL, ""
1463+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14641464
}, {
14651465
"policy errchk - mismatched key cardinalities (2)",
14661466
"sh(multi(1,@0/<0;1>/*,@1/*))",
14671467
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1468-
WALLY_MINISCRIPT_POLICY, NULL, ""
1468+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14691469
}, {
14701470
"policy errchk - invalid key cardinality (key path)",
14711471
"pkh(@0/<0;1;2>/*)",
14721472
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1473-
WALLY_MINISCRIPT_POLICY, NULL, ""
1473+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14741474
}, {
14751475
"policy errchk - invalid key cardinality (variant)",
14761476
"combo(@0/**)",
14771477
WALLY_NETWORK_BITCOIN_MAINNET, 0, 0, 0, NULL,
1478-
WALLY_MINISCRIPT_POLICY, NULL, ""
1478+
WALLY_MINISCRIPT_POLICY_TEMPLATE, NULL, ""
14791479
}
14801480
};
14811481

@@ -1924,7 +1924,7 @@ static bool check_descriptor_to_script(const struct descriptor_test* test)
19241924
int expected_ret, ret, len_ret;
19251925
uint32_t multi_index = 0;
19261926
uint32_t child_num = test->child_num ? *test->child_num : 0, features;
1927-
const bool is_policy = test->flags & WALLY_MINISCRIPT_POLICY;
1927+
const bool is_policy = test->flags & WALLY_MINISCRIPT_POLICY_TEMPLATE;
19281928
const struct wally_map *keys = is_policy ? &g_policy_map : &g_key_map;
19291929

19301930
expected_ret = test->script ? WALLY_OK : WALLY_EINVAL;

src/descriptor.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#define MS_FLAGS_ALL (WALLY_MINISCRIPT_TAPSCRIPT | \
1919
WALLY_MINISCRIPT_ONLY | \
2020
WALLY_MINISCRIPT_REQUIRE_CHECKSUM | \
21-
WALLY_MINISCRIPT_POLICY)
21+
WALLY_MINISCRIPT_POLICY_TEMPLATE)
2222
#define MS_FLAGS_CANONICALIZE (WALLY_MINISCRIPT_REQUIRE_CHECKSUM | \
23-
WALLY_MINISCRIPT_POLICY)
23+
WALLY_MINISCRIPT_POLICY_TEMPLATE)
2424

2525
/* Properties and expressions definition */
2626
#define TYPE_NONE 0x00
@@ -388,7 +388,7 @@ static int canonicalize(const char *descriptor,
388388
if (!descriptor || (flags & ~MS_FLAGS_CANONICALIZE))
389389
return WALLY_EINVAL;
390390

391-
if (flags & WALLY_MINISCRIPT_POLICY) {
391+
if (flags & WALLY_MINISCRIPT_POLICY_TEMPLATE) {
392392
if (!is_valid_policy_map(vars_in))
393393
return WALLY_EINVAL; /* Invalid policy variables given */
394394
is_id_start = is_policy_start_char;
@@ -421,7 +421,7 @@ static int canonicalize(const char *descriptor,
421421
}
422422
required_len += item->value_len;
423423
++*num_substitutions;
424-
if (flags & WALLY_MINISCRIPT_POLICY) {
424+
if (flags & WALLY_MINISCRIPT_POLICY_TEMPLATE) {
425425
int key_index = (int)(item - vars_in->items);
426426
if (key_index > key_index_hwm + 1)
427427
return WALLY_EINVAL; /* Must be ordered with no gaps */
@@ -452,7 +452,7 @@ static int canonicalize(const char *descriptor,
452452

453453
if (!*p && (flags & WALLY_MINISCRIPT_REQUIRE_CHECKSUM))
454454
return WALLY_EINVAL; /* Checksum required but not present */
455-
if (flags & WALLY_MINISCRIPT_POLICY) {
455+
if (flags & WALLY_MINISCRIPT_POLICY_TEMPLATE) {
456456
if (!found_policy_key)
457457
return WALLY_EINVAL; /* At least one key expression must be present */
458458
if (found_policy_single && found_policy_multi)
@@ -483,7 +483,7 @@ static int canonicalize(const char *descriptor,
483483
item = wally_map_get(vars_in, (unsigned char*)start, lookup_len);
484484
lookup_len = item ? item->value_len : lookup_len;
485485
memcpy(out, item ? (char *)item->value : start, lookup_len);
486-
if (item && flags & WALLY_MINISCRIPT_POLICY) {
486+
if (item && flags & WALLY_MINISCRIPT_POLICY_TEMPLATE) {
487487
if (p[1] == '*' && p[2] == '*') {
488488
out += lookup_len;
489489
lookup_len = strlen("/<0;1>/*");
@@ -2631,7 +2631,7 @@ int wally_descriptor_parse(const char *miniscript,
26312631
flags, NULL, NULL, &ctx->top_node);
26322632
if (ret == WALLY_OK)
26332633
ret = node_generation_size(ctx->top_node, &ctx->script_len);
2634-
if (ret == WALLY_OK && (flags & WALLY_MINISCRIPT_POLICY)) {
2634+
if (ret == WALLY_OK && (flags & WALLY_MINISCRIPT_POLICY_TEMPLATE)) {
26352635
if (ctx->keys.num_items != num_substitutions)
26362636
ret = WALLY_EINVAL; /* A non-substituted key was present */
26372637
else if (ctx->num_variants > 1 || ctx->num_multipaths > 2)

src/test/test_descriptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
MS_TAP = 0x1 # WALLY_MINISCRIPT_TAPSCRIPT
1414
MS_ONLY = 0x2 # WALLY_MINISCRIPT_ONLY
1515
REQUIRE_CHECKSUM = 0x4 # WALLY_MINISCRIPT_REQUIRE_CHECKSUM
16-
POLICY = 0x08 # WALLY_MINISCRIPT_POLICY
16+
POLICY = 0x08 # WALLY_MINISCRIPT_POLICY_TEMPLATE
1717

1818
MS_IS_RANGED = 0x1
1919
MS_IS_MULTIPATH = 0x2

src/wasm_package/src/const.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const WALLY_MAX_OP_RETURN_LEN = 80; /* Maximum length of OP_RETURN data p
121121
export const WALLY_MINISCRIPT_DEPTH_MASK = 0xffff0000; /** Mask for limiting maximum depth */
122122
export const WALLY_MINISCRIPT_DEPTH_SHIFT = 16; /** Shift to convert maximum depth to flags */
123123
export const WALLY_MINISCRIPT_ONLY = 0x02; /** Only allow miniscript (not descriptor) expressions */
124-
export const WALLY_MINISCRIPT_POLICY = 0x08; /** Only allow policy @n variable substitution */
124+
export const WALLY_MINISCRIPT_POLICY_TEMPLATE = 0x08; /** Only allow policy templates with @n BIP32 keys */
125125
export const WALLY_MINISCRIPT_REQUIRE_CHECKSUM = 0x04; /** Require a checksum to be present */
126126
export const WALLY_MINISCRIPT_TAPSCRIPT = 0x01; /** Tapscript, use x-only pubkeys */
127127
export const WALLY_MS_CANONICAL_NO_CHECKSUM = 0x01; /** Do not include a checksum */

0 commit comments

Comments
 (0)