EIP-8526: SSZ Keccak Merkleization
Keccak-256 based Merkleization for SSZ types
Abstract
This EIP introduces a hash keyword for composite Simple Serialize (SSZ) types that names the hash function of their Merkleization, and defines Keccak-256 as an alternative to SHA-256. The Merkle tree shape and the generalized indices of a type do not depend on its hash function.
Motivation
SSZ Merkleization is based on SHA-256, the hash function of the consensus specifications. The execution layer commits to its state, transactions, receipts and blocks with Keccak-256, derives addresses with it, and provides it to smart contracts as the KECCAK256 (0x20) instruction. Execution layer data structures can so far adopt SSZ solely with SHA-256.
Keccak-256 is a conservative choice for a hash function that Ethereum relies on in the long term: it has a large security margin and a long record of public cryptanalysis. In "PQAI #1" (2026-11-24), researchers of the Ethereum Foundation observe that proof systems over binary fields now prove hash functions such as Keccak-256 efficiently, so that security decides the choice of hash function. They recommend Keccak-256 for Ethereum's hash-based cryptography, and for SSZ once it is introduced on the execution layer.
The hash keyword lets execution layer data structures adopt SSZ with Keccak-256 by:
- Binding the hash function to the type, so that an object has the same
hash_tree_rootwherever it is used, on both layers. - Retaining the Merkle tree shape, so that generalized indices are stable across hash functions.
- Applying to each type individually, so that a type adopts Keccak-256 without changing the hash function of the types that contain it.
Specification
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174.
hash keyword
The notation of every SSZ composite type is extended with an optional hash keyword that names the hash function of its Merkleization:
| Type | Notation with hash keyword |
|---|---|
Container | Container(hash=keccak256) |
ProgressiveContainer(active_fields) | ProgressiveContainer(active_fields, hash=keccak256) |
Vector[type, N] | Vector(hash=keccak256)[type, N] |
List[type, N] | List(hash=keccak256)[type, N] |
ProgressiveList[type] | ProgressiveList(hash=keccak256)[type] |
Bitvector[N] | Bitvector(hash=keccak256)[N] |
Bitlist[N] | Bitlist(hash=keccak256)[N] |
ProgressiveBitlist | ProgressiveBitlist(hash=keccak256) |
Union[type_0, type_1, ...] | Union(hash=keccak256)[type_0, type_1, ...] |
CompatibleUnion({selector: type}) | CompatibleUnion({selector: type}, hash=keccak256) |
- The keyword is part of the constructor call and precedes bracket parameters. A constructor call with the keyword denotes a type, never a value.
- Only the notations of the table and the aliases below take the keyword.
- Omitting the keyword is equivalent to
hash=sha256: both denote the same type. - A type expression denotes the same type wherever it is used: neither a type that contains it nor a type that it contains changes its hash function.
- A type MAY contain types with other hash functions.
- Basic types have no hash function and take no keyword.
- A container or progressive container MAY have a field named
hash.
For convenience we alias:
ByteVector(hash=keccak256)[N]toVector(hash=keccak256)[byte, N]BytesN(hash=keccak256)toByteVector(hash=keccak256)[N]ByteList(hash=keccak256)[N]toList(hash=keccak256)[byte, N]ProgressiveByteList(hash=keccak256)toProgressiveList(hash=keccak256)[byte]
class Square(ProgressiveContainer(active_fields=[1, 0, 1], hash=keccak256)):
side: uint16
color: uint8
class Drawing(Container(hash=keccak256)):
shapes: ProgressiveList(hash=keccak256)[Square]
others: ProgressiveList[Square] # Merkleized with `sha256`, each `Square` with `keccak256`
title: ProgressiveByteList # Merkleized with `sha256`
class Gallery(Container): # Merkleized with `sha256`
drawings: ProgressiveList(hash=keccak256)[Drawing]
owner: ByteVector[48] # Merkleized with `sha256`
Serialization, deserialization, JSON mapping, default values, Merkle tree shape and generalized indices of a type are identical for every hash function.
Hash functions
A hash function maps bytes to Bytes32. The following hash functions are defined:
hash | Hash function |
|---|---|
sha256 | SHA-256, the hash function of the consensus specifications |
keccak256 | Keccak-256, the keccak256 function of the execution specifications |
keccak256 is not the SHA3-256 function of FIPS 202.
Merkleization
The helper functions of the SSZ Merkleization specification are extended for a hash function H:
hash(a, b): Givenaandbof at mostBYTES_PER_CHUNKbytes each, right-pad each with zeroes toBYTES_PER_CHUNKbytes and returnH(a + b).merkleize(chunks, limit=None): "merkleize as binary tree" computes each parent node ashash(left, right)of its two child nodes, including every node above zeroed chunks.
The Merkleization definitions are extended.
- In every definition of
hash_tree_root(value)for avalueof a composite type,His the hash function of the type ofvalue. - Each nested
hash_tree_rootuses the hash function of the type of its own argument. - A type invokes
hashif and only if its definition ofhash_tree_root(value)does so outside of nestedhash_tree_root.- A
Vector,BitvectororContainertype invokeshashif and only ifchunk_count(type) > 1, e.g.,ByteVector[48]but notByteVector[32]. - A
List,Bitlist,ProgressiveList,ProgressiveBitlist,ProgressiveContainer,UnionorCompatibleUniontype always invokeshash.
- A
- A type that invokes
hashis a summary type of an expansion type only if they share the same hash function.
Compatible Merkleization
The compatible Merkleization definitions are extended.
- Types that invoke
hashare compatible only if they also share the same hash function.
Merkle proofs
The SSZ Merkle proof specification is extended.
merkle_tree,calculate_merkle_rootandcalculate_multi_merkle_root, as well asverify_merkle_proofandverify_merkle_multiproof, are additionally given the hash function of each node that is computed: that of the type whose Merkleization computes the node. A node that combines the roots of nested values uses the hash function of the containing type.- Below a
Union(but not aCompatibleUnion), the hash function of a node depends on the selected option.
Rationale
Why is the hash function bound to the type?
An object has a single hash_tree_root, independent of where it is used: an object whose type is Merkleized with Keccak-256 keeps its root when it is nested in a container that is Merkleized with SHA-256, e.g., an execution layer object in a consensus layer container. A root that one layer computes can be used by the other layer without hashing the object a second time.
Why is nothing inferred from the containing type?
If the hash function of a container extended to its fields, the same type expression would denote different Merkle trees in different containers, and reusing a type would silently change the roots of its objects.
Why not a hash function chosen by the caller?
A hash function that is passed to hash_tree_root applies to an entire tree, so an object would have one root per caller. Objects of one layer are nested in objects of the other, so a tree has to be able to contain Keccak-256 and SHA-256 types.
Why keep the Merkle tree shape?
The Merkle tree shape determines the generalized indices. Keeping it lets a type change its hash function with stable generalized indices, and lets implementations share everything but the hash function.
Why Keccak-256 and not SHA3-256?
Keccak-256 and SHA3-256 share their permutation, rate and capacity and differ in their padding. The execution layer computes its block hash and trie roots with Keccak-256 and provides it to smart contracts as the KECCAK256 instruction.
What is the performance impact?
Per parent node, SHA-256 runs its compression function twice, as the padding of the 64-byte input takes a second block, and Keccak-256 runs its permutation once. Keccak-256 Merkleization is nevertheless slower than SHA-256 Merkleization on processors that implement SHA-256 instructions, which most current x86 and Arm processors do. Neither instruction set includes an instruction that computes a round of Keccak: x86 has none that is specific to Keccak, and the optional Arm extension for SHA-3 provides XOR, AND-NOT and rotate combinations from which a round is assembled. Implementations can narrow the gap by hashing multiple nodes per call.
Backwards Compatibility
Existing SSZ types do not carry the hash keyword. The hash_tree_root of their objects does not change.
Adding hash=keccak256 to a type that invokes hash changes the hash_tree_root of its objects and of the objects that contain them. An empty list keeps its root when only the hash function of its element type changes. A union value keeps its root when only an unselected option changes. Merkle proof verifiers require updates where they compute a node with the new hash function. Serialization and generalized indices remain unchanged.
Test Cases
Let T = List[ByteVector(hash=keccak256)[64], 1], and let the value of T contain one element of 64 zero bytes. The element comprises two zero chunks. The list has capacity one, so its data root is the element root. The list uses its default hash function, SHA-256, for the length mix-in.
| Generalized index | Computation | Expected root (hex) |
|---|---|---|
2 | keccak256(bytes(64)) | ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5 |
1 | sha256(element_root + (1).to_bytes(32, "little")) | 69335a635977117abab65bb8c344f71463eb500380c8861f7fa81ecba782196e |
A proof for the first data chunk, at generalized index 4, uses its sibling at index 5 to compute the element root with Keccak-256. It then uses the length chunk at index 3 to compute the list root with SHA-256.
Reference Implementation
TBD
Security Considerations
- Security level: SHA-256 and Keccak-256 have the same output length and the same generic strengths, 128 bits against collisions and 256 bits against preimages. The
hash_tree_rootof an object whose Merkle tree has nodes of both hash functions relies on the collision resistance of both. - Preimages: Every
hashinvocation of a type withhash=keccak256computes Keccak-256 over 64 bytes. Other uses of Keccak-256 hash 64 bytes as well, e.g., the derivation of an address from a public key. A transaction, its signing payload or a trie node can also be encoded in 64 bytes. Where both children of a node hold data, e.g., two siblingBytes32fields or two sibling chunks of a byte list, all 64 bytes can be chosen freely. - Signatures and identifiers: A protocol that signs a Keccak-256 based
hash_tree_roothas to specify the signing preimage and how it is distinguished from preimages used for other purposes under the same signing key. A protocol can include the root in an existing domain-separated signing envelope. It can also define a two-fieldContainer(hash=keccak256)whose fields are a protocol-specificBytes32domain constant and theBytes32object root, in that order, with a domain constant that does not begin any other encoding signed with the same key, e.g., RLP data or an EIP-2718 typed transaction. A protocol that uses a root as an identifier in a shared namespace likewise has to specify how it distinguishes the identifier domains. - Type separation: As with SHA-256, mix-ins do not separate types from each other. A length of
6, a selector of6and anactive_fieldsconfiguration of[0, 1, 1]are mixed in as the same chunk. - Merkle proofs: A generalized index identifies a position in the tree, not the hash function of its node. A verifier of a proof that spans types with different hash functions needs the types along the proven path.
- Resource usage: On processors that implement SHA-256 instructions, hashing an object of a given size takes longer with Keccak-256 than with SHA-256. Limits that bound the hashing work per block or per message have to account for the difference.
Copyright
Copyright and related rights waived via CC0.