diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2023-01-22 12:49:44 +0100 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2023-10-08 02:43:16 +0200 |
commit | e5aaa3d77af7459b37c0c4a37eb22c5fd0cda3e1 (patch) | |
tree | 00de57ec2cca6c7594395b61f877627c0b1a23d9 /src/script | |
parent | 687a0b0fa53ddd5632287b9e00ad8b0550830287 (diff) | |
download | bitcoin-e5aaa3d77af7459b37c0c4a37eb22c5fd0cda3e1.tar.xz |
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.
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/miniscript.cpp | 6 | ||||
-rw-r--r-- | src/script/miniscript.h | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/script/miniscript.cpp b/src/script/miniscript.cpp index 82f65e5dde..15e0778ef5 100644 --- a/src/script/miniscript.cpp +++ b/src/script/miniscript.cpp @@ -33,7 +33,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); @@ -116,7 +117,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 diff --git a/src/script/miniscript.h b/src/script/miniscript.h index bb75f3e52e..cd656444b6 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -249,7 +249,7 @@ constexpr bool IsTapscript(MiniscriptContext ms_ctx) namespace internal { //! Helper function for Node::CalcType. -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); //! Helper function for Node::CalcScriptLen. 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 @@ private: Type y = subs.size() > 1 ? subs[1]->GetType() : ""_mst; Type z = subs.size() > 2 ? subs[2]->GetType() : ""_mst; - return SanitizeType(ComputeType(fragment, x, y, z, sub_types, k, data.size(), subs.size(), keys.size())); + return SanitizeType(ComputeType(fragment, x, y, z, sub_types, k, data.size(), subs.size(), keys.size(), m_script_ctx)); } public: |