descriptor: avoid iterating multisig nodes twice
What changed, and why it matters
This is a small code cleanup in how a Bitcoin descriptor function counts child nodes. It removes a redundant loop and counts children while already checking them. There is no visible security bug being fixed—just an efficiency and clarity improvement.
No security action needed. Treat as a normal refactoring/cleanup commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In verify_multi(), the previous code called node_get_child_count() to count all children, then iterated again to validate them. The patch merges the count into the validation loop. The functional checks remain equivalent: it still validates the threshold number node, ensures keys are valid, and enforces the same upper/lower bounds. No behavioral change that would affect security is evident.
Changed components
src/descriptor.cverify_multi()Inspect captured patch +9 / −10
diff --git a/src/descriptor.c b/src/descriptor.c
index 83a74fe..fcddd79 100644
--- a/src/descriptor.c
+++ b/src/descriptor.c
@@ -725,23 +725,22 @@ static int verify_combo(ms_ctx *ctx, ms_node *node)
static int verify_multi(ms_ctx *ctx, ms_node *node)
{
(void)ctx;
- const int64_t count = node_get_child_count(node);
- ms_node *top, *key;
+ const ms_node *top = node->child;
+ ms_node *key = top ? top->next : NULL;
+ int64_t key_count = 0;
- if (count < 2 || count - 1 > MINISCRIPT_MULTI_MAX)
+ if (!top || !key || top->builtin ||
+ top->kind != KIND_NUMBER || top->number <= 0)
return WALLY_EINVAL;
- top = node->child;
- if (!top->next || top->builtin || top->kind != KIND_NUMBER ||
- top->number <= 0 || count < top->number)
- return WALLY_EINVAL;
-
- key = top->next;
while (key) {
- if (key->builtin || !(key->kind & KIND_KEY))
+ if (key->builtin || !(key->kind & KIND_KEY) ||
+ ++key_count > MINISCRIPT_MULTI_MAX)
return WALLY_EINVAL;
key = key->next;
}
+ if (top->number > key_count)
+ return WALLY_EINVAL;
node->type_properties = builtin_get(node)->type_properties;
return WALLY_OK;
Why this scored 12/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.