---
eip: 8016
label: EIP-8016
title: SSZ CompatibleUnion
status: Draft
type: Standards Track
category: Core
created: 2025-08-28
requires: 7495, 7916
official: https://eips.ethereum.org/EIPS/eip-8016
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8016.md
canonical: https://eips.huatuo.xyz/eip-8016/
lang: en
tldr: Defines CompatibleUnion, an SSZ tagged-union type whose variants must Merkleize compatibly, so a field keeps the same generalized index (and proof path) no matter which variant is used.
tags: [ssz, serialization, merkle, consensus, core]
---

# EIP-8016: SSZ CompatibleUnion

> SSZ type for forward-compatible unions

**TL;DR:** Defines CompatibleUnion, an SSZ tagged-union type whose variants must Merkleize compatibly, so a field keeps the same generalized index (and proof path) no matter which variant is used.

## What problem does it solve?

Some Ethereum objects come in several variants that share most of their fields; transaction types are the obvious example. If each variant is a separate SSZ container, the same field (say `to` or `value`) can end up at a different position in the Merkle tree for each variant. A light client or contract that verifies Merkle proofs then needs a per-variant table of field positions, and that table has to be updated whenever a new variant appears.

EIP-8016 adds a union type that only accepts variants whose trees line up, so a common field always has the same **generalized index (gindex)** across all of them.

## How it works

- **Notation:** `CompatibleUnion({selector: type})`, for example `CompatibleUnion({1: Square, 2: Circle})`. Selectors must be in `1..127`; `0` and values above `127` are reserved.
- **Compatibility rules:** variants must Merkleize the same way. Identical types are compatible; lists, vectors and bitfields need the same capacity; `Container`s need the same field names in the same order. [ProgressiveContainer](/eip-7495/) variants are compatible when their shared active fields have the same names and compatible types and no other field name is shared. [ProgressiveList](/eip-7916/) needs a compatible element type.
- **Serialization:** one selector byte followed by the serialized value. The type is always variable-size and has no default value.
- **Merkleization:** `hash(hash_tree_root(data), selector)`, i.e. the selector is mixed in. This guarantees two variants with identical tree shapes still get distinct roots.
- **JSON:** `{ "selector": "<n>", "data": ... }`.

## Sample code

Illustrative Python in the style of the consensus specs:

```python
class Square(ProgressiveContainer(active_fields=[1, 0, 1])):
    side: uint16
    color: uint8

class Circle(ProgressiveContainer(active_fields=[0, 1, 1])):
    radius: uint16
    color: uint8

Shape = CompatibleUnion({1: Square, 2: Circle})

def serialize_union(value) -> bytes:
    return value.selector.to_bytes(1, "little") + serialize(value.data)

def hash_tree_root_union(value) -> Root:
    return hash(hash_tree_root(value.data), value.selector.to_bytes(1, "little"))

# `color` sits at the same gindex in both Square and Circle,
# so one Merkle proof path works for every Shape.
```

## Things to know

- Status is **Draft**. It is part of the broader effort to move Ethereum data structures to SSZ, alongside [EIP-7495](/eip-7495/) and [EIP-7916](/eip-7916/) (both in Review).
- Wrapping an existing field in a `CompatibleUnion` is **not** backwards compatible, so the spec recommends introducing it early wherever more variants are expected, even with only one option today. After that, options can be added or dropped without breaking verifiers.
- It replaces an earlier SSZ union design that was only used in deprecated specs.
- Reference implementation: `ethereum/remerkleable`.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-8016
