-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
I just happened to meet this empty bitlist corner case and expected a different serialization for it. Empty bitlist is the default value as per SSZ spec and the serialization should be as follows:
>>> # Import the SSZ types we need
>>> from eth2spec.utils.ssz.ssz_typing import Bitlist
>>> from eth2spec.utils.ssz.ssz_impl import serialize
>>> # Create an empty bitlist with limit 8
>>> empty_bitlist = Bitlist[8]()
>>> serialize(empty_bitlist)
b'\x01'
>>> serialize(empty_bitlist) = Bitlist[16]()
>>> empty_bitlserialize(ist = Bitlist)
b'\x01'This affects also the hash_tree_root. Instead of returning an error in case of empty bitlist:
fastssz/sszgen/generator/hash.go
Lines 146 to 150 in 7a7ae52
| case *BitList: | |
| tmpl := `if len({{.name}}) == 0 { | |
| err = ssz.ErrEmptyBitlist | |
| return | |
| } |
For the empty bitlist, it must compute the hash_tree_root following the spec
mix_in_length(merkleize(pack_bits(value), limit=chunk_count(type)), len(value))
ifvalueis a bitlist.
Here I expose two hash tree root examples of empty bitlists with different sizes:
>>> empty_bitlist_length16 = Bitlist[16]()
>>> hash_tree_root(empty_bitlist_length16)
0xf5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b
>>> empty_bitlist_length2048 = Bitlist[2048]()
>>> hash_tree_root(empty_bitlist_length2048)
0xe8e527e84f666163a90ef900e013f56b0a4d020148b2224057b719f351b003a6Metadata
Metadata
Assignees
Labels
No labels