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

SSZ list Merkle hashing change #538

Merged
merged 4 commits into from
Feb 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions specs/simple-serialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ Return the hash of the serialization of the value.

#### List/Vectors

First, we define some helpers and then the Merkle tree function.
First, we define some helpers and then the Merkle tree function. `zpad(input: bytes, length: int) -> bytes` is a helper that extends the given `bytes` value to the desired `length` by adding zero bytes on the right.
djrtwo marked this conversation as resolved.
Show resolved Hide resolved
vbuterin marked this conversation as resolved.
Show resolved Hide resolved

```python
# Merkle tree hash of a list of homogenous, non-empty items
Expand All @@ -401,7 +401,7 @@ def merkle_hash(lst):
items_per_chunk = SSZ_CHUNK_SIZE // len(lst[0])

# Build a list of chunks based on the number of items in the chunk
chunkz = [b''.join(lst[i:i+items_per_chunk]) for i in range(0, len(lst), items_per_chunk)]
chunkz = [zpad(b''.join(lst[i:i+items_per_chunk]), SSZ_CHUNK_SIZE) for i in range(0, len(lst), items_per_chunk)]
vbuterin marked this conversation as resolved.
Show resolved Hide resolved
else:
# Leave large items alone
chunkz = lst
Expand Down