diff --git a/src/ctest/test_descriptor.c b/src/ctest/test_descriptor.c index 4b891bad9..4a2da51c8 100644 --- a/src/ctest/test_descriptor.c +++ b/src/ctest/test_descriptor.c @@ -2490,6 +2490,44 @@ static const descriptor_test g_descriptor_cases[] = { "descriptor errchk - uncompressed binding key", "ct(uncompressed,elwpkh(key_4))", WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + /* Only the outermost expression (or ct() script) has the el prefix */ + "descriptor errchk - el prefix on a nested descriptor", + "elsh(elwpkh(key_1))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "descriptor errchk - el prefix on a nested miniscript", + "wsh(elpk(key_1))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "descriptor errchk - el prefix on both expressions", + "elwsh(elpk(key_1))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "descriptor errchk - el prefix on a tapscript leaf", + "eltr(key_1,elpk(key_1))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "descriptor errchk - el prefix on a nested ct() descriptor", + "ct(slip77(slip77_key),elsh(elwpkh(key_1)))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + /* ct() and its blinding key are not script expressions */ + "descriptor errchk - el prefix on ct()", + "elct(slip77(slip77_key),elwpkh(key_1))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "descriptor errchk - el prefix on slip77()", + "ct(elslip77(slip77_key),elwpkh(key_1))", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "descriptor errchk - el prefix after a wrapper", + "c:elpk_k(key_1)", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, 0, NULL, "", VARS_STD + }, { + "miniscript errchk - el prefix", + "elpk(key_1)", + WALLY_NETWORK_LIQUID, 0, 0, 0, NULL, WALLY_MINISCRIPT_ONLY, NULL, "", VARS_STD } /* Elements/Confidential wallet policy error cases */ , { diff --git a/src/descriptor.c b/src/descriptor.c index 8686b0cbe..0de825e9c 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -3256,6 +3256,18 @@ static int analyze_miniscript(ms_ctx *ctx, const char *str, size_t str_len, /* Not a pure descriptor */ ctx->features &= ~WALLY_MS_IS_DESCRIPTOR; } + if (builtin_is_elements(str + offset, i - offset) && + ((parent && parent->kind != KIND_DESCRIPTOR_CT) || + node->kind == KIND_DESCRIPTOR_CT || + node->kind == KIND_DESCRIPTOR_SLIP77 || + node->wrapper_str[0] || !(kind & KIND_DESCRIPTOR))) { + /* Only the outermost script expression of a descriptor + * can be prefixed, e.g. elsh(wpkh()) or ct(k,elsh(wpkh())), + * but not elsh(elwpkh()), elct(), ct(elslip77(k),wpkh()), + * c:elpk_k() or a miniscript-only expression */ + ret = WALLY_EINVAL; + break; + } if (builtin_is_elements(str + offset, i - offset) || node->kind == KIND_DESCRIPTOR_CT) { /* ct() is Elements-only: treat its descriptor as Elements