Skip to content

fix: reject fixed-length typed data arrays with the wrong length - #5556

Merged
jxom merged 1 commit into
mainfrom
fix/typed-data-fixed-array-length
Nov 18, 2026
Merged

jxom merged 1 commit into
mainfrom
fix/typed-data-fixed-array-length

Conversation

@jxom

@jxom jxom commented Nov 17, 2026

Copy link
Copy Markdown
Member

Supersedes #5555 by @erkancamli, whose tests are kept here (credited as co-author).

When an EIP-712 type declares a fixed-length array such as uint256[2], a value with a different number of elements was hashed anyway, giving a digest that no verifier for that type produces. validateTypedData now checks the declared length in every dimension (including uint256[2][] and Person[2]) and inside struct arrays, and throws AbiEncodingArrayLengthMismatchError.

The check lives in validateTypedData rather than in hashTypedData's encoder, so every path agrees: hashTypedData, local and JSON-RPC signTypedData, verifyTypedData and recoverTypedDataAddress. With the check only in the encoder (#5555), a JSON-RPC account still forwarded the message to the wallet, while a local account threw and verifying the wallet's signature threw.

Dynamic arrays and correctly sized fixed arrays hash exactly as before. Since validateData now runs on structs inside arrays, their fields also get the existing address, integer and bytes checks.

Agreement with other implementations

Case Before After ethers 6.17 ox 1.8.16 ox 0.14.67 / eth-sig-util V4
uint256[3] with 3 items, uint256[2][3] 3×2, Person[2] with 2 hash same hash same hash same hash same hash
uint256[3] with 2 or 4 items hash throws throws throws hash
uint256[2][3], outer or inner length wrong hash throws throws throws hash
Person[2] with 1 or 3 structs, or a wrong uint256[2] field inside hash throws throws throws hash
uint256[] (0, 1, 5 items), ragged uint256[][] hash same hash same hash same hash same hash
bytes32[1] with 0 items hash throws throws throws hash

ox added this check in 1.0.0. eth-sig-util (MetaMask) still hashes wrong-length values, but no contract can verify those signatures, because Solidity encodes exactly n elements for T[n].

Tests

hashTypedData, validateTypedData (a wrong length inside a struct array) and wallet signTypedData with a JSON-RPC account. All 5 new tests fail without the fix.

validateTypedData now checks the declared length of fixed-length array
fields in every dimension and inside struct arrays, so hashTypedData,
local and JSON-RPC signTypedData, verifyTypedData and
recoverTypedDataAddress all reject the value instead of hashing or
forwarding an encoding no verifier for that type produces.

Co-authored-by: ecamli <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1ea85-1cf1-779a-8d5c-06d0c603a194
Co-authored-by: jxom <[email protected]>
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
viem Error Error Nov 17, 2026 9:13pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f1e50ce

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

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T21:10:26.802035Z f1e50ce 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.

@github-actions

Copy link
Copy Markdown
Contributor

Published [email protected] under the pr-5556 dist-tag, which follows this pull request until it closes.

pnpm add viem@pr-5556
pnpm add [email protected]

@jxom
jxom merged commit 4febd22 into main Nov 18, 2026
36 of 38 checks passed
@jxom
jxom deleted the fix/typed-data-fixed-array-length branch November 18, 2026 04:37
@github-actions github-actions Bot mentioned this pull request Nov 18, 2026

This branch had an error being deployed

1 failed deployment
Preview — f1e50ce5 Deployed Nov 17, 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