Skip to content

Commit

Permalink
miniscript: make 'd:' have the 'u' property under Tapscript context
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darosior committed Mar 16, 2023
1 parent c0ba8eb commit 866284d
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 87 deletions.
6 changes: 4 additions & 2 deletions src/script/miniscript.cpp
Expand Up @@ -43,7 +43,8 @@ Type SanitizeType(Type e) {
return e;
}

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) {
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) {
// Sanity check on data
if (fragment == Fragment::SHA256 || fragment == Fragment::HASH256) {
assert(data_size == 32);
Expand Down Expand Up @@ -126,7 +127,8 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
"e"_mst.If(x << "f"_mst) | // e=f_x
(x & "ghijk"_mst) | // g=g_x, h=h_x, i=i_x, j=j_x, k=k_x
(x & "ms"_mst) | // m=m_x, s=s_x
// NOTE: 'd:' is not 'u' under P2WSH as MINIMALIF is only a policy rule there.
// NOTE: 'd:' is 'u' under Tapscript but not P2WSH as MINIMALIF is only a policy rule there.
"u"_mst.If(IsTapscript(ms_ctx)) |
"ndx"_mst; // n, d, x
case Fragment::WRAP_V: return
"V"_mst.If(x << "B"_mst) | // V=B_x
Expand Down

0 comments on commit 866284d

Please sign in to comment.