-
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
Bigint and bitfield-as-integer #1096
Conversation
Adds bigint and bitfield support to SSZ. Possible alternative definition for `Bitfield`: ``` o = [0] * (len(value)//8 + 1) for i in range(len(value)): o[i//8] ^= value[i] << (i%8) o[len(value)//8] ^= 1 << (len(value) % 8) return bytes(o) ```
Is there a good reason for why we want to support Bigints? Otherwise I would tend to favour the alternative definition over introducing Bigints just for defining Bitfields. While the definition is more elegant with Bigints, I think in reality all implementations will use this. |
If we want to use SSZ as an ABI later on, then there will definitely be use cases for bigints, so there's arguably a reason to have them in there. But you're right, it's not necessary for consensus layer. |
I think it makes sense to add this, we've already opted for union types on similar grounds. Also, I quite like the "Bitfield as Bigint" definition because where it will come very natural is in MPCs where it is very natural to operate on Bitfields in this way. |
Another argument for the bigint types was to be able to handle deeper SSZ objects in generalized merkle indices ( #842 (comment)) |
Oh, and this request would basically only support variable size Bitfields, right? Some of the potential applications in the spec seem to be fixed size, should we add support for this too? |
This looks good. We should modify the |
As per our discussion yesterday, added a fixed length Bitfield. Not really sure about the notation I'm using; some alternatives:
|
Now that #1077 is merged and we have My recommendation would be to not push it to the SSZ layer. And instead, just implement the data types as subclasses of Edit: not sure about the big-int usage, but understand consistent formatting/hashing of big-ints (no leading zero bytes) is important for consensus. So that may need to be addressed in SSZ. If we're going that route, it may be better to wrap bitlist and bitvector around that type, instead of bytes/BytesN. |
Just a quick nitpick: the code is full of off-by-1 errors (missing the partially used byte). E.g. |
@dankrad Can we close this in favor of your coming PR? |
Yes, please :) |
Adds bigint and bitfield support to SSZ.
Possible alternative definition for
Bitfield
: