Made code work with #1186

This commit is contained in:
vbuterin 2019-08-01 10:58:15 -04:00 committed by Hsiao-Wei Wang
parent fab37e747a
commit b9fddfe310
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
1 changed files with 2 additions and 16 deletions

View File

@ -86,29 +86,15 @@ def get_previous_power_of_2(x: int) -> int:
```python ```python
def verify_merkle_proof(leaf: Hash, proof: Sequence[Hash], index: GeneralizedIndex, root: Hash) -> bool: def verify_merkle_proof(leaf: Hash, proof: Sequence[Hash], index: GeneralizedIndex, root: Hash) -> bool:
assert len(proof) == log2(index) assert len(proof) == get_generalized_index_length(index)
for i, h in enumerate(proof): for i, h in enumerate(proof):
if index & 2**i: if get_generalized_index_bit(index, i):
leaf = hash(h + leaf) leaf = hash(h + leaf)
else: else:
leaf = hash(leaf + h) leaf = hash(leaf + h)
return leaf == root return leaf == root
``` ```
#### `concat_generalized_indices`
```python
def concat_generalized_indices(*indices: Sequence[GeneralizedIndex]) -> GeneralizedIndex:
"""
Given generalized indices i1 for A -> B, i2 for B -> C .... i_n for Y -> Z, returns
the generalized index for A -> Z.
"""
o = GeneralizedIndex(1)
for i in indices:
o = o * get_previous_power_of_2(i) + i
return o
```
#### `compute_historical_state_generalized_index` #### `compute_historical_state_generalized_index`
```python ```python