mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-13 04:04:19 +00:00
fix typing check, add zero-hash cache to hash function
This commit is contained in:
parent
1157d9b8d8
commit
f4814862fe
@ -1,5 +1,19 @@
|
||||
from hashlib import sha256
|
||||
|
||||
ZERO_BYTES32 = b'\x00' * 32
|
||||
|
||||
def _hash(x):
|
||||
return sha256(x).digest()
|
||||
|
||||
zerohashes = [(None, ZERO_BYTES32)]
|
||||
for layer in range(1, 32):
|
||||
k = zerohashes[layer - 1][1] + zerohashes[layer - 1][1]
|
||||
zerohashes.append((k, _hash(k)))
|
||||
zerohashes = zerohashes[1:]
|
||||
|
||||
|
||||
def hash(x):
|
||||
return sha256(x).digest()
|
||||
for (k, h) in zerohashes:
|
||||
if x == k:
|
||||
return h
|
||||
return _hash(x)
|
||||
|
@ -513,7 +513,7 @@ def read_vector_elem_type(vector_typ: Type[Vector[T, L]]) -> T:
|
||||
|
||||
|
||||
def read_elem_type(typ):
|
||||
if issubclass(typ, bytes): # bytes or bytesN
|
||||
if typ == bytes or (isinstance(typ, type) and issubclass(typ, bytes)): # bytes or bytesN
|
||||
return byte
|
||||
elif is_list_type(typ):
|
||||
return read_list_elem_type(typ)
|
||||
|
Loading…
x
Reference in New Issue
Block a user