Skip to content

Commit e5aaa3d

Browse files
committed
miniscript: make 'd:' have the 'u' property under Tapscript context
In Tapscript MINIMALIF is a consensus rule, so we can rely on the fact that the `DUP IF [X] ENDIF` will always put an exact 1 on the stack upon satisfaction.
1 parent 687a0b0 commit e5aaa3d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/script/miniscript.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Type SanitizeType(Type e) {
3333
return e;
3434
}
3535

36-
Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Type>& sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys) {
36+
Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Type>& sub_types, uint32_t k,
37+
size_t data_size, size_t n_subs, size_t n_keys, MiniscriptContext ms_ctx) {
3738
// Sanity check on data
3839
if (fragment == Fragment::SHA256 || fragment == Fragment::HASH256) {
3940
assert(data_size == 32);
@@ -116,7 +117,8 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
116117
"e"_mst.If(x << "f"_mst) | // e=f_x
117118
(x & "ghijk"_mst) | // g=g_x, h=h_x, i=i_x, j=j_x, k=k_x
118119
(x & "ms"_mst) | // m=m_x, s=s_x
119-
// NOTE: 'd:' is not 'u' under P2WSH as MINIMALIF is only a policy rule there.
120+
// NOTE: 'd:' is 'u' under Tapscript but not P2WSH as MINIMALIF is only a policy rule there.
121+
"u"_mst.If(IsTapscript(ms_ctx)) |
120122
"ndx"_mst; // n, d, x
121123
case Fragment::WRAP_V: return
122124
"V"_mst.If(x << "B"_mst) | // V=B_x

src/script/miniscript.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ constexpr bool IsTapscript(MiniscriptContext ms_ctx)
249249
namespace internal {
250250

251251
//! Helper function for Node::CalcType.
252-
Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Type>& sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys);
252+
Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Type>& sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys, MiniscriptContext ms_ctx);
253253

254254
//! Helper function for Node::CalcScriptLen.
255255
size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys);
@@ -576,7 +576,7 @@ struct Node {
576576
Type y = subs.size() > 1 ? subs[1]->GetType() : ""_mst;
577577
Type z = subs.size() > 2 ? subs[2]->GetType() : ""_mst;
578578

579-
return SanitizeType(ComputeType(fragment, x, y, z, sub_types, k, data.size(), subs.size(), keys.size()));
579+
return SanitizeType(ComputeType(fragment, x, y, z, sub_types, k, data.size(), subs.size(), keys.size(), m_script_ctx));
580580
}
581581

582582
public:

src/test/fuzz/miniscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ struct SmartInfo
580580
if (subs > 0) subt.push_back(x);
581581
if (subs > 1) subt.push_back(y);
582582
if (subs > 2) subt.push_back(z);
583-
Type res = miniscript::internal::ComputeType(frag, x, y, z, subt, k, data_size, subs, n_keys);
583+
Type res = miniscript::internal::ComputeType(frag, x, y, z, subt, k, data_size, subs, n_keys, MsCtx::P2WSH);
584584
// Continue if the result is not a valid node.
585585
if ((res << "K"_mst) + (res << "V"_mst) + (res << "B"_mst) + (res << "W"_mst) != 1) continue;
586586

0 commit comments

Comments
 (0)