Skip to content
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

ssz: finish implementation #42

Merged
merged 3 commits into from
Dec 17, 2018
Merged

ssz: finish implementation #42

merged 3 commits into from
Dec 17, 2018

Conversation

arnetheduck
Copy link
Member

  • add object support, simplify implementation
  • fix extra round of hashing in tree_hash_root

* add object support, simplify implementation
* fix extra round of hashing in tree_hash_root
Copy link
Contributor

@mratsim mratsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, apart from the length dummy value comment that I don't understand

# for which toBytesSSZ is defined!
# TODO think about this for a bit - depends where the serialization of
# validator keys ends up going..
SomeInteger | Uint24 | EthAddress | Eth2Digest | ValidatorPubKey |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to split integers from the others as there is this endianness consideration

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, endianess and such type-to-byte conversions are the responsibility of toBytesSSZ - this type union describes the types that are statically sized, basically, and therefore don't need a length prefix in the encoding.

true

func deserialize[T: enum](dest: var T, offset: var int, data: openArray[byte]): bool =
# TODO er, verify the size here, probably an uint64 but...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use case T.sizeof: though to ensure compile-time evaluation the syntax may be awkward.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem here is that sizeof(enum) is undefined in nim - at least I couldn't find a reliable reference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the smallest size needed to store an enum (1 byte if less than 256 values). Note sure how that works with enum with holes though.

On devel it should be more reliable given the merging of nim-lang/Nim#5664 and its extensive test suite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the smallest size needed to store an enum (1 byte if less than 256 values). Note sure how that works with enum with holes though.

where does it say that? also, that kind of implicitness is bad when working with bytes on the wire, easy to mess up.

nim-lang/Nim#5664 is pretty messy - the interplay between the c and nim compilers, and the platform and options passed to the c compiler, is incomplete. it will need a lot more rigor to be usable in a cross-platform setting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right it's not in the manual so it's implementation detail. It works like that for the C and C++ backend unless the {.size: mySizeInBytes.} pragma is added.

beacon_chain/ssz.nim Outdated Show resolved Hide resolved
@mratsim mratsim merged commit 142aa8c into master Dec 17, 2018
@arnetheduck arnetheduck deleted the ssz-refresh branch January 2, 2019 13:05
@arnetheduck arnetheduck mentioned this pull request May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants