-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree hash functions for SSZ #54
Comments
Very minor, but I suspect Update: I was expecting |
Fixed both! Merkle root accidentally returned the entire tree. |
In |
Did an evaluation in Java. def merkle_root(objs):
min_pow_of_2 = 1
# while min_pow_of_2 <= len(objs):
while min_pow_of_2 < len(objs):
min_pow_of_2 *= 2
# o = [0] * min_pow_of_2 + [len(objs).to_bytes(32, 'big')] + objs + [b'\x00'*32] * (min_pow_of_2 - len(objs))
o = [len(objs).to_bytes(32, 'big')] + [0] * (min_pow_of_2 - 1) + objs + [b'\x00'*32] * (min_pow_of_2 - len(objs))
for i in range(min_pow_of_2 - 1, 0, -1):
o[i] = hash(o[i*2] + o[i*2+1])
# return o[1]
return o[0] But original algorithm with @sorpaas's correction looks good to me either. |
I made a modified algorithm that has some efficiency improvements: |
The following is a general-purpose strategy for making all data structures in the beacon chain more light client friendly. When (i) hashing the beacon chain active state, (ii) hashing the beacon chain crystallized state, or (iii) hashing beacon chain blocks, we instead use the following hash function specific to SSZ objects, where
hash(x)
is some underlying hash function with a 32-byte output (eg.blake(x)[0:32]
)Where
merkle_root
is defined as follows:Collision resistance is only guaranteed between objects of the same type, not objects of different types.
Efficiency
Fundamentally, Merkle-hashing instead of regular hashing doubles the amount of data hashes, but because hash functions have fixed costs the overhead is higher. Here are some simulation results, using 111-byte objects for accounts because this is currently roughly the size of a beacon chain ValidatorRecord object:
The text was updated successfully, but these errors were encountered: