fix: handle odd-length hex in signed hexToBigInt / hexToNumber - #4913
Open
Kropiunig wants to merge 1 commit into
Open
fix: handle odd-length hex in signed hexToBigInt / hexToNumber#4913Kropiunig wants to merge 1 commit into
Kropiunig wants to merge 1 commit into
Conversation
|
@Kropiunig is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 7b8d935 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hexToBigInt(andhexToNumber) withsigned: truecrash on any odd-length hex value:This is the function's own
@example(src/utils/encoding/fromHex.ts:124documents it returning420n). It also hits minimal-encoded JSON-RPC quantities, which are odd-length whenever the leading nibble is dropped (0x0,0xf,0x1a4, ...).Root cause
src/utils/encoding/fromHex.ts:140:For odd-length hex the byte size is fractional (
'0x1a4'→1.5), and the subsequentBigInt(size)throws. The unsigned path is unaffected —sizeis only used to compute the signed two's-complement bound.Fix
Round the byte size up:
An odd-length value is interpreted at its minimal byte width (
0x1a4≙0x01a4, 2 bytes), sohexToBigInt('0x1a4', { signed: true })now returns420nas documented. Even-length inputs take the exact same path as before.Test
Extended the
args: signedtests infromHex.test.tswith odd-length cases (0x0,0xf,0x1a4) for bothhexToBigIntandhexToNumber. They fail onmainwith theRangeErrorabove and pass with the fix.