Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not duplicate bytes length when tree-hashing #596

Merged
merged 2 commits into from
Feb 11, 2019
Merged

Conversation

JustinDrake
Copy link
Collaborator

When tree-hashing a bytes the length currently appears twice:

  1. in the first four bytes of the serialisation
  2. in the final hash(chunkz[0] + datalen)

This is suboptimal:

  1. It is unnecessary and causes an awkward 4-byte misalignment.
  2. It is inconsistent with the way lists are handled. (bytes is just a list of uint8.)
  3. Removing the 4 leading bytes is an optimisation opportunity when the Merkle root of the bytes object is already known.

When tree-hashing a `bytes` the length currently appears twice:

1) in the first four bytes of the serialisation
2) in the final `hash(chunkz[0] + datalen)`

This is suboptimal:

1) It is unnecessary and causes an awkward 4-byte misalignment.
2) It is inconsistent with the way lists are handled. (`bytes` is just a list of `uint8`.)
3) Removing the 4 leading bytes is an optimisation opportunity when the Merkle root of the `bytes` object is already known.
@vbuterin
Copy link
Contributor

I'd support making bytes a de facto synonym for List[bytes1] globally in SSZ; it does make it simple.

@JustinDrake
Copy link
Collaborator Author

Yay, 47 lines removed!

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:SSZ Simple Serialize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants