---
eip: 6475
label: EIP-6475
title: SSZ Optional
status: Stagnant
type: Standards Track
category: Core
created: 2023-02-09
official: https://eips.ethereum.org/EIPS/eip-6475
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-6475.md
canonical: https://eips.huatuo.xyz/eip-6475/
lang: en
tldr: "Proposes a native Optional[T] type for SSZ, the consensus layer's serialization format, so a value can be explicitly absent without awkward list or union workarounds."
tags: [ssz, serialization, consensus, types]
---

# EIP-6475: SSZ Optional

> New SSZ type to represent optional values

**TL;DR:** Proposes a native Optional[T] type for SSZ, the consensus layer's serialization format, so a value can be explicitly absent without awkward list or union workarounds.

## What problem does it solve?

Simple Serialize (SSZ) is the encoding and Merkleization scheme used by Ethereum's consensus layer. It has no way to say "this field may be missing". Spec writers have to fake it, typically with a `List[T, 1]` (zero or one element) or a `Union[None, T]`. Both work but are clumsy:

- `List[T, 1]` needs an offset table for variable-size `T`, so it serializes larger than necessary.
- `Union` types had no finalized design and were not used in any final specification, and `Union[None, T]` hints that more variants might be added later.

EIP-6475 proposes a dedicated `Optional[T]` that maps cleanly onto `Optional` types in programming languages.

## How it works

- **Type:** `Optional[T]` holds either a value of SSZ type `T`, or `None`. The default is `None`.
- **Serialization:** `None` serializes to an empty byte string. A present value serializes as `0x01` followed by `serialize(value)`.
- **Deserialization:** an empty input means `None`; otherwise the first byte must be `0x01` and the rest is decoded as `T`.
- **Merkleization:** identical to `List[T, 1]`: length 0 for `None`, length 1 with the value otherwise. So the hash tree root is the same as the list workaround, while the byte encoding is more compact.

## Sample code

Python-style reference logic:

```python
def serialize_optional(value, serialize_t) -> bytes:
    if value is None:
        return b""
    return b"\x01" + serialize_t(value)

def deserialize_optional(data: bytes, deserialize_t):
    if len(data) == 0:
        return None
    assert data[0] == 0x01, "invalid Optional prefix"
    return deserialize_t(data[1:])

def hash_tree_root_optional(value, T):
    # Merkleized exactly like List[T, 1]
    return hash_tree_root(List[T, 1]([] if value is None else [value]))

# Example with T = uint64
assert serialize_optional(None, ser_u64) == b""
assert serialize_optional(5, ser_u64) == b"\x01" + (5).to_bytes(8, "little")
```

## Things to know

- **Status: Stagnant.** `Optional[T]` is not part of the SSZ specification used by Ethereum clients today.
- Because the encoding of `None` is empty, an `Optional` is variable-size: inside a container it is placed behind an offset like other variable-size fields.
- Later SSZ work has focused on other extensions, such as [EIP-7495](/eip-7495/) (ProgressiveContainer) and [EIP-7916](/eip-7916/) (ProgressiveList), which address forward-compatible containers and unbounded lists.


---

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