Skip to main content

Overview

BinaryTree implements the Binary State Tree structure proposed in EIP-7864. It provides a unified tree structure for Ethereum state using BLAKE3 hashing with stem-based key organization.

Tree Structure

The tree consists of four node types:

Key Methods

init

Create an empty tree.

insert

Insert a value at a 32-byte key. Returns a new tree (immutable).
Keys are split into:
  • Stem (31 bytes) - path through the tree
  • Subindex (1 byte) - slot index within stem node (0-255)

get

Retrieve a value by key. Returns null if not found.

rootHash

Compute the 32-byte root hash of the tree.

rootHashHex

Get root hash as hex string.

Key Utilities

addressToKey

Convert a 20-byte Ethereum address to a 32-byte key (pads with 12 zero bytes).

splitKey

Split a 32-byte key into stem (31 bytes) and subindex (1 byte).

getStemBit

Get bit value at position in a stem (for tree traversal).

Hashing Functions

All hashing uses BLAKE3. Factory functions allow dependency injection for tree-shaking.

hashNode

Hash any node type. Returns 32-byte hash.

hashInternal

Hash an internal node (concatenates left and right hashes).

hashStem

Hash a stem node (concatenates stem + all 256 values).

hashLeaf

Hash a leaf node (hashes the value directly).

Types

BinaryTree

The tree container type.

AccountData

Layout for account data stored at index 0 of stem nodes.

Error Handling

Example: State Storage

See Also