Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers EIP-8016.
EIP-8016 proposes adding a composite type called CompatibleUnion to SSZ so that Merkle proofs for common fields remain stable even when data can have multiple type options.
For data such as transactions, where several formats coexist, it allows fields with the same meaning to be verified at the same positional index.
Overview
EIP-8016 adds a type called CompatibleUnion({selector: type}) to SSZ.
It contains one type option selected by selector.
Unlike a regular Union, however, its available type options must have compatible Merkleization.
SSZ is the serialization format used by Ethereum's consensus layer. SSZ data can be converted into a Merkle tree, allowing Merkle proofs to be constructed for individual fields. A field's position is expressed as a generalized index (gindex).
The purpose of CompatibleUnion is to ensure that common fields retain the same gindex even when the type option changes.
This means verifiers can verify common fields without maintaining a separate mapping that says, for example, where amount appears in type 1 versus type 2.
The following diagram provides an overview of CompatibleUnion. The original diagrams in this article retain their Japanese labels.

On the left, types 1 and 2 share the fields amount and recipient.
In the middle, CompatibleUnion uses selector to choose the type.
On the right, the common fields occupy the same positional indices, allowing verifiers to apply the same Merkle proof approach to check their values.
Motivation
Data types such as transactions tend to acquire multiple formats over time. Formats with new features, older formats, and formats tailored to specific use cases can coexist.
The problem arises when fields with the same meaning are assigned different gindices depending on the type.
For example, if several transaction types all contain amount and recipient but place them at different positions in the Merkle tree, verifiers must maintain a mapping for each type.
As the number of types grows, mappings become easier to overlook during updates and verification logic becomes more complex.
CompatibleUnion reduces this burden.
By restricting type options to those with compatible Merkleization, it stabilizes the gindices of common fields.
As a result, verifiers can treat common fields as occupying the same positions even when multiple types coexist.
Programming languages use tagged unions for similar purposes.
EIP-8016 brings together a tag, represented by selector, and stable positional relationships for Merkle proofs in SSZ.
Specification
The EIP-8016 specification covers the definition of CompatibleUnion, compatible Merkleization, serialization, deserialization, JSON representation, and extensions to Merkleization.
CompatibleUnion({selector: type})
CompatibleUnion({selector: type}) is an SSZ composite type that contains one of the specified type options.
Its notation is as follows.
CompatibleUnion({1: Square, 2: Circle})In this example, when selector is 1, the contents are interpreted as Square; when it is 2, they are interpreted as Circle.
CompatibleUnion is always treated as a variable-size type, even if all its type options are fixed-size.
No default value is defined.
In other words, automatically constructing an initial value for CompatibleUnion is an error.
The following type definitions are invalid.
| Type definition | Behavior |
|---|---|
CompatibleUnion({}) |
Invalid because there are no type options. |
CompatibleUnion({selector: type}) with selector outside the range 1 to 127 |
Invalid because the selector is outside the permitted range. |
| Type options with incompatible Merkleization | Invalid because common field positions cannot be stabilized. |
The range of selector is uint8(1) through uint8(127).
0 is reserved to avoid collisions with uninitialized values.
Values of 128 and above have the most significant bit set and are reserved for future compatible extensions.
Compatible Merkleization
Whether a type can be used as an option depends on its Merkleization compatibility. Compatibility means that fields with the same meaning can occupy the same positions in the Merkle tree structure.
The compatibility rules are as follows.
| Type | Compatibility condition |
|---|---|
| Identical type | Compatible with itself. |
byte and uint8 |
Mutually compatible. |
Bitlist[N] |
Compatible if capacity N is the same. |
Bitvector[N] |
Compatible if capacity N is the same. |
List[type, N] |
Compatible if element types are compatible and capacity N is the same. |
Vector[type, N] |
Compatible if element types are compatible and length N is the same. |
ProgressiveList[type] |
Compatible if element types are compatible. |
Container |
Compatible if field names appear in the same order and each field type is compatible. |
ProgressiveContainer(active_fields) |
Compatible if fields active in both active_fields correspond to identical names and compatible types, with no other shared field names. |
Two CompatibleUnion types |
Compatible if every cross-combination of type options is compatible. |
| Other cases | Incompatible. |
ProgressiveList, proposed in EIP-7916, is a list type designed to support future extensions without a fixed capacity limit.
ProgressiveContainer, proposed in EIP-7495, is a type designed to make containers extensible by managing their active field sets.
EIP-8016 includes both of these extended types in its compatibility rules. This allows designs that expand fields or lists in the future to be combined with designs that stabilize Merkle proofs for common fields.
Serialization
A CompatibleUnion value has value.selector and value.data.
value.selector identifies the selected type option, while value.data contains the actual contents.
Serialization places selector in the first byte in little-endian format and appends the SSZ serialization of data.
return value.selector.to_bytes(1, "little") + serialize(value.data)Because selector is one byte, reading the first byte reveals which type should be used to interpret the remaining data.
This is also important when working with nested CompatibleUnion values.
A parser can determine the type of the remaining data early, without having to infer the entire tree structure afterward.
Deserialization
During deserialization, the first byte of the input scope is read as selector.
The remaining bytes are then deserialized using the type option selected by selector.
The process is illustrated below.

The first byte selects the type, and the remaining data is interpreted as that type.
When constructing the Merkle root, selector is mixed into the hash_tree_root of data, allowing distinct roots even for different type options with the same tree structure.
Implementations must robustly handle the following invalid inputs.
| Invalid input | Behavior |
|---|---|
Out-of-range selector |
Fails because no type option can be selected. |
| Input shorter than one byte | Fails because selector cannot be read. |
| Malformed serialized data | Fails because it cannot be read as a valid SSZ value. |
| Data invalid for the inner type | Fails according to the selected type's deserialization rules. |
JSON Representation
The JSON representation of CompatibleUnion is an object containing selector and data.
The contents of data vary according to the type selected by selector.
{
"selector": "1",
"data": {
"width": "10",
"height": "20"
}
}Explicitly including selector in JSON also makes it possible to determine which type to use when reading data back into an SSZ value.
Merkleization
EIP-8016 adds a helper function called mix_in_selector to SSZ Merkleization.
mix_in_selector takes a Merkle root and selector and hashes them to construct the root of the entire CompatibleUnion.
The selector passed here is a value serialized as uint8.
def mix_in_selector(root, selector):
return hash(root, selector)The hash_tree_root of CompatibleUnion is computed as follows.
mix_in_selector(hash_tree_root(value.data), value.selector)With this operation, even if the Merkle tree for data has the same shape, different values of selector produce different final roots.
For different type options sharing the same tree structure, or values such as empty lists whose roots are difficult to distinguish by element type alone, selector reflects the type difference in the root.
Rationale
Why selector is restricted to 1 through 127
The value 0 of selector is not used to avoid collisions with uninitialized values.
This also leaves room for a future EIP to use it as a value representing Optional.
Values of 128 and above have the most significant bit set.
Leaving this range unused allows it to be used for future backward-compatible extensions.
For the use cases currently envisaged, the 127 type options from 1 through 127 are sufficient.
Why use a tag instead of a field set?
An alternative design considered including the active_fields bitvector in the serialization.
This would represent which fields are active as a sequence of bits.
However, when ProgressiveContainer types are nested, a parser cannot immediately determine the entire tree structure.
Each nesting level also becomes variable-size, increasing serialization overhead.
In CompatibleUnion, the leading selector identifies the type first.
The parser can therefore determine the type of the remaining data early.
Even with nested data, it is clear which type to read at each level.
Why introduce the type early?
Wrapping an existing field in CompatibleUnion after the fact is not a backward-compatible change.
For fields expected to be extended in the future, CompatibleUnion must therefore be introduced early, even when only one type option exists.
Once CompatibleUnion has been introduced, however, new type options can be added and old ones removed without breaking verifiers.
This is because verifiers can continue to use the gindices of common fields.
Backward Compatibility
CompatibleUnion({selector: type}) replaces the previous SSZ Union proposal.
The earlier Union design was used in deprecated specifications.
The Portal Network also has a notion of unions.
However, since the Portal Network's network types do not use hash_tree_root, it can migrate to CompatibleUnion by introducing a new network version.
The important point is that wrapping a field in CompatibleUnion is not itself backward-compatible.
Where future type extensions are anticipated, the design should use CompatibleUnion from an early stage rather than wrapping fields later.
Test Cases
EIP-8016 is tested using existing SSZ implementations and test resources.
ethereum/remerkleable contains static tests in test_impl.py and test_typing.py.
Releases of ethereum/consensus-specs also include randomized tests under tests/general/phase0/ssz_generic.
These tests are generated according to the format defined in tests/format/ssz_generic.
Reference Implementation
The reference implementation is available in ethereum/remerkleable.
Because CompatibleUnion affects the SSZ type system, serialization, deserialization, and Merkleization, it is more natural to support it within an SSZ library than to handle it solely in application code.
Key implementation checks include the range of selector, compatibility between type options, delegation of deserialization to the inner type, and root calculation through mix_in_selector.
Security Considerations
In CompatibleUnion, mixing selector into the Merkle root is important.
It allows the final hash_tree_root to distinguish different type options even when they share the same Merkle tree structure.
Without mixing in selector, different type options with the same tree structure may produce the same root.
For empty List[type, N] or ProgressiveList[type] values differing only in element type, hash_tree_root alone may also have difficulty expressing the type difference.
In such cases, applications need additional mechanisms, such as mixing type information into the signing root or representing the type in a separate field.
EIP-8016 incorporates this responsibility into SSZ Merkleization.
Using mix_in_selector(hash_tree_root(value.data), value.selector) binds the type selection and the root of the data itself into a single root.
Deserialization must reliably reject out-of-range selector values, inputs shorter than one byte, malformed data, and values invalid for the inner type.
Ambiguity here could cause implementations to interpret identical byte sequences differently and produce inconsistent verification results.
Conclusion
This article covered EIP-8016.
CompatibleUnion is a proposal for stabilizing Merkle proofs for common fields while supporting multiple SSZ type options.
It uses the first byte, selector, to select the type and mixes selector into the Merkle root of data, combining type distinction with straightforward verification of common fields.
For SSZ data expected to evolve in the future, incorporating a Union type into the design early is important.
I also write articles elsewhere, so feel free to explore them.




