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

wire: derive arena chunk class without cursor state

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

73/100 · Adequate
wire: derive arena chunk class without cursor state

In this commit, we remove the per-arena class field and its starting
class constants entirely. grow now derives the chunk size class from
the request itself on every call, choosing the smallest class that holds
both the allocation and one more byte than the current chunk, so
consecutive growths keep walking up the ladder without any cursor state
to maintain or reset across borrows, rewinds, and releases. The worst
case is four iterations of the class lookup.

This also removes the borrowScriptArena starting class parameter, since
without a cursor there is nothing to seed: every arena starts at the
smallest class and grows on demand. The rewind path no longer needs to
reposition a class cursor after retaining the largest chunk, and release
no longer needs to reset one.

alloc additionally rejects negative sizes with errScriptArenaFull. The
decode path never passes one, but the remaining budget check alone would
let a negative size through and panic on the slice bounds below it, so
the guard keeps alloc total on any input.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit refactors a memory arena used when decoding Bitcoin transactions and blocks. It removes a chunk-size cursor and instead calculates the right chunk size on every allocation. It also adds a guard so negative allocation sizes are rejected instead of causing a panic. The change is primarily a robustness and maintainability improvement; it does not appear to fix an actively exploitable vulnerability, but it removes a class of potential panic/corruption bugs related to stale cursor state and negative sizes.

Recommended action

Reviewers should confirm that the new `grow()` loop cannot select a class smaller than `n` and that `max(n, len(a.cur)+1)` correctly prevents oscillation or fragmentation. Fuzz/property tests already cover round-trips and randomized allocations; consider adding a test for an arena reused across many borrow/release cycles to ensure no class-cursor regression. No urgent security deployment is indicated by the diff alone.

Security signals we found

01

Defensive check added: negative allocation sizes now return an error instead of panicking on slice bounds.

02

Stateful cursor removed, reducing risk of incorrect chunk-size escalation after rewind/release/reuse.

03

putScriptChunk comment updated to explain that a length mismatch would be internal corruption and could cause a future slice-bounds panic.

04

No direct diff evidence of an exploitable memory-safety bug being fixed; changes are framed as robustness/correctness.

Risk score

Why this scored 35/100

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