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

validation: check invariants when inserting into m_blocks_unlinked

Public commit record

What the developer wrote

Authored by stratospher

93/100 · Strong
validation: check invariants when inserting into m_blocks_unlinked

For an entry A -> B in m_blocks_unlinked, the entry B was added into
m_blocks_unlinked either because:
- some ancestor of B was never received (or)
- some ancestor of B was pruned away.

Every insert must satisfy two invariants:
1. B has BLOCK_HAVE_DATA set.
2. No duplicate A -> B entries in m_blocks_unlinked (this is UB zone if
this entry gets popped twice in ReceivedBlockTransactions and
happens to be in setBlockIndexCandidates)

2 bugs (#35070 and #35168) discovered recently stemmed from the
m_blocks_unlinked insertion sites not enforcing these invariants.
So add a helper which wraps around insertion sites of m_blocks_unlinked
with these invariants.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit adds safety checks around a Bitcoin Core internal data structure called m_blocks_unlinked, which tracks blocks whose parent chain is missing. The change prevents two problems: inserting blocks that have no actual stored data, and inserting the same block twice. The commit message says both duplicate entries and missing-data entries could lead to undefined behavior inside the block validation engine, including corrupting the candidate-chain ordering. The patch is defensive hardening rather than a complete fix for the two referenced bugs.

Recommended action

Treat this as a defensive hardening commit that mitigates symptoms of two related bugs. Review the root-cause fixes for issues #35070 and #35168 separately, and consider whether additional runtime checks or fuzzing around m_blocks_unlinked state transitions are warranted. Node operators should upgrade to a release containing this and the related fixes once available.

Security signals we found

01

Insertion into m_blocks_unlinked now enforces BLOCK_HAVE_DATA invariant

02

Duplicate (parent, child) entries are now rejected at all insertion sites

03

Commit message states duplicate entries can cause undefined behavior when popped twice in ReceivedBlockTransactions

04

Commit message references two recently discovered bugs (#35070 and #35168) stemming from these invariants being violated

05

Use of Assume() macros indicates these are treated as internal-consistency assumptions

Risk score

Why this scored 59/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 10/15
Affected reach 12/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.