Skip to content

Commit c38c7c5

Browse files
committed
miniscript: don't check for top level validity at parsing time
Letting the caller perform the checks allows for finer-grained error reporting.
1 parent 327b7e9 commit c38c7c5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/script/miniscript.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,11 @@ void BuildBack(const Ctx& ctx, Fragment nt, std::vector<NodeRef<Key>>& construct
953953
}
954954
}
955955

956-
//! Parse a miniscript from its textual descriptor form.
956+
/**
957+
* Parse a miniscript from its textual descriptor form.
958+
* This does not check whether the script is valid, let alone sane. The caller is expected to use
959+
* the `IsValidTopLevel()` and `IsSaneTopLevel()` to check for these properties on the node.
960+
*/
957961
template<typename Key, typename Ctx>
958962
inline NodeRef<Key> Parse(Span<const char> in, const Ctx& ctx)
959963
{
@@ -1255,9 +1259,7 @@ inline NodeRef<Key> Parse(Span<const char> in, const Ctx& ctx)
12551259
// Sanity checks on the produced miniscript
12561260
assert(constructed.size() == 1);
12571261
if (in.size() > 0) return {};
1258-
const NodeRef<Key> tl_node = std::move(constructed.front());
1259-
if (!tl_node->IsValidTopLevel()) return {};
1260-
return tl_node;
1262+
return std::move(constructed.front());
12611263
}
12621264

12631265
/** Decode a script into opcode/push pairs.

src/test/miniscript_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE(fixed_tests)
276276
// (for now) have 'd:' be 'u'. This tests we can't use a 'd:' wrapper for a thresh, which requires
277277
// its subs to all be 'u' (taken from https://github.com/rust-bitcoin/rust-miniscript/discussions/341).
278278
const auto ms_minimalif = miniscript::FromString("thresh(3,c:pk_k(03d30199d74fb5a22d47b6e054e2f378cedacffcb89904a61d75d0dbd407143e65),sc:pk_k(03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556),sc:pk_k(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798),sdv:older(32))", CONVERTER);
279-
BOOST_CHECK(!ms_minimalif);
279+
BOOST_CHECK(ms_minimalif && !ms_minimalif->IsValid());
280280
// A Miniscript with duplicate keys is not sane
281281
const auto ms_dup1 = miniscript::FromString("and_v(v:pk(03d30199d74fb5a22d47b6e054e2f378cedacffcb89904a61d75d0dbd407143e65),pk(03d30199d74fb5a22d47b6e054e2f378cedacffcb89904a61d75d0dbd407143e65))", CONVERTER);
282282
BOOST_CHECK(ms_dup1);

0 commit comments

Comments
 (0)