Skip to content

fix: strip error keyword in normalizeSignature - #5300

Merged
jxom merged 2 commits into
mainfrom
fix/normalize-signature-error
Oct 26, 2026
Merged

jxom merged 2 commits into
mainfrom
fix/normalize-signature-error

Conversation

@jxom

@jxom jxom commented Oct 26, 2026

Copy link
Copy Markdown
Member

Supersedes #5290 and keeps @wavebyrd's original commit and changeset.

normalizeSignature drops a leading function or event keyword but kept error, so string error signatures hashed with the keyword included and gave the wrong selector:

toFunctionSelector('error Unauthorized(address)') // before: 0x83d39bf3, after: 0x8e4a23d6
toFunctionSelector('error Error(string)')         // before: 0x7563ad2f, after: 0x08c379a0

The fix adds error to the keywords it drops, the same as ox. As with function and event, it only matches when the whole top-level prefix is exactly error. So function f(uint256 error), function error(), event Error(string), errors Foo() and errorCode Foo() normalize the same as before.

On top of the original commit:

  • Added a toFunctionSelector test for error-prefixed signatures, including Error(string) and Panic(uint256). It fails without the fix.
  • Updated the toSignature and toSignatureHash TSDoc to mention error definitions.

Viem's own error encoding and decoding (encodeErrorResult, decodeErrorResult, getAbiItem) builds signatures with its internal formatAbiItem, which never adds the keyword, so only user-supplied strings change.


Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bc833a1

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 Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Ready Ready Preview Oct 26, 2026 5:15am UTC

Request Review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T05:13:01.225298Z bc833a1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/viem@5300

commit: bc833a1

This branch was successfully deployed

1 active deployment
Preview — bc833a1d Deployed Oct 26, 2026 by vercel[bot]
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.

3 participants