Skip to content

fix: left-pad odd-length raw hex in toPrefixedMessage - #5631

Merged
jxom merged 1 commit into
wevm:mainfrom
mortezashojaei:fix/odd-length-raw-message-prefix
Nov 21, 2026
Merged

jxom merged 1 commit into
wevm:mainfrom
mortezashojaei:fix/odd-length-raw-message-prefix

Conversation

@mortezashojaei

@mortezashojaei mortezashojaei commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

toPrefixedMessage now left-pads an odd-length hex raw message to whole bytes before prefixing it, matching hexToBytes and #5466. For example, { raw: '0x123' } now hashes as the EIP-191 message of bytes 0x0123.

Problem

The raw hex was appended to the prefix unpadded. When keccak256 converted the odd-length result to bytes, it left-padded the whole string, which shifted every nibble of the prefix:

toPrefixedMessage({ raw: '0x123' })
// before: hashed bytes 0x01 94 57 46 86 … 0a 32 12 3   (no 0x19 prefix)
// after:  hashed bytes 0x19 45 74 68 65 … 0a 32 01 23   ("\x19Ethereum Signed Message:\n2" ‖ 0x0123)

So signMessage({ message: { raw: '0x123' } }) on a local account signed a hash that is not an EIP-191 message hash, and verifyMessage and recoverMessageAddress disagreed with other implementations for the same input. The ERC-7739 hashMessage and signMessage also use toPrefixedMessage.

Change

  • toPrefixedMessage: left-pad odd-length raw hex strings (0x123 → 0x0123). Even-length strings, Uint8Array, and string messages are unchanged.
  • Tests: the existing toPrefixedMessage default and hashMessage to hex cases gain an odd-length raw assertion. The hashMessage snapshot is the standard EIP-191 hash of 0x0123 (0x849ae777…5751).

Validation

  • pnpm test --project core --run src/utils/signature/ src/accounts/: 191 passed.
  • Both updated cases fail without the source change.
  • Biome is clean, and tsc passes on the touched modules.

@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 264375b

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

@mortezashojaei
mortezashojaei force-pushed the fix/odd-length-raw-message-prefix branch from 974f4fa to 264375b Compare November 21, 2026 18:09
@jxom
jxom merged commit 1cf295c into wevm:main Nov 21, 2026
28 of 35 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 21, 2026
jxom added a commit to wevm/ox that referenced this pull request Nov 28, 2026
…e`, `Hex` and `PersonalMessage` (#729)

- Kept a leading U+FEFF when decoding UTF-8 strings (wevm/viem#5590).
- Rejected a missing static head after a dynamic parameter in AbiParameters.decode (wevm/viem#5572).
- Rejected odd-length hex in PersonalMessage.encode (wevm/viem#5631).
- Added blockAccessListHash and slotNumber to Block (wevm/viem#5674).
- Added baseFeePerBlobGas and blobGasUsedRatio to Fee.FeeHistory (wevm/viem#5635).

Amp-Thread-ID: https://ampcode.com/threads/T-01a21f59-905f-745c-8634-6581aa9f965e

Co-authored-by: Amp <[email protected]>
jxom added a commit to wevm/ox that referenced this pull request Nov 28, 2026
…e`, `Hex` and `PersonalMessage` (#730)

- Kept a leading U+FEFF when decoding UTF-8 strings (wevm/viem#5590).
- Rejected a missing static head after a dynamic parameter in AbiParameters.decode (wevm/viem#5572).
- Rejected odd-length hex in PersonalMessage.encode (wevm/viem#5631).
- Added blockAccessListHash and slotNumber to Block (wevm/viem#5674).
- Added baseFeePerBlobGas and blobGasUsedRatio to Fee.FeeHistory (wevm/viem#5635).

Backport of #729.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21f59-905f-745c-8634-6581aa9f965e

Co-authored-by: Amp <[email protected]>
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