Skip to content

Fix isHash accepting odd-length hex strings - #5042

Merged
jxom merged 1 commit into
wevm:mainfrom
Wagalidoom:fix/isHash
Sep 1, 2026
Merged

Fix isHash accepting odd-length hex strings#5042
jxom merged 1 commit into
wevm:mainfrom
Wagalidoom:fix/isHash

Conversation

@Wagalidoom

Copy link
Copy Markdown
Contributor

isHash returns true for hex strings of 65 characters, one short of a valid
32-byte hash. The most common way to produce one is truncating a real hash by a
single character, so the false positive lands exactly where validation matters.

isHash('0x' + 'a'.repeat(63)) // true — expected false

Cause

isHash is isHex(hash) && size(hash) === 32. isHex in strict mode accepts an
odd number of nibbles, and size rounds up: Math.ceil(63 / 2) === 32. So 63
nibbles report as 32 bytes and pass the check.

Impact

Validation passes client-side and the value fails later, further down the stack.
A node rejects it with -32602 invalid params, so the error surfaces from inside
a query or a receipt wait rather than at the input boundary. For comparison,
ethers rejects the same string: isHexString(value, 32) returns false and
getBytes throws.

Note
The same pattern (size(value) === N used as a validator on untrusted input) appears at several other call sites.

@changeset-bot

changeset-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c5a192

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

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

@vercel

vercel Bot commented Aug 24, 2026

Copy link
Copy Markdown

@Wagalidoom is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@Wagalidoom Wagalidoom changed the title fix: isHash returning true for a 63-character string Fix isHash accepting odd-length hex strings Aug 24, 2026
@jxom
jxom merged commit 5df9819 into wevm:main Sep 1, 2026
2 of 3 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 1, 2026
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 this pull request may close these issues.

2 participants