Skip to content
This repository was archived by the owner on Apr 23, 2019. It is now read-only.
This repository was archived by the owner on Apr 23, 2019. It is now read-only.

Support "tuples" and "lists" from SSZ Spec v0.5.1 #207

Description

@schroedingerscode

@atoulme and/or @cleishm, if you wouldn't mind giving a little thought to the below proposal, I'd be most appreciative. I've spent a little bit mulling this over and plan to take a first stab at a PR shortly, but in the meantime an extra set of eyes doesn't hurt.

Description
The SSZ spec was rewritten as part of the eth2-specs v0.5.1 release to include both fixed-length and variable-length arrays/lists. Following the python notation used in the eth2-specs, and for the sake of clarity, fixed-length arrays/lists will be referred to as "tuples" and variable-length array/lists will be referred to as "lists".

(Not so) Quick Background

  • Firstly, the SSZ spec has a limited number of base types:
    • uintN (where N is in 8, 16, 32, 64, 128, or 256)
      a N bit unsigned integer
    • bool
      A Boolean (True or False)
    • byte == uint8
      byte is an alias for uint8
  • Composite types from these include:
    • tuple, represented as [type, N]
      a fixed-length homogenous collection of N values
    • list, represented as [type]
      a variable-length homogenous collection of values
  • Some derived values, therefore are:
    • bytes == ["byte"]
      A variable-length collection of byte types (uint8 types by extension)
    • bytesN == ["byte", N]
      A fixed-length collection of byte types with N length

The implications of the above are that "list" requires a length mixin, where as a "tuple" does not.

Proposed Changes

  • When Java bytes are serialized (i.e. when recursively serializing a Cava Bytes type), they should be serialized as a uint8.
  • A Cava Bytes type of length 1 should be serialized as a uint8. [still undecided on this one]
  • A Cava Bytes type of length >1 should be treated and serialized as a "list".
  • All fixed length Cava BytesN types (i.e. Bytes32) should be treated and serialized as a "tuple".
  • Support will be added for serializing Bytes... (varags list) as either a "list" or a "tuple"
    • The proposed method of achieving this is overloading the relevant functions with an additional length parameter.
  • Support will be added for serializing List<? extends Bytes> as either a "list" or a "tuple".
    • The proposed method of achieving this is overloading the relevant functions with an additional length parameter.

Additional Information
See https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/simple-serialize.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions