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

Remove alloc feature gate for MerkleNode

Public commit record

What the developer wrote

Authored by Mitchell Bagot

68/100 · Adequate
Remove alloc feature gate for MerkleNode

With the introduction of pop() to ArrayVec, the
MerkleNode::calculate_root logic can be implemented using ArrayVec
instead of alloc::vec::Vec. This allows for use of the functionality
without the alloc feature, albeit with an upper iterator length bound
of 32768 (exclusive) items.

Introduce ArrayVec bounded variation to MerkleNode::calculate_root,
and remove alloc feature gate from MerkleNode.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit refactors how Bitcoin Merkle roots are calculated so the code works even when the optional 'alloc' memory allocator feature is disabled. It replaces a growable vector with a fixed-size 15-slot array, which limits the no-alloc path to at most 32,767 transaction IDs. The change is a feature-portability improvement, not a security fix, and it explicitly returns None when the no-alloc limit is exceeded rather than overflowing or corrupting state.

Recommended action

No immediate security action required. Reviewers should verify that the 32,768 no-alloc limit is acceptable for all intended no-std use cases and that the ArrayVec capacity of 15 correctly bounds every possible Merkle tree depth for that input size. Consider whether callers relying on calculate_root in no-alloc environments handle the new None case appropriately.

Security signals we found

01

Bounds check added: returns None when no-alloc stack reaches capacity, preventing ArrayVec overflow/panic.

02

Existing duplicate-leaf rejection (CVE-2012-2459 mitigation) is preserved and now also runs without alloc.

03

No new unsafe code, no new cryptographic operations, no change to hashing algorithm.

04

Public API expands: calculate_root, combine, and from_leaf become available without the alloc feature.

Risk score

Why this scored 18/100

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