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.
This commit is contained in:
Antoine Poinsot committed 2023-07-01 12:02:06 +02:00
1 parent e3280eae1b
commit 639e3b6c97
2 files changed
+7 -2

No files matched your search

+4 -2
View File
@@ -1541,14 +1541,14 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const
error = std::move(parser.m_key_parsing_error); error = std::move(parser.m_key_parsing_error);
return nullptr; return nullptr;
} }
if (!node->IsSane()) { if (!node->IsSane() || node->IsNotSatisfiable()) {
// Try to find the first insane sub for better error reporting. // Try to find the first insane sub for better error reporting.
auto insane_node = node.get(); auto insane_node = node.get();
if (const auto sub = node->FindInsaneSub()) insane_node = sub; if (const auto sub = node->FindInsaneSub()) insane_node = sub;
if (const auto str = insane_node->ToString(parser)) error = *str; if (const auto str = insane_node->ToString(parser)) error = *str;
if (!insane_node->IsValid()) { if (!insane_node->IsValid()) {
error += " is invalid"; error += " is invalid";
} else { } else if (!node->IsSane()) {
error += " is not sane"; error += " is not sane";
if (!insane_node->IsNonMalleable()) { if (!insane_node->IsNonMalleable()) {
error += ": malleable witnesses exist"; 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()) { } else if (!insane_node->ValidSatisfactions()) {
error += ": needs witnesses that may exceed resource limits"; error += ": needs witnesses that may exceed resource limits";
} }
} else {
error += " is not satisfiable";
} }
return nullptr; return nullptr;
} }
+3
View File
@@ -1161,6 +1161,9 @@ public:
return true; return true;
} }
//! Whether no satisfaction exists for this node.
bool IsNotSatisfiable() const { return !GetStackSize(); }
//! Return the expression type. //! Return the expression type.
Type GetType() const { return typ; } Type GetType() const { return typ; }