-
Notifications
You must be signed in to change notification settings - Fork 22
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
v0.8 spec sync #77
v0.8 spec sync #77
Conversation
25037b9
to
a9bd4fe
Compare
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.
Preliminary review, only managed to go through bitlist so far, will continue soon.
ssz/sedes/bitlist.py
Outdated
|
||
class Bitlist(BaseCompositeSedes[BytesOrByteArray, bytes]): | ||
def __init__(self, bit_count: int) -> None: | ||
if bit_count < 0: |
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.
if bit_count < 0: | |
if bit_count < 1: |
as the new spec version now explicitly forbids zero-length vectors..
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.
looks like I was wrong, empty lists (but not vectors) should be fine.
ssz/sedes/bitlist.py
Outdated
if len_value == 0: | ||
return b'\x01' | ||
|
||
as_bytearray = [0] * (len_value // 8 + 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.
is there a reason you aren't actually using a bytearray? I think it will give you some added type/value safety since it won't allow assignment of values outside of the 0-256 range.
as_bytearray = bytearray(len_value // 8 + 1)
Also, won't len_value // 8 + 1
produce arrays with an extra element in the case that len_value
is a clean multiple of 8
?
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.
Right, I should have used bytearray
, thanks!
Also, won't
len_value // 8 + 1
produce arrays with an extra element in the case thatlen_value
is a clean multiple of8
?
It is. https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#bitlistn:
"Note that from the offset coding, the length (in bytes) of the bitlist is known. An additional leading 1 bit is added so that the length in bits will also be known."
ssz/sedes/bitlist.py
Outdated
|
||
class Bitlist(BaseCompositeSedes[BytesOrByteArray, bytes]): | ||
def __init__(self, bit_count: int) -> None: | ||
if bit_count < 0: |
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.
looks like I was wrong, empty lists (but not vectors) should be fine.
Co-Authored-By: jannikluhn <jannik@brainbot.com>
@jannikluhn @pipermerriam @jannikluhn while the minimum length check is pending on the spec side discussion, we can go back to check it later after this PR. |
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.
Probably worth revisiting some parts in the feature for cleanups, but since those wouldn't affect the external API and it would be helpful to get a feeling of the performance requirements first, I think we can merge this now.
@@ -142,20 +153,18 @@ def _deserialize_stream(self, stream: IO[bytes]) -> Iterable[TDeserialized]: | |||
# Tree hashing | |||
# | |||
def hash_tree_root(self, value: Iterable[TSerializable]) -> bytes: |
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 was just thinking about input validation, to prevent people from accidentally hashing inputs that are too big. Don't think it's super necessary though, we can always add this later.
for layer in range(chunk_depth, max_depth): | ||
tmp_list[layer + 1] = hash_eth2(tmp_list[layer] + zerohashes[layer]) | ||
|
||
return tmp_list[max_depth] |
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.
Yes, you're right. In the interest of time I'd be ok with keeping it as it is for now. We might have to revisit the implementation anyway when we're going to implement tree caching.
* convert bash scripts to py
* convert bash scripts to py
What was wrong?
Fix #76
How was it fixed?
merkle_minimal/zerohashes
style Merkleization since withmax_length
, we do needzerohashes
approach for saving computations of a lot of padding.max_length
inList
and addmix_in_length
forList.hash_tree_root()
.Bitvector
andBitlist
:NOTE: Use spec patch Define Bitlist/Bitvector serialization using bytes, not bigints consensus-specs#1267 for
Bitvector
andBitlist
serialization. Should wait for Define Bitlist/Bitvector serialization using bytes, not bigints consensus-specs#1267 getting merged.BeaconState
,BeaconBlock
in pyspec side).Cute Animal Picture