Skip to content

fix(typedData): validate struct names in validateTypedData - #5308

Merged
jxom merged 1 commit into
mainfrom
jxom/adoring-turing-50lfxc
Oct 26, 2026
Merged

jxom merged 1 commit into
mainfrom
jxom/adoring-turing-50lfxc

Conversation

@jxom

@jxom jxom commented Oct 26, 2026

Copy link
Copy Markdown
Member

Supersedes #5305.

validateTypedData rejected every struct name that starts with int, uint or bytes, so a valid struct such as intent or bytesInfo made hashTypedData throw. #5305 matched the whole name against the integer and bytes regexes instead. That change also accepted names that the prefix check rejected, such as uint256[], and reopened #2888 with a hash collision:

hashTypedData({
  domain: { name: 'D', chainId: 1 },
  types: {
    Message: [{ name: 'a', type: 'uint256[]' }],
    'uint256[]': [{ name: 'x', type: 'uint256' }],
  },
  primaryType: 'Message',
  message: { a: { x: 1n } },
})
// With #5305: 0x40a5571c…c4e1. This is also the hash of the real
// `uint256[]` message `a: [keccak256('uint256[](uint256 x)'), 1n]`.

validateTypedData now validates every key of types once, before it validates the message. A struct name must contain only letters, digits, _ and $. It must not be address, bool, string, or int, uint or bytes followed only by digits. findTypeDependencies now strips only the array suffix, as validateTypedData does, so a struct name that contains $ is included in the encoded type.

Struct name Before After
intent, bytesInfo, uintPair Rejected Accepted
Foo$Bar Accepted, with Foo$Bar left out of the encoded type Accepted, with the same hash as ethers
Foo.Bar Accepted, with Foo.Bar left out of the encoded type Rejected
uint256[], uint7, uint256 Rejected Rejected
bytes32, referenced only as bytes32[] Accepted, with the bytes32 values left out of the hash Rejected

Points for review:

  • Keys of types that no field references are now validated too. Typed data with an unused key such as uint256 now throws. ethers rejects unused types entirely.
  • The uint7 and bytes33 names are rejected even though they are not valid Solidity types, since ethers fails on them with "invalid numeric width" or "invalid bytes width".
  • ox's TypedData.validateReference and findTypeDependencies have the same logic as before this change, so ox needs the same fix.

Validation: pnpm test --run --project core src/utils/typedData.test.ts src/utils/signature/hashTypedData.test.ts passes (62 tests), and 13 of them fail on main. The intent, bytesInfo, interval, uintPair, Foo$Bar and intent[] hashes match ethers 6.13.4. The ERC-7739 suites need Anvil and the contracts build, so they run only in CI.


Generated by Claude Code

`validateTypedData` validates every key of `types` once. A struct name
must contain only letters, digits, `_` and `$`, and must not be
`address`, `bool`, `string`, or `int`, `uint` or `bytes` followed only
by digits. Struct names such as `intent` and `bytesInfo` are accepted,
and names such as `uint256[]`, `uint7` and `bytes32` are rejected, also
when a field references them only as array elements.

`findTypeDependencies` strips only the array suffix of a field type, so
the encoded type includes struct names that contain `$`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bm5cqLUPRzJwRDAciDwTss
@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 Building Building Preview Oct 26, 2026 10:00am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9e803db

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

@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 🔄 Running since 2026-10-26T10:00:10.124000Z 9e803db 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 71636a3 into main Oct 26, 2026
34 of 36 checks passed
@jxom
jxom deleted the jxom/adoring-turing-50lfxc branch October 26, 2026 10:00
@github-actions github-actions Bot mentioned this pull request Oct 26, 2026
jxom pushed a commit that referenced this pull request Oct 26, 2026
Struct name validation in `validateTypedData` (#5308) raised the `viem`
(esm) bundle to 88.02 kB, 20 B over its limit. The limit is 1 kB higher.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011rqkaz4bQxmMPuJJUx2aCi
jxom added a commit that referenced this pull request Oct 26, 2026
Struct name validation in `validateTypedData` (#5308) raised the `viem`
(esm) bundle to 88.02 kB, 20 B over its limit. The limit is 1 kB higher.


Claude-Session: https://claude.ai/code/session_011rqkaz4bQxmMPuJJUx2aCi

Co-authored-by: Claude <[email protected]>
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 — 9e803db0 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.

2 participants