From cd9fb869fbd424daed82932733f7e11b3f60a737 Mon Sep 17 00:00:00 2001 From: odudex Date: Tue, 6 Oct 2026 11:20:10 -0300 Subject: [PATCH] descriptor: only allow the el prefix on the outermost expression As in ELIP-150 and elements-miniscript, Elements descriptors prefix only their outermost script expression with el, e.g. elsh(wpkh()). The prefix was accepted on any builtin, so expressions such as wsh(elpk(K)), elct(), ct(elslip77(k),wpkh(K)) or c:elpk_k(K) parsed as Elements descriptors and canonicalized to non-standard names. It is also no longer accepted when parsing with WALLY_MINISCRIPT_ONLY. --- src/ctest/test_descriptor.c | 38 +++++++++++++++++++++++++++++++++++++ src/descriptor.c | 9 +++++++++ 2 files changed, 47 insertions(+) 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..7c92aa121 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -3256,6 +3256,15 @@ 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 can be prefixed */ + 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