Simple Serialize (SSZ) is a serialization and hashing scheme used by Ethereum. This project is a reference implementation written in Python which serves as the official specifications.
This project uses uv and
just.
just check # Run code quality checks
just fix # Run code quality fixers
just test # Run unit tests
just fill # Generate reference testsThis project generates JSON reference tests, included in each release, that SSZ implementations can run to ensure compliance with the specifications.
Each release ships the eth-ssz-specs package on PyPI and the reference tests on the
releases page, both built from
the tagged commit.
pip install eth-ssz-specsTAG=v0.1.0
curl -sSLO "https://github.com/leanEthereum/ssz-specs/releases/download/$TAG/ssz-test-vectors-$TAG.tar.gz"
curl -sSLO "https://github.com/leanEthereum/ssz-specs/releases/download/$TAG/ssz-test-vectors-$TAG.tar.gz.sha256"
sha256sum --check "ssz-test-vectors-$TAG.tar.gz.sha256"
tar -xzf "ssz-test-vectors-$TAG.tar.gz" # extracts fixtures/A true or false value.
Boolean(True)A zero or one value.
Bit(1)Eight bits of opaque data.
Byte(0xFF)An 8-bit unsigned integer.
Uint8(0xFF)A 16-bit unsigned integer.
Uint16(0xFFFF)A 32-bit unsigned integer.
Uint32(0xFFFFFFFF)A 64-bit unsigned integer.
Uint64(0xFFFFFFFFFFFFFFFF)A 128-bit unsigned integer.
Uint128(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)A 256-bit unsigned integer.
Uint256(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)A fixed number of elements.
class Color(Vector[Uint8]):
LENGTH = 3
Color(data=[255, 128, 0])A variable number of elements up to a limit.
class Scores(List[Uint64]):
LIMIT = 8
Scores(data=[10, 20, 30])A fixed number of bytes.
class Serial(ByteVector):
LENGTH = 4
Serial(b"\x01\x02\x03\x04")A variable number of bytes up to a limit.
class Message(ByteList):
LIMIT = 32
Message(data=b"hello")A fixed number of bits.
class Weekdays(BitVector):
LENGTH = 7
Weekdays(data=[1, 0, 0, 1, 0, 1, 0])A variable number of bits up to a limit.
class Answers(BitList):
LIMIT = 20
Answers(data=[1, 0, 1])A variable number of elements with no limit.
class Temperatures(ProgressiveList[Uint16]):
pass
Temperatures(data=[20, 21, 19])A variable number of bits with no limit.
ProgressiveBitList(data=[1, 0, 1])A fixed set of named fields.
class Point(Container):
x: Uint64
y: Uint64
Point(x=1, y=2)Named fields that keep their positions as the set changes.
class Square(ProgressiveContainer):
ACTIVE_FIELDS = active_fields(width=3, gaps=(1,))
side: Uint16 # position 0
color: Uint8 # position 2
Square(side=0x1234, color=0x42)A choice between options that share one tree shape.
class Shape(CompatibleUnion):
OPTIONS = {1: Square, 2: Circle}
Shape(selector=1, data=Square(side=0x1234, color=0x42))