ebc136a
When hashing containers using SSZTreeHash, it is currently specified that fields short be sorted lexicographically.
There are advantages:
- generic solution
- no mental overhead to decide where fields go, can focus on "logical" ordering in spec
There are a few downsides of this approach however:
- Variable-length fields make offsets non-predictable even for fixed-length fields
- Reduced possibility to group similar fields together, for example by data type, to exploit bulk operations
Alternative approaches:
- Manual ordering - enforce that hashing is done in same order as in spec, and control a good ordering manually
- Often coupled with a restriction that new fields are added at end for upgrades, to maintain soft compatibility with previous versions
- Data-type based ordering - generally, these kinds of orderings group data by type, putting fixed-length fields before variable-length fields - this gives each field a fixed relative offset making it easy to look up. This kind of ordering also helps keep aliasing issues at a minimum.
Most helpful comment
+1 for manual ordering