EIP-8016 · Draft · Core · 2025-08-28
EIP-8016: SSZ CompatibleUnion
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 exampleCompatibleUnion({1: Square, 2: Circle}). Selectors must be in1..127;0and values above127are reserved. - Compatibility rules: variants must Merkleize the same way. Identical types are compatible; lists, vectors and bitfields need the same capacity;
Containers need the same field names in the same order. ProgressiveContainer variants are compatible when their shared active fields have the same names and compatible types and no other field name is shared. ProgressiveList 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:
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 and EIP-7916 (both in Review).
- Wrapping an existing field in a
CompatibleUnionis 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.