Eth2.0-specs: SSZ: explicit ordering vs sorted-by-field

Created on 10 Dec 2018  路  2Comments  路  Source: ethereum/eth2.0-specs

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.
enhancement

Most helpful comment

+1 for manual ordering

All 2 comments

+1 for manual ordering

closed via #339

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dankrad picture dankrad  路  14Comments

spble picture spble  路  28Comments

protolambda picture protolambda  路  23Comments

hwwhww picture hwwhww  路  13Comments

JustinDrake picture JustinDrake  路  24Comments