-
Notifications
You must be signed in to change notification settings - Fork 146
Conversation
ethereum/consensus-specs#483 is merged. 🎉 |
) | ||
|
||
|
||
def int_to_bytes32(value: Union[int, bool]) -> Hash32: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that this should be value: int
since the next line explicitely disallows bools.
|
||
def get_highest_bit_index(value: int) -> int: | ||
value >>= 1 | ||
for bit_length in itertools.count(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set a reasonable upper bound on this loop?
Bound the given ``value`` between ``inclusive_lower_bound`` and | ||
``inclusive_upper_bound``. | ||
""" | ||
if value <= inclusive_lower_bound: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how performance critical this is, but maybe it's better to optimize the common case? Assuming the common case is that the value is within range then maybe start this with:
if inclusive_lower_bound <= value <= inclusive_upper_bound:
return value
elif value <= ...:
...
elif value >= ...:
...
else:
raise Exception("Unreachable")
|
||
x = value | ||
y = (x + 1) // 2 | ||
while y < x: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we worked up a faster version of this using a combination of decimal.Decimal
and logarithms.
) | ||
c = b'' | ||
for i in range(32): | ||
c += bytes([a[i] ^ b[i]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, we had a better version of this in some other PR.
if repeats == 0: | ||
return Hash32(data) | ||
else: | ||
return repeat_hash_eth2(bytes(hash_eth2(data)), repeats - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a non-recursive version of this using cytoolz.pipe
and itertools.repeat(hash_eth, iterations)
Replaced by #252 |
This is a copy of ethereum/py-evm#1686 by @prateekreddy that I only rebased to Trinity.
Note that merging it right now is not a good idea as there are still unaddressed comments and it soon needs to be updated anyways once ethereum/consensus-specs#483 is merged.
What was wrong?
Implement
validate_randao
as per Eth 2.0 spec https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#randaoCute Animal Picture