-
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
Proposal: generic uint_to_bytes
#1935
Conversation
Rename `bytes_to_int` to `bytes_to_uint64` Use `encode_bytes` to implement `int_to_bytes` Rename `int_to_bytes` to `uint_to_bytes` and move it to `ssz_impl.py`
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.
I like this approach
specs/phase0/beacon-chain.md
Outdated
source = hash(seed + int_to_bytes(current_round, length=1) + int_to_bytes(position // 256, length=4)) | ||
source = hash( | ||
seed | ||
+ uint_to_bytes(current_round) |
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.
Doing an explicit cast to uint8 right here might result in better readability and fewer client errors
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.
mainly because current_round
being 8-bit is an exception to our general 64-bit rule and easy to overlook
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.
open to other's thoughts on this
Please review the |
Co-authored-by: Alex Vlasov <avv49@mail.ru>
Issue
An alternative to #1746
int_to_bytes
andcompute_shuffled_index
part.int_to_bytes
expectsuint64
as the input. But actually we were passing Pythonint
to it in some cases.Proposed solution
int_to_bytes
touint_to_bytes
and enforce the input ofuint_to_bytes
to be SSZuint
type.uint
object by its length in bytes. i.e., encodeuint8
to 1-byte output anduint64
to 8-byte output.uint_to_bytes
in prose instead of in code. Similar tohash_tree_root
.bytes_to_int
tobytes_to_uint64
.Note: It's a refactoring change of the current spec and it should not change the consensus logic.