optimism-java / zephyrus

Ethereum consensus client in Zig
MIT License
8 stars 2 forks source link

SSZ zig enhancement #29

Open GrapeBaBa opened 4 days ago

GrapeBaBa commented 4 days ago

There is a zig ssz lib here developed by the member of Verkle/ZEAM team, but we found some issues when used it in consensus spec types. We can enhance this lib and further do optimization to make it available for both beacon and beam chain. There is a talk at Devcon 7 which introduced high perf ssz lib implementation here which can be inspired.

eightfilms commented 3 days ago

What are some of the issues found? I guess it has to do with the issues you've opened.

GrapeBaBa commented 3 days ago

@fearlessfe Can you post all the issues and alternative solutions here to discuss

fearlessfe commented 3 days ago

@eightfilms Our code is not exact the same with the ssz lib , because we use the latest version of zig, the std.builtin.Type has changed.

In fact our encode and decode methods are from the zabi, the origin code of zabi is also from the ssz lib , but with some updates; the hashRootTree method are from the ssz lib .

In our ssz spec tests, we find some bugs(according to the current ssz lib)

  1. when serialize struct, int, bool, array, struct with fixed length should serialize directly, the same with deserialize method
  2. there is bug in merkleize method, you can see in this pr
  3. in hashTreeRoot method, when the type is Slice, we must pass the limit, after that, it should call the mixInLength method. Now, we doesn't find a solution to pass the limit of Slice type.