Repository navigation
Fix normalizeSignature dropping the parameter after ( - #5201
Merged
Merged
Conversation
…llowing `(` Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@ara-stock 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: c94c054 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](https://github.com/ara-stock/viem/new/fix/normalize-signature-leading-space?filename=.changeset/ready-experts-stick.md&value=---%0A%22viem%22%3A%20patch%0A---%0A%0AFix%20%60normalizeSignature%60%20dropping%20the%20parameter%20after%20%60(%20%60%0A) |
This was referenced Oct 11, 2026
Merged
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.
normalizeSignature(used bytoSignature,toFunctionSelector,toEventSelector,toFunctionHash,toEventHash) silently drops the first parameter of a list when a space directly follows the opening parenthesis. The result is a valid-looking but wrong selector/topic, with no error.Other examples (released viem 2.57.3 → expected, expected computed with ethers v6
FunctionFragment.from(s).format('sighash')):function foo( uint256 a )foo()foo(uint256)foo( uint256 a, address b)foo(,address)foo(uint256,address)function foo(( uint256 a, bool b) c)foo((,bool))foo((uint256,bool))function foo( ( uint256 a, bool b)[] c)foo((,bool)[])foo((uint256,bool)[])Cause: a space inside the parameter list deactivates the parser (to skip the parameter name /
indexed/ data location) unless it follows a separator. The check only recognised,,current === ','andcurrent === ',(', so a space after(at the start of a list (or after(() was treated as the end of a type, and everything up to the next separator was skipped. The existingtrim spacestest passed only because its( uint104 ...tuple follows a,.Fix: treat a space as leading whitespace whenever the current section ends with
(or,(this subsumes the three existing conditions), otherwise deactivate as before.Alternatives considered: routing string inputs through abitype's
parseAbiItemwould also fix it, but changes whattoSignatureaccepts (e.g. barefoo(uint256)without afunctionkeyword), so I kept the change local to the existing parser.Tests:
normalizeSignature.test.ts,toFunctionSelector.test.tsandtoEventSelector.test.ts. With the fix reverted, these 3 tests fail; with the fix they pass.vitest run src/utils/hash/(Node 24,SKIP_GLOBAL_SETUP=true): 41 passed. The one remaining failure,error: invalid signatures, is an inline snapshot that expects[email protected]and receives[email protected]because the global setup was skipped; it fails the same way onmainin this setup.biome checkon the four changed files: clean.(,,and), compared with ethers v6format('sighash'): 2,108 mismatches with viem 2.57.3, 0 with this change.Changeset added (
patch).I used an AI assistant while preparing this; I reproduced the bug and ran the tests myself.
🤖 Generated with Claude Code