EEVM.MPT.HexPrefix (eevm v0.1.0)

Copy Markdown View Source

Hex-prefix (aka compact) encoding used by Ethereum's Merkle Patricia Trie.

Trie leaf and extension nodes encode their nibble path as a compact byte string. The first nibble carries node kind and parity flags:

  • 0x0 = extension, even path length
  • 0x1 = extension, odd path length
  • 0x2 = leaf, even path length
  • 0x3 = leaf, odd path length

Paths are represented as nibble lists ([0..15]).

Summary

Types

Nibble values used in hex-prefix paths.

Functions

Decodes Ethereum hex-prefix bytes into {nibbles, is_leaf}.

Encodes a nibble path using Ethereum hex-prefix rules.

Types

nibble()

@type nibble() :: 0..15

Nibble values used in hex-prefix paths.

Functions

decode(bytes)

@spec decode(binary()) :: {[nibble()], boolean()}

Decodes Ethereum hex-prefix bytes into {nibbles, is_leaf}.

encode(nibbles, is_leaf)

@spec encode([nibble()], boolean()) :: binary()

Encodes a nibble path using Ethereum hex-prefix rules.