Closed itsdevbear closed 1 week ago
[!WARNING]
Review failed
The pull request is closed.
This update introduces the SSZ (Simple Serialize) library for basic and composite data types in the types
and ssz
packages. The changes include defining SSZ-compatible types and their methods, adding merkleizers, and implementing marshaling and unmarshaling functions. Additionally, certain functions have been removed or adjusted to align with the updated SSZ implementation. Tests have been updated to verify the correctness of serialization logic.
File(s) | Change Summary |
---|---|
.../types/basic.go |
Introduced SSZ types (bool, uint8, uint16, uint32, uint64, byte) with methods for SSZ operations and hash tree root computation. |
.../types/constants.go |
Defined constants (BytesPerChunk , BytesPerLengthOffset , BitsPerByte ) for SSZ serialization. |
.../types/interfaces.go |
Introduced Merkleizer interface with methods for basic and composite types' merkleization. |
.../types/vector_basic.go , .../types/vector_composite.go |
Added SSZ vectors for basic and composite types with methods for SSZ serialization and hash tree root computation. |
.../types/list_basic.go , .../types/list_composite.go |
Added SSZ lists for basic and composite types with methods for SSZ serialization and hash tree root computation. |
.../vector.go |
Introduced SSZ vectors for basic and composite types, including SSZ operations and vector conversion functions. |
.../vector_test.go |
Added test cases for SSZ vectors, including size calculations, hashing, marshaling, and unmarshaling operations. |
.../serialization.go |
Removed redundant (un)marshal functions and focused on bit manipulation functions for improved clarity and performance. |
.../index.go |
Renamed package from merkle to ssz and updated related imports. |
.../index_test.go |
Renamed package references from merkle to ssz in test cases. |
.../constraints.go |
Introduced Base , Basic , and Composite interfaces defining SSZ serialization and hash tree root calculation methods. |
.../interfaces.go |
Introduced BaseMerkleizer , BasicMerkleizer , CompositeMerkleizer interfaces for SSZ merkleization operations for different SSZ types. |
To visualize the changes, we can create a high-level sequence diagram for the SSZ serialization process of a basic type (e.g., uint32):
sequenceDiagram
participant App as Application
participant SSZUInt32 as SSZUInt32
participant Merkleizer as BasicMerkleizer
App->>SSZUInt32: Create instance
App->>SSZUInt32: MarshalSSZ()
SSZUInt32-->>App: Serialized bytes
App->>Merkleizer: HashTreeRoot(SSZUInt32)
Merkleizer-->>App: Computed Hash Root
π Amid the bytes and roots so bright,
SSZ forms take joyful flight.
Bits and chunks dance in array,
Vector, listβthey find their way.
Marshaled, hashed, they hold their ground,
In merkle's world, they're tightly bound.
A coder's heart in data's light,
The rabbit's joy takes graceful height. π
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 70.45%. Comparing base (
de48919
) to head (5065a46
).:exclamation: Current head 5065a46 differs from pull request most recent head 5575df8
Please upload reports for the commit 5575df8 to get more accurate results.
@itsdevbear with regard to schema definition and parsing theyβre separate concerns, in schema.go one parser could be substituted for another. In other words if the beacon monolith defines fields with these types a slightly different parser is needed to get the reflection right, and that could be plugged in.
It looks like that PR could end up being part of a substitute for fastssz though which is probably good.
On the other hand, if you commit to wrapping all types in an SSZ monolithic struct maybe reflection wouldn't even be needed? The generic impl could return the metadata required to build the schema? Not sure yet.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Refactor
merkle
tossz
for clarity and consistency across the project.