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

Added tree hashing algorithm #120

Merged
merged 5 commits into from
Nov 15, 2018
Merged

Added tree hashing algorithm #120

merged 5 commits into from
Nov 15, 2018

Conversation

vbuterin
Copy link
Contributor

@vbuterin vbuterin commented Nov 8, 2018

Adds to the SSZ spec an algorithm for tree-hashing SSZ objects.

Experiments suggest that the hashing time required is increased by a factor of ~4-6, partly because Merkle hashing inherently raises the amount of data hashes due to multiple layers of hashing and partially because hash functions have a fixed computation cost in addition to the per-byte cost.

Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

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

It's pretty dense. I would give some more motivation/explanation in the header.
Specifically, why this instead of a straight merkle tree? This allows for easy updates when isolated SSZ containers/lists are modified.

specs/simple-serialize.md Show resolved Hide resolved
specs/simple-serialize.md Show resolved Hide resolved
@mkalinin
Copy link
Collaborator

It would be nice to have an example of tree_hash function implementation at the end of Tree hash section.

@vbuterin
Copy link
Contributor Author

It would be nice to have an example of tree_hash function implementation at the end of Tree hash section.

@mkalinin you can find this here: https://github.com/ethereum/beacon_chain/blob/vitalik_hash_ssz/hash_ssz.py

I imagine @djrtwo will copy the code or something like it into the python impl once this gets finalized/approved.

chunkz.append(b'\x00' * CHUNKSIZE)
chunkz = [hash(chunkz[i] + chunkz[i+1]) for i in range(0, len(chunkz), 2)]
# Return hash of root and length data
return hash(chunkz[0] + datalen)
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: lst / chunkz can be empty in the general case

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

Successfully merging this pull request may close these issues.

4 participants