Repository navigation
fix: reject fixed-length typed data arrays with the wrong length - #5556
Merged
Merged
Conversation
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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: f1e50ce 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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
|
Published pnpm add viem@pr-5556
pnpm add [email protected] |
Merged
This branch had an error being 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.
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.validateTypedDatanow checks the declared length in every dimension (includinguint256[2][]andPerson[2]) and inside struct arrays, and throwsAbiEncodingArrayLengthMismatchError.The check lives in
validateTypedDatarather than inhashTypedData's encoder, so every path agrees:hashTypedData, local and JSON-RPCsignTypedData,verifyTypedDataandrecoverTypedDataAddress. 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
validateDatanow runs on structs inside arrays, their fields also get the existing address, integer and bytes checks.Agreement with other implementations
uint256[3]with 3 items,uint256[2][3]3×2,Person[2]with 2uint256[3]with 2 or 4 itemsuint256[2][3], outer or inner length wrongPerson[2]with 1 or 3 structs, or a wronguint256[2]field insideuint256[](0, 1, 5 items), raggeduint256[][]bytes32[1]with 0 itemsox 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
nelements forT[n].Tests
hashTypedData,validateTypedData(a wrong length inside a struct array) and walletsignTypedDatawith a JSON-RPC account. All 5 new tests fail without the fix.