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

Support big.Int #107

Closed
henridf opened this issue Sep 9, 2022 · 8 comments
Closed

Support big.Int #107

henridf opened this issue Sep 9, 2022 · 8 comments

Comments

@henridf
Copy link

henridf commented Sep 9, 2022

It would be handy to have built-in support for big.Int (along the lines of the time.Time support added in #100).

(This is motivated by ssz-encoding geth block headers).

Would you be open to a PR doing this? If so i'll put one up.

@mcdee
Copy link
Contributor

mcdee commented Sep 9, 2022

What would the underlying ssz type be, and how would it be represented? Would you use a uintN with an ssz-size tag to define it? And what would happen in the case of overflow?

@henridf
Copy link
Author

henridf commented Sep 9, 2022

I would probably use (*big.Int).FillBytes, like in https://github.com/henridf/eip44s-proto/blob/ca23838c532de78a279b09772286a8a443a58d08/spec/spec.go#L80.

Overflow would have to be an encoding error.

@mcdee
Copy link
Contributor

mcdee commented Sep 9, 2022

To expand upon my first question: SSZ defines a clear set of types (basic and composite) at https://github.com/ethereum/consensus-specs/blob/dev/ssz/simple-serialize.md#basic-types so what type is big.Int representing?

big.Int should represent a type that is known in the SSZ spec, and then this library can handle the encoding and decoding of said type. Without a proper type representation in the SSZ spec it won't result in an interoperable binary format.

Is this perhaps a uint256 type?

@henridf
Copy link
Author

henridf commented Sep 9, 2022 via email

@henridf
Copy link
Author

henridf commented Sep 9, 2022

@ferranbt
Copy link
Owner

I concur with @mcdee, we need to comply with the ssz spec, and as of now, the ssz spec does not define how a big.Int is encoded. That is something we would need to clarify first with the eth2 team (not sure in which platform) before moving ahead to avoid future compatibility issues.

Even more, there should be an agreement on how the Header itself (with Bodies and Receipts) gets encoded in ssz format (i.e. does the Number is the Header gets encoded as big.Int or uint64?) which is a side topic of this issue. Otherwise, I see a lot of edge cases being implemented in the generator to cover everything.

@henridf
Copy link
Author

henridf commented Sep 20, 2022

@ferranbt makes sense. Thinking a little more, I'm not sure SSZ needs or wants to define explicitly define arbitrary-size ints as a basic type, given the availability of uintNN and vectors.

@henridf henridf closed this as completed Sep 20, 2022
@lightclient
Copy link

@ferranbt could we have big.Int be specified with an annotation like ssz-size or ssz-uint and error if the value is outside the range?

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

No branches or pull requests

4 participants