Skip to content

Commit 639e3b6

Browse files
committed
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.
1 parent e3280ea commit 639e3b6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/script/descriptor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,14 +1541,14 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const
15411541
error = std::move(parser.m_key_parsing_error);
15421542
return nullptr;
15431543
}
1544-
if (!node->IsSane()) {
1544+
if (!node->IsSane() || node->IsNotSatisfiable()) {
15451545
// Try to find the first insane sub for better error reporting.
15461546
auto insane_node = node.get();
15471547
if (const auto sub = node->FindInsaneSub()) insane_node = sub;
15481548
if (const auto str = insane_node->ToString(parser)) error = *str;
15491549
if (!insane_node->IsValid()) {
15501550
error += " is invalid";
1551-
} else {
1551+
} else if (!node->IsSane()) {
15521552
error += " is not sane";
15531553
if (!insane_node->IsNonMalleable()) {
15541554
error += ": malleable witnesses exist";
@@ -1561,6 +1561,8 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t& key_exp_index, Span<const
15611561
} else if (!insane_node->ValidSatisfactions()) {
15621562
error += ": needs witnesses that may exceed resource limits";
15631563
}
1564+
} else {
1565+
error += " is not satisfiable";
15641566
}
15651567
return nullptr;
15661568
}

src/script/miniscript.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ struct Node {
11611161
return true;
11621162
}
11631163

1164+
//! Whether no satisfaction exists for this node.
1165+
bool IsNotSatisfiable() const { return !GetStackSize(); }
1166+
11641167
//! Return the expression type.
11651168
Type GetType() const { return typ; }
11661169

0 commit comments

Comments
 (0)