Minor fixes

This commit is contained in:
Hsiao-Wei Wang 2019-08-15 18:26:22 +08:00
parent 0f52d460a5
commit 2741a5f33d
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
2 changed files with 4 additions and 4 deletions

View File

@ -8,7 +8,7 @@
- [Merkle proof formats](#merkle-proof-formats) - [Merkle proof formats](#merkle-proof-formats)
- [Table of contents](#table-of-contents) - [Table of contents](#table-of-contents)
- [Custom types](#custom-types) - [Custom types](#custom-types)
- [Helpers](#helpers) - [Helper functions](#helper-functions)
- [Generalized Merkle tree index](#generalized-merkle-tree-index) - [Generalized Merkle tree index](#generalized-merkle-tree-index)
- [SSZ object to index](#ssz-object-to-index) - [SSZ object to index](#ssz-object-to-index)
- [Helpers for generalized indices](#helpers-for-generalized-indices) - [Helpers for generalized indices](#helpers-for-generalized-indices)
@ -30,7 +30,7 @@ We define the following Python custom types for type hinting and readability:
| - | - | - | | - | - | - |
| `GeneralizedIndex` | `uint64` | the index of a node in a binary Merkle tree | | `GeneralizedIndex` | `uint64` | the index of a node in a binary Merkle tree |
## Helpers ## Helper functions
```python ```python
def get_next_power_of_two(x: int) -> int: def get_next_power_of_two(x: int) -> int:
@ -67,7 +67,7 @@ In a binary Merkle tree, we define a "generalized index" of a node as `2**depth
Note that the generalized index has the convenient property that the two children of node `k` are `2k` and `2k+1`, and also that it equals the position of a node in the linear representation of the Merkle tree that's computed by this function: Note that the generalized index has the convenient property that the two children of node `k` are `2k` and `2k+1`, and also that it equals the position of a node in the linear representation of the Merkle tree that's computed by this function:
```python ```python
def merkle_tree(leaves: List[Bytes32]) -> List[Bytes32]: def merkle_tree(leaves: Squence[Hash]) -> Squence[Hash]:
padded_length = get_next_power_of_two(len(leaves)) padded_length = get_next_power_of_two(len(leaves))
o = [Hash()] * padded_length + leaves + [Hash()] * (padded_length - len(leaves)) o = [Hash()] * padded_length + leaves + [Hash()] * (padded_length - len(leaves))
for i in range(len(leaves) - 1, 0, -1): for i in range(len(leaves) - 1, 0, -1):