-
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
[WIP] Spec update #46
Conversation
byte_list is not implemented as a list of bytes due to efficiency concerns.
This makes fixed size/length prefixed sedes superfluous, so those have been removed.
Also, |
7052858
to
441e504
Compare
Implemented tree hashing. Not really convinced that it's correct yet, as tests are still missing. |
size: number of bytes length: number of (first level) elements
I think there's still an error with containers that contain dynamic sized elements:
|
Do you have an example? I tried the following and it seemed to work: In [3]: class Test(ssz.Serializable):
...: fields = (("a", List(uint8)),)
...:
In [4]: ssz.encode(Test([1, 2, 3]))
Out[4]: b'\x07\x00\x00\x00\x03\x00\x00\x00\x01\x02\x03'
In [5]: ssz.decode(Out[4], Test)
Out[5]: <__main__.Test at 0x7fa8fa3007b8> |
Example here: https://github.com/ethereum/bimini/blob/master/tests/test_sss_vs_rlp.py You probably have to manually install some of those dependencies like |
ssz/hash.py
Outdated
@@ -33,18 +33,18 @@ def merkle_hash(input_items: Sequence[Any]) -> Hash32: | |||
data_length = len(input_items).to_bytes(32, "little") | |||
if len(input_items) == 0: | |||
# Handle empty list case | |||
chunks = (b'\x00' * SSZ_CHUNK_SIZE,) | |||
elif len(input_items[0]) < SSZ_CHUNK_SIZE: | |||
chunks = (b'\x00' * CHUNK_SIZE,) |
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.
Use EMPTY_CHUNK
here?
ssz/hash.py
Outdated
@@ -54,7 +54,7 @@ def merkle_hash(input_items: Sequence[Any]) -> Hash32: | |||
# Tree-hash | |||
while len(chunks) > 1: | |||
if len(chunks) % 2 == 1: | |||
chunks += (b'\x00' * SSZ_CHUNK_SIZE, ) | |||
chunks += (b'\x00' * CHUNK_SIZE, ) |
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.
ditto EMPTY_CHUNK
.
ssz/sedes/base.py
Outdated
prefix, content_start_index = self.consume_bytes(data, start_index, SIZE_PREFIX_SIZE) | ||
length = int.from_bytes(prefix, "little") | ||
content, continuation_index = self.consume_bytes(data, content_start_index, length) | ||
return self.deserialize_content(content), continuation_index |
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.
line 173 is identical to line 168, maybe just one return at the end of the function?
Sorry for the delay, only got round to test it now. This takes a while but passes on my machine. The latest relevant commit should be this one: 6f6e3bb Are you sure you're on the latest version? |
This might also relevant ethereum/consensus-specs#794 (review) |
@pipermerriam Found another bug while writing tests, so likely that was the one you encountered as well. Fixed now. |
7b5ffdd
to
6570062
Compare
@jannikluhn I actually built #47 off of your branch. I suspect we have overlapping changes but I made sufficient modifications that they're likely to be heavily obscured or just completely overwritten. Anyways, I think this branch and #47 might need to be merged in some fashion if the SOS+SSZ spec update gets accepted. |
They are slightly more extensive than the other tests as they will likely not be part of the YAML test suite.
This got out of hand a little, sorry for this. Wanted to finish this to finally move on to more important stuff. Most noteworthy changes are the added tests in I also got rid of lots of old tests and cleaned up Some minor fixes in the tree hashing functions (the helpers that contain most of the complexity haven't changed though). Finally, I removed the YAML tests as they are outdated according to the latest spec (no support for uint24, etc.). For some reason, pytest and isort don't work on CircleCI anymore (even though they pass locally). Will look into this tomorrow, but it shouldn't affect the rest of the PR. |
ONce you get everything green I'd advocate for breaking this up into smaller pieces. Largely unreviewable as-is. |
Without them, pytest will fail as we've got test files with the same name in different directories.
As suggested, I'm going to try to split this up into smaller pieces to make it reviewable. Note to self: The tree hashing benchmark fails by a mile. I think (hope) this is because tree hashing of byte lists and vectors works with the bytes individually, but this should be fairly easy to optimize. |
…t-deps Update testing and lint deps
Implement changes in the latest spec update.
Main changes:
LengthPrefixedSedes
andFixedSizedSedes
base classes in favor ofBasicSedes
andCompositeSedes
(note that they don't overlap fully) and update sub classes accordingly.Bytes
andTuple
class.UInts
as they are explicitly not part of the spec anymoreBytesSedes
a list of bytes andBytesN
a tuple of bytes (but with an optimized implementation that doesn't unnecessarily encodes every single byte separately)bytes_sedes
tobyte_list
andBytesN
toByteTuple
What's left to do:
Cute Animal Picture