Skip to main content

Overview

SSZ (Simple Serialize) is the serialization format used by Ethereum’s consensus layer (Beacon Chain). It provides efficient, deterministic encoding with Merkle tree support for proofs.

Features

  • Basic type encoding (uint8, uint16, uint32, uint64, uint256, bool)
  • Variable-length types (vectors, lists, bitvectors, bitlists)
  • Container (struct) encoding
  • Hash tree root computation for Merkle proofs
  • Full Zig implementation with TypeScript bindings

Basic Types

Encoding

Decoding

Merkleization

Hash Tree Root

Compute Merkle tree root for proofs:

Properties

  • Deterministic: Same input always produces same root
  • 32-byte output: Compatible with Merkle proofs
  • SHA256-based: Uses standard cryptographic hash

Examples

Validator Deposit

Beacon Block Header

Sync Committee

Zig API

Basic Types

Variable Types

Container Encoding

Hash Tree Root

Specification

SSZ follows the Ethereum consensus-specs:

Basic Types

  • Boolean: 1 byte (0 = false, 1 = true)
  • Unsigned integers: Little-endian encoding
    • uint8: 1 byte
    • uint16: 2 bytes
    • uint32: 4 bytes
    • uint64: 8 bytes
    • uint256: 32 bytes

Variable Types

  • Vector: Fixed-length homogeneous collection
  • List: Variable-length with maximum size
  • Bitvector: Fixed-length collection of bits
  • Bitlist: Variable-length collection of bits with sentinel

Container Encoding

  1. Fixed part: All fixed-size fields + offsets for variable fields
  2. Variable part: Concatenated variable-size fields

Merkleization

  1. Chunk data into 32-byte leaves
  2. Pad to next power of 2
  3. Build binary Merkle tree bottom-up using SHA256
  4. Return root hash

Performance

TypeScript

  • Basic types: ~10-50 ns per operation
  • Hash tree root: ~100-500 μs depending on data size
  • Web Crypto API used for SHA256

Zig

  • Basic types: ~5-20 ns per operation
  • Hash tree root: ~50-200 μs with optimized hashing
  • Zero-copy decoding where possible

Limitations

Current implementation:
  • ✅ Basic types (all unsigned integers, bool)
  • ✅ Variable types (vector, list, bitvector, bitlist)
  • ✅ Container encoding (fixed fields only)
  • ✅ Hash tree root computation
  • ⚠️ Variable fields in containers (partial support)
  • ❌ Union types (not yet implemented)
  • ❌ Full consensus-specs test vectors (in progress)

See Also