Fix SSZ merkleisation bug (#602)
This commit is contained in:
parent
41e95cf9ea
commit
9a4f4d5344
|
@ -367,13 +367,16 @@ def merkle_hash(lst):
|
||||||
# Leave large items alone
|
# Leave large items alone
|
||||||
chunkz = lst
|
chunkz = lst
|
||||||
|
|
||||||
# Tree-hash
|
# Merkleise
|
||||||
while len(chunkz) > 1:
|
def next_power_of_2(x):
|
||||||
if len(chunkz) % 2 == 1:
|
return 1 if x == 0 else 2**(x - 1).bit_length()
|
||||||
chunkz.append(b'\x00' * SSZ_CHUNK_SIZE)
|
|
||||||
|
for i in range(len(chunkz), next_power_of_2(len(chunkz))):
|
||||||
|
chunkz.append(b'\x00' * SSZ_CHUNK_SIZE)
|
||||||
|
while len(chunkz) > 1:
|
||||||
chunkz = [hash(chunkz[i] + chunkz[i+1]) for i in range(0, len(chunkz), 2)]
|
chunkz = [hash(chunkz[i] + chunkz[i+1]) for i in range(0, len(chunkz), 2)]
|
||||||
|
|
||||||
# Return hash of root and length data
|
# Return hash of root and data length
|
||||||
return hash(chunkz[0] + datalen)
|
return hash(chunkz[0] + datalen)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue