Skip to content

fix(typedData): reject invalid field types in validateTypedData - #5370

Merged
jxom merged 2 commits into
mainfrom
fix/typed-data-validate-all-field-types
Nov 1, 2026
Merged

jxom merged 2 commits into
mainfrom
fix/typed-data-validate-all-field-types

Conversation

@jxom

@jxom jxom commented Nov 1, 2026

Copy link
Copy Markdown
Member

Supersedes #5366: it keeps that PR's commit and fixes the cases it missed.

validateTypedData (and so hashTypedData and signTypedData) accepted field types that are not EIP-712 types, such as uint7, uint264, uint08, int0 or bytes0, and field types that reference a struct missing from types. It now throws InvalidTypedDataTypeError for them.

What changed compared with #5366:

  • Structs used as array elements are now checked. fix(typedData): reject invalid field types in validateTypedData #5366 checked field types only while walking the message. That walk never enters a struct used through an array type like Person[], so a uint7 or bytes0 field there was still hashed. Every struct's field types are now checked up front, next to the existing struct-name check. Struct names are checked first, so an invalid struct name still throws InvalidStructTypeError.
  • Field types that match built-in object properties are rejected. A field type such as constructor, toString or hasOwnProperty was found on the object prototype and treated as a defined struct, which crashed with a raw TypeError. The lookups now only count keys defined in types itself (Object.hasOwn).
  • The "Use uint256 instead." hint is still shown only for the int/uint aliases. The canonical type is now built only in that case.

Tests added: Person[], Person[][] and Person[2] structs containing bytes0, uint, uint7, uint7[] or an undefined struct, plus the four property-name types, and a hashTypedData snapshot for the array-element case.

Verification: src/utils/typedData.test.ts and src/utils/signature/hashTypedData.test.ts pass (84 tests), and tsc --noEmit -p src/tsconfig.json and Biome are clean on the changed files. I ran the tests with a minimal Vitest config, because the repo's global setup could not start Anvil in my environment. Tests that need the local chain were not run.


Generated by Claude Code

haybinalim and others added 2 commits November 1, 2026 13:03
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.
Field types were only checked while walking the message, so structs only
referenced as array elements (e.g. `Person[]`) were never checked and
`uint7` or `bytes0` fields were still hashed. Validate every struct's
field types up front, and use own-property lookups so field types like
`constructor` or `toString` are rejected instead of crashing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWjRL6So1WQiDdN7nnu
@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d3952ce

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 Nov 1, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
viem Building Building Preview Nov 1, 2026 9:51pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

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-11-01T21:53:42.642286Z d3952ce 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.

@jxom
jxom merged commit 18b6b90 into main Nov 1, 2026
34 of 36 checks passed
@jxom
jxom deleted the fix/typed-data-validate-all-field-types branch November 1, 2026 21:52
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
jxom added a commit to wevm/ox that referenced this pull request Nov 1, 2026
…s, and `AbiItem` (#561)

* fix: validate struct names and field types in `TypedData.assert`

Ports wevm/viem#5308 and wevm/viem#5370. A struct name must contain
only letters, digits, `_` and `$`, and must not be a Solidity type. A
field type must be a struct in `types` or an EIP-712 atomic or dynamic
type, so `uint`, `uint7` and `bytes0` throw the new
`TypedData.InvalidTypeError`. Every struct is checked, including structs
referenced only as array elements. `findTypeDependencies` strips only the
array suffix, so struct names with `$` are encoded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWgFaNg3t1E6VyYCzXq

* fix: reject a tip above a zero `maxFeePerGas` in transaction envelopes

Ports wevm/viem#5318 and wevm/viem#5319. `TxEnvelopeEip1559.assert` and
`TxEnvelopeTempo.assert` compared fees only when both were truthy, so a
zero `maxFeePerGas` skipped the check. `deserialize` for EIP-1559,
EIP-4844, EIP-7702, and Tempo envelopes reads an empty `maxFeePerGas` as
zero when a tip is set. `TipAboveFeeCapError` and `FeeCapTooHighError`
now show zero values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWgFaNg3t1E6VyYCzXq

* fix: treat indistinguishable overloads as ambiguous in `AbiItem.fromAbi`

Ports wevm/viem#5339. Distinct types that both match an argument, such
as `bytes32` and `bytes` or `uint256` and `int256`, and arrays of the
same element type with different shapes now throw
`AbiItem.AmbiguityError` instead of resolving to the last match. An
integer overload matches only a value in its range, and a fixed bytes
overload matches only a value of its size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWgFaNg3t1E6VyYCzXq

---------

Co-authored-by: Claude <[email protected]>
jxom added a commit to wevm/ox that referenced this pull request Nov 1, 2026
…d `AbiItem` (#560)

* fix: validate struct names and field types in `TypedData.assert`

Ports wevm/viem#5308 and wevm/viem#5370. A struct name must contain
only letters, digits, `_` and `$`, and must not be a Solidity type. A
field type must be a struct in `types` or an EIP-712 atomic or dynamic
type, so `uint`, `uint7` and `bytes0` throw the new
`TypedData.InvalidTypeError`. Every struct is checked, including structs
referenced only as array elements. `findTypeDependencies` strips only the
array suffix, so struct names with `$` are encoded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWgFaNg3t1E6VyYCzXq

* fix: reject a tip above a zero `maxFeePerGas` in transaction envelopes

Ports wevm/viem#5318 and wevm/viem#5319. `TxEnvelopeEip1559.assert` and
`TxEnvelopeTempo.assert` compared fees only when both were truthy, so a
zero `maxFeePerGas` skipped the check. `deserialize` for EIP-1559,
EIP-4844, EIP-7702, and Tempo envelopes reads an empty `maxFeePerGas` as
zero when a tip is set. `TipAboveFeeCapError` and `FeeCapTooHighError`
now show zero values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWgFaNg3t1E6VyYCzXq

* fix: treat indistinguishable overloads as ambiguous in `AbiItem.fromAbi`

Ports wevm/viem#5339. Distinct types that both match an argument, such
as `bytes32` and `bytes` or `uint256` and `int256`, and arrays of the
same element type with different shapes now throw
`AbiItem.AmbiguityError` instead of resolving to the last match. An
integer overload matches only a value in its range, and a fixed bytes
overload matches only a value of its size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWgFaNg3t1E6VyYCzXq

---------

Co-authored-by: Claude <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — d3952ce4 Deployed Nov 1, 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