diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2023-07-01 11:59:11 +0200 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2023-07-01 12:02:06 +0200 |
commit | 639e3b6c9759a7a582c5c86fdbfa5ea99cb7bb16 (patch) | |
tree | 7429892e15f97e5393440c56c2c41d49a807d7d6 /src/script | |
parent | e3280eae1b53006d74d11f3cf9d7a9dc7ff2c39e (diff) |
descriptor: refuse to parse unspendable miniscript descriptors
It's possible for some unsatisfiable miniscripts to be considered sane.
Make sure we refuse to import those, as they would be unspendable.
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/descriptor.cpp | 6 | ||||
-rw-r--r-- | src/script/miniscript.h | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index b8ade1684a..787bf43127 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1541,14 +1541,14 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const error = std::move(parser.m_key_parsing_error); return nullptr; } - if (!node->IsSane()) { + if (!node->IsSane() || node->IsNotSatisfiable()) { // Try to find the first insane sub for better error reporting. auto insane_node = node.get(); if (const auto sub = node->FindInsaneSub()) insane_node = sub; if (const auto str = insane_node->ToString(parser)) error = *str; if (!insane_node->IsValid()) { error += " is invalid"; - } else { + } else if (!node->IsSane()) { error += " is not sane"; if (!insane_node->IsNonMalleable()) { error += ": malleable witnesses exist"; @@ -1561,6 +1561,8 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const } else if (!insane_node->ValidSatisfactions()) { error += ": needs witnesses that may exceed resource limits"; } + } else { + error += " is not satisfiable"; } return nullptr; } diff --git a/src/script/miniscript.h b/src/script/miniscript.h index 919e2b9f64..b58740a125 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -1161,6 +1161,9 @@ public: return true; } + //! Whether no satisfaction exists for this node. + bool IsNotSatisfiable() const { return !GetStackSize(); } + //! Return the expression type. Type GetType() const { return typ; } |