File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 8
8
import math
9
9
from typing import (
10
10
cast ,
11
- Hashable ,
12
11
Iterable ,
13
12
NewType ,
14
13
Sequence ,
14
+ Union ,
15
15
)
16
16
17
17
from cytoolz import (
@@ -78,7 +78,7 @@ def _calc_parent_hash(left_node: Hash32, right_node: Hash32) -> Hash32:
78
78
79
79
80
80
def verify_merkle_proof (root : Hash32 ,
81
- item : Hashable ,
81
+ item : Union [ bytes , bytearray ] ,
82
82
item_index : int ,
83
83
proof : MerkleProof ) -> bool :
84
84
"""
@@ -108,15 +108,15 @@ def _hash_layer(layer: Sequence[Hash32]) -> Iterable[Hash32]:
108
108
)
109
109
110
110
111
- def calc_merkle_tree (items : Sequence [Hashable ]) -> MerkleTree :
111
+ def calc_merkle_tree (items : Sequence [Union [ bytes , bytearray ] ]) -> MerkleTree :
112
112
"""
113
113
Calculate the Merkle tree corresponding to a list of items.
114
114
"""
115
115
leaves = tuple (hash_eth2 (item ) for item in items )
116
116
return calc_merkle_tree_from_leaves (leaves )
117
117
118
118
119
- def calc_merkle_root (items : Sequence [Hashable ]) -> Hash32 :
119
+ def calc_merkle_root (items : Sequence [Union [ bytes , bytearray ] ]) -> Hash32 :
120
120
"""
121
121
Calculate the Merkle root corresponding to a list of items.
122
122
"""
@@ -133,11 +133,15 @@ def calc_merkle_tree_from_leaves(leaves: Sequence[Hash32]) -> MerkleTree:
133
133
tree = cast (
134
134
MerkleTree ,
135
135
tuple (
136
- take (
137
- n_layers ,
138
- iterate (_hash_layer , leaves ),
136
+ reversed (
137
+ tuple (
138
+ take (
139
+ n_layers ,
140
+ iterate (_hash_layer , leaves ),
141
+ )
142
+ )
139
143
)
140
- )[:: - 1 ]
144
+ )
141
145
)
142
146
if len (tree [0 ]) != 1 :
143
147
raise Exception ("Invariant: There must only be one root" )
Original file line number Diff line number Diff line change 1
1
from typing import (
2
- Hashable ,
2
+ Union ,
3
3
)
4
4
5
5
from eth_typing import Hash32
6
6
from eth_hash .auto import keccak
7
7
8
8
9
- def hash_eth2 (data : Hashable ) -> Hash32 :
9
+ def hash_eth2 (data : Union [ bytes , bytearray ] ) -> Hash32 :
10
10
"""
11
11
Return Keccak-256 hashed result.
12
12
Note: it's a placeholder and we aim to migrate to a S[T/N]ARK-friendly hash function in
You can’t perform that action at this time.
0 commit comments