-
Notifications
You must be signed in to change notification settings - Fork 138
[ZkTracer] fix conversion bytes to int/long #2375
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,7 +109,7 @@ public static Bytes booleanToBytes(boolean x) { | |
| public static long bytesToLong(final Bytes input) { | ||
| final Bytes trimmedBytes = input.trimLeadingZeros(); | ||
| checkArgument(trimmedBytes.size() <= 8, "Input bytes must be at most 8 bytes long"); | ||
| return trimmedBytes.toLong(); | ||
| return trimmedBytes.toUnsignedBigInteger().longValueExact(); | ||
| } | ||
|
|
||
| public static short bytesToShort(final Bytes input) { | ||
|
|
@@ -134,7 +134,9 @@ public static String bytesToHex(byte[] bytes) { | |
| } | ||
|
|
||
| public static int bytesToInt(Bytes bytes) { | ||
| return bytes.trimLeadingZeros().toInt(); | ||
| final Bytes trimmedBytes = bytes.trimLeadingZeros(); | ||
| checkArgument(trimmedBytes.size() <= 4, "Input bytes must be at most 4 bytes long"); | ||
| return Math.toIntExact(bytes.trimLeadingZeros().toLong()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant
|
||
| } | ||
|
|
||
| /** | ||
|
|
||


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 solved the same issue I think on the 7702 HUB PR by letting
LEAD_DELEGATION_BYTESbe a long rather than an int. Probably best to use the same approach in both PR's.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.
it could work as well. But the issue is that this functiun can be called elsewhere and has to be fixed anyway. And once it's fixed, there is no need to have the leading bytes as long, as it's an (unsigned) int. Or the best would be to have leadingBytes a Bytes of length 4 ...