Merge pull request #538 from ethereum/vbuterin-patch-1

SSZ list Merkle hashing change
This commit is contained in:
vbuterin 2019-02-03 14:37:30 -06:00 committed by GitHub
commit 2ac420c5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -390,7 +390,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 the Merkle tree function.
```python
# Merkle tree hash of a list of homogenous, non-empty items
@ -406,7 +406,10 @@ 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)
]
else:
# Leave large items alone
chunkz = lst