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

Merge pull request #2565 from Roasbeef/wire-script-arena

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

73/100 · Adequate
Merge pull request #2565 from Roasbeef/wire-script-arena

wire: replace 4 MiB script slab with tiered arena allocator
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides an explanatory body✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit is a large refactoring of how btcd decodes Bitcoin network messages. It replaces a fixed 4 MiB temporary buffer (a 'slab') with a tiered arena allocator and adds checks to avoid reserving huge amounts of memory when a message claims to contain many elements but the data is truncated. The change is primarily defensive: it reduces memory waste and makes malformed messages harder to turn into memory-exhaustion attacks. A small fix in the RPC client also stops a local validation helper from mutating caller-owned transactions.

Recommended action

Review the arena ownership contract carefully: ensure every public decode path copies scripts out of the arena before release, and that failed decodes clear all arena-backed fields. Run the new fuzz/property tests under the race detector and consider adding a corpus test for a maximally large witness item that exhausts the arena to confirm graceful error handling.

Security signals we found

01

Replaced fixed 4 MiB decode slab with tiered arena to reduce memory amplification and unbounded free-list retention

02

Added truncated-payload guards (validateElementCount, canPreallocateElements, readBytes) to prevent huge preallocation on malformed length/count prefixes

03

Cleared TxIn/TxOut on failed MsgTx decode to avoid leaking arena-backed slices to callers

04

Fixed caller-owned transaction mutation in rpcclient TestMempoolAcceptAsync by decoding into a separate variable

05

Added property-based, fuzz, concurrency, and decode-budget tests covering arena reuse, aliasing, and truncated inputs

Risk score

Why this scored 61/100

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