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

util: introduce `TrySub` to prevent unsigned underflow

Public commit record

What the developer wrote

Authored by Lőrinc

85/100 · Strong
util: introduce `TrySub` to prevent unsigned underflow

Introduce `TrySub(T&, U)` which subtracts an unsigned integral `U` from an unsigned integral `T`, returning `false` on underflow.
Use with `Assume(TrySub(...))` at coins cache accounting decrement sites so invariant violations fail immediately rather than silently wrapping.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: Pieter Wuille <pieter@wuille.net>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This change adds a safety check to subtraction operations in Bitcoin Core's coin-cache accounting. Previously, certain internal counters could silently wrap around to huge values if a bug caused them to be decremented more than they were incremented. Now the program will detect that impossible condition and abort, turning a silent accounting corruption into a visible failure. The patch is defensive hardening; it does not by itself prove an attacker can trigger the underflow.

Recommended action

Treat as a defensive hardening commit. Review whether any of the changed decrement sites are reachable from untrusted network input, and consider whether `Assume()` is the appropriate failure policy for each site (non-fatal in release builds may still permit continued operation with corrupted accounting). No immediate emergency response is indicated by the diff alone.

Security signals we found

01

Unsigned integer underflow hardening in memory/dirty-coin accounting

02

Conversion of silent wraparound to assertion-triggering failure

03

Defensive invariant enforcement in UTXO cache code

04

No new externally reachable input validation added

Risk score

Why this scored 44/100

Our methodology →
Potential impact 12/30
Exploitability 5/25
Stealth signal 8/15
Affected reach 10/15
Confidence 6/10
Evidence quality 3/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.