Fix the definition of `GeneralizedIndex`
This commit is contained in:
parent
7409b5ae82
commit
bbaa238742
|
@ -37,7 +37,7 @@ from eth2spec.utils.bls import (
|
|||
from eth2spec.utils.hash_function import hash
|
||||
'''
|
||||
PHASE1_IMPORTS = '''from typing import (
|
||||
Any, Dict, Optional, Set, Sequence, MutableSequence, Tuple, Union,
|
||||
Any, Dict, Optional, Set, Sequence, MutableSequence, NewType, Tuple, Union,
|
||||
)
|
||||
from math import (
|
||||
log2,
|
||||
|
@ -70,6 +70,7 @@ from eth2spec.utils.hash_function import hash
|
|||
|
||||
|
||||
SSZVariableName = str
|
||||
GeneralizedIndex = NewType('GeneralizedIndex', int)
|
||||
'''
|
||||
SUNDRY_CONSTANTS_FUNCTIONS = '''
|
||||
def ceillog2(x: uint64) -> int:
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
- [Merkle proof formats](#merkle-proof-formats)
|
||||
- [Table of contents](#table-of-contents)
|
||||
- [Custom types](#custom-types)
|
||||
- [Helper functions](#helper-functions)
|
||||
- [Generalized Merkle tree index](#generalized-merkle-tree-index)
|
||||
- [SSZ object to index](#ssz-object-to-index)
|
||||
|
@ -22,13 +21,6 @@
|
|||
|
||||
<!-- /TOC -->
|
||||
|
||||
## Custom types
|
||||
|
||||
We define the following Python custom types for type hinting and readability:
|
||||
|
||||
| - | - | - |
|
||||
| `GeneralizedIndex` | `uint64` | the index of a node in a binary Merkle tree |
|
||||
|
||||
## Helper functions
|
||||
|
||||
```python
|
||||
|
@ -75,6 +67,8 @@ def merkle_tree(leaves: Sequence[Hash]) -> Sequence[Hash]:
|
|||
return o
|
||||
```
|
||||
|
||||
We define a custom type `GeneralizedIndex` as a Python integer type in this document. It can be represented as a Bitvector/Bitlist object as well.
|
||||
|
||||
We will define Merkle proofs in terms of generalized indices.
|
||||
|
||||
## SSZ object to index
|
||||
|
@ -175,7 +169,7 @@ def get_generalized_index(typ: SSZType, path: Sequence[Union[int, SSZVariableNam
|
|||
else:
|
||||
pos, _, _ = get_item_position(typ, p)
|
||||
base_index = (GeneralizedIndex(2) if issubclass(typ, (List, Bytes)) else GeneralizedIndex(1))
|
||||
root = root * base_index * get_next_power_of_two(chunk_count(typ)) + pos
|
||||
root = GeneralizedIndex(root * base_index * get_next_power_of_two(chunk_count(typ)) + pos)
|
||||
typ = get_elem_type(typ, p)
|
||||
return root
|
||||
```
|
||||
|
@ -280,8 +274,8 @@ def get_helper_indices(indices: Sequence[GeneralizedIndex]) -> Sequence[Generali
|
|||
return sorted([
|
||||
x for x in all_indices if (
|
||||
not (
|
||||
generalized_index_child(x, GeneralizedIndex(0)) in all_indices and
|
||||
generalized_index_child(x, GeneralizedIndex(1)) in all_indices
|
||||
generalized_index_child(x, False) in all_indices and
|
||||
generalized_index_child(x, True) in all_indices
|
||||
) and not (x in indices)
|
||||
)
|
||||
], reverse=True)
|
||||
|
|
Loading…
Reference in New Issue