Repository navigation
fix(typedData): reject invalid field types in validateTypedData - #5366
Closed
haybinalim wants to merge 1 commit into
Closed
haybinalim wants to merge 1 commit into
haybinalim wants to merge 1 commit into
Conversation
validateTypedData only matched a field type against the integer and bytes regexes to check its value, so a type that matched neither, such as uint7, uint264, uint08, int0 or bytes0, passed and hashTypedData encoded it as uint256 under a type hash no Solidity struct can produce. A field's base type must now be a struct in types or an EIP-712 atomic or dynamic type.
|
@haybinalim 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: 9245f4f 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 |
Member
|
Closing in favour of #5370. It keeps this PR's commit and adds two fixes: it also checks structs that are only used as array elements (e.g. Generated by Claude Code |
This branch was successfully deployed
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.
Closes #5365
What
validateTypedDataonly matched a field type againstintegerRegex/bytesRegexto range-check its value. A type that matched neither, such asuint7,uint264,uint08,int0,bytes0(or an array of one, likeuint7[]), fell through every check, andhashTypedDatathen encoded the value asuint256(thesize = '256'fallback inencodeAbiParameters) under a type hash likeMessage(uint7 a). No Solidity struct can produce that type hash, so the resulting signature can't be verified on-chain, and auint7field accepted any value up to2^256 - 1.uint7(value1000n)InvalidTypedDataTypeErroruint264,uint08,int0,int7InvalidTypedDataTypeErrorbytes0InvalidTypedDataTypeErrorbytes33Hex size (33) exceeds padding size (32)InvalidTypedDataTypeErroruint7[],uint264[2]InvalidTypedDataTypeErrorPersonwith noPersonintypesInvalidAbiEncodingTypeErrorInvalidTypedDataTypeErrorethers (
invalid numeric width), eth-account (No definition of type `uint7`) and MetaMasketh-sig-utilV4 (Invalid number length, foruint7/uint264/int0) already reject these. viem itself already rejects the same names when they are used as a struct name (validateReference).How
validateTypedData: after the existingint/uintalias check, a field's base type (array suffixes stripped) must be a struct intypesor an EIP-712 atomic/dynamic type:address,bool,string, or a full match ofbytesRegex/integerRegex. Otherwise it throwsInvalidTypedDataTypeError. SincehashTypedDataand thesignTypedDataaction both callvalidateTypedData, they reject these types too.InvalidTypedDataTypeError: theUse "uint256" instead.hint is now only added for theint/uintaliases; foruint7it would have suggested"uint7256".Tests
typedData.test.ts:bytes0,bytes33,int0,int7,uint08,uint7,uint7[],uint264,uint264[2]as field types, and a field that references an undefined struct.hashTypedData.test.ts:uint7andbytes0(inline snapshots).All new tests fail on
mainand pass with this change. Locally I rantypedData.test.ts,hashTypedData.test.ts,recoverTypedDataAddress.test.ts,accounts/utils/signTypedData.test.ts, theprivateKeyToAccount/hdKeyToAccount/mnemonicToAccount/toAccounttests andgetUserOperationTypedData.test.ts(all green), plus Biome andtscon the changed files. Anvil-backed suites and the full typecheck are left to CI.Regressions
Valid typed data is unaffected: every type that passes now is one that already hashed correctly before. The only inputs that change behavior are the invalid ones above, which now fail in
validateTypedDatainstead of being hashed (or failing later with a less specific error). Struct types, including ones only referenced as array elements and recursive ones, are still looked up intypesfirst.Note
Related but out of scope here:
encodeAbiParameters([{ type: 'uint7' }], [1000n])also encodes asuint256because of the same fallback. I kept this PR to typed data; happy to follow up on the ABI encoder if you want that tightened too.AI assistance: I used an AI assistant to help find this through differential testing against ethers, eth-account and MetaMask's eth-sig-util and to draft the change. I reviewed the code, ran the tests and checked the behavior myself.