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

Do not use uint in consensus datastructures. #16750

Closed
MicahZoltu opened this issue May 17, 2018 · 5 comments · Fixed by #16784
Closed

Do not use uint in consensus datastructures. #16750

MicahZoltu opened this issue May 17, 2018 · 5 comments · Fixed by #16784

Comments

@MicahZoltu
Copy link
Contributor

https://github.com/ethereum/go-ethereum/blob/master/core/types/receipt.go#L49

https://golang.org/pkg/builtin/#uint

uint is an unsigned integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, uint32.

uint in golang isn't guaranteed to be exactly 32-bits, so it should not be used in a datastructure that needs to be serialized or hashed since future compilers may use uint64 under the hood.

@karalabe
Copy link
Member

It's actually uint64 on amd64 and uint32 on 386. That said, I agree.

@karalabe
Copy link
Member

Hmm, however, all consensus data is encoded into RLP, which truncates any integer to it's minimal size. So uint64(15), will still be serialized as a single byte of 0x0f.

@MicahZoltu
Copy link
Contributor Author

Ah, if the serialization scheme encodes the same number in both uint32 and uint64 to the same encoded byte array then this isn't a big problem. I still recommend being explicit rather than relying on this fact as a style/problem-avoidance scheme, but that is much less critical than I originally thought.

@karalabe
Copy link
Member

I concur that it's generally a good idea to keep protocol fields as strict as possible.

@rjl493456442
Copy link
Member

@MicahZoltu Actually there is a convert function to fill PostStateOrStatus field with receiptStatusFailedRLP = []byte{}, receiptStatusSuccessfulRLP = []byte{0x01} or PostState before the byzantium fork.

But for more strict field definition purpose, i will submit a PR to eliminate misleading.

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 a pull request may close this issue.

3 participants