AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 59 Bitcoin

Limit the amount of nesting for `thresh` fragments to 4

Public commit record

What the developer wrote

Authored by Salvatore Ingala

73/100 · Adequate
Limit the amount of nesting for `thresh` fragments to 4

compute_thresh_ops and compute_thresh_stacksize each need two arrays of
MAX_N_IN_THRESH + 2 counters. Since they were inlined by the compiler,
they bloat the size of the stack frame of
compute_miniscript_policy_ext_info, which vastly reduces the stack usage
on usual policies.

Yet, stack usage would remain very large on policies that recursively
nest 'thresh' fragments.
Therefore, we add a limit of 4 nested thresh expressions, by keeping
track in the parsing context.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a stack-overflow risk in Ledger's Bitcoin app when parsing wallet policies that deeply nest 'thresh' miniscript fragments. It limits nesting to four levels and prevents two helper functions from being inlined so their large local arrays don't multiply across every recursive call. Without the fix, a crafted policy could exhaust the device's limited stack and crash or potentially corrupt memory.

Recommended action

Treat this as a security hardening fix and include it in the next firmware release. Review whether other recursive walkers in the codebase have similar inlined large-array issues, and consider adding runtime stack-canary or static-analysis checks for large stack frames in security-critical parsing code.

Security signals we found

01

Stack-frame bloat from inlined functions with large local arrays

02

Recursive policy-tree walker with unbounded nested thresh input

03

Potential stack exhaustion / overflow on crafted miniscript policy

04

New parse-time limit rejects deeply nested thresh fragments

05

Helper functions made noinline to scope large arrays to their own frames

Risk score

Why this scored 59/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.