Add failing unit test for thresh parsing
What changed, and why it matters
This commit only adds two new test cases to the project's unit tests. The tests check that the wallet policy parser correctly rejects 'thresh' descriptors with an invalid threshold number (zero or larger than the number of available sub-policies). It does not change any production code. The commit itself is a test-only change and appears to be preparing the ground for a later fix, but it signals that the developers have identified a parsing edge case that currently fails.
Treat this as a low-severity, test-only signal. Review the corresponding production parser to confirm whether invalid thresh thresholds are currently accepted, and if so, patch the validation logic. Monitor follow-up commits that may implement the fix.
Security signals we found
Test-only commit adding negative assertions for policy parsing
Targets threshold validation in descriptor wallet policies
Commit title explicitly labels the new tests as 'failing', suggesting a latent parser bug
Evidence from the diff
The diff extends test_failures() in unit-tests/test_wallet.c with two assertions expecting parse_policy() to return a negative value (failure) for: (1) wsh(thresh(0,pk(@0/),s:pk(@1/),s:pk(@2/))) and (2) wsh(thresh(4,pk(@0/),s:pk(@1/),s:pk(@2/))). In Miniscript/Output descriptor conventions, thresh(k,…) requires 1 <= k <= n where n is the count of subexpressions. k=0 is invalid, and k=4 with only three sub-policies is invalid. The commit title says ‘Add failing unit test’, implying these tests currently fail against the existing implementation. No parser or validation logic is modified.
Changed components
unit-tests/test_wallet.cparse_policy() (indirectly, via new test coverage)Inspect captured patch +6 / −0
diff --git a/unit-tests/test_wallet.c b/unit-tests/test_wallet.c
index f49efd9..0063d32 100644
--- a/unit-tests/test_wallet.c
+++ b/unit-tests/test_wallet.c
@@ -415,6 +415,12 @@ static void test_failures(void **state) {
assert_true(0 > parse_policy("multi(1)", out, sizeof(out)));
assert_true(0 > parse_policy("multi(1,)", out, sizeof(out)));
+ // invalid k in thresh (0, or too large)
+ assert_true(0 >
+ parse_policy("wsh(thresh(0,pk(@0/**),s:pk(@1/**),s:pk(@2/**)))", out, sizeof(out)));
+ assert_true(0 >
+ parse_policy("wsh(thresh(4,pk(@0/**),s:pk(@1/**),s:pk(@2/**)))", out, sizeof(out)));
+
// syntactically invalid tr descriptors
assert_true(0 > parse_policy("tr(,pk(@0))", out, sizeof(out)));
assert_true(0 > parse_policy("tr(pk(@0))", out, sizeof(out)));
Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.