Merkleise SSZ container elements (#595)

Reasons to use `merkle_hash` instead of  `hash` for containers:

1) **Smaller witnesses**: `BeaconState` is a somewhat wide container (26 fields as of now, likely 30+ in phase 2). With concatenation and plain concatenation the size of the Merkle witnesses for the top level are ~32 bytes per field element.
2) **Faster incremental hashing**
3) **Consistency**: Consistent with `merkle_hash` for lists/vectors.
This commit is contained in:
Justin 2019-02-12 21:57:54 +00:00 committed by GitHub
parent f871b9a0d1
commit 3459515c2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -390,10 +390,10 @@ Where the inner `hash_tree_root_internal` is a recursive application of the tree
#### Container
Recursively tree hash the values in the container in the same order as the fields, and return the hash of the concatenation of the results.
Recursively tree hash the values in the container in the same order as the fields, and Merkle hash the results.
```python
return hash(b''.join([hash_tree_root_internal(getattr(x, field)) for field in value.fields]))
return merkle_hash([hash_tree_root_internal(getattr(x, field)) for field in value.fields])
```
## Implementations