Skip to content

fix: treat indistinguishable ABI overloads as ambiguous - #5339

Merged
jxom merged 3 commits into
wevm:mainfrom
mortezashojaei:fix/abi-item-indistinguishable-overloads
Nov 1, 2026
Merged

jxom merged 3 commits into
wevm:mainfrom
mortezashojaei:fix/abi-item-indistinguishable-overloads

Conversation

@mortezashojaei

@mortezashojaei mortezashojaei commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

 getAmbiguousTypes(source, target, args)
   if address vs bytes20
     throw
   if address vs string|bytes and value looks like an address
     throw
+  if the two ABI types differ
+    throw
   last matching overload wins

getAbiItem already throws AbiItemAmbiguityError for address/bytes20. Other overloads that both accept the same JavaScript value still last-wins by ABI order. That encodes the wrong selector.

The Safe/ERC-1271 case is the sharp one: isValidSignature(bytes32,bytes) vs isValidSignature(bytes,bytes) with a 32-byte hash currently encodes 0x20c13b0b instead of 0x1626ba7e. The same last-wins flip happens for uint256/int256 if the ABI array is reversed.

This also closes the gap reported in #1799.

Evidence

  • Before: encodeFunctionData with both isValidSignature overloads returned selector 0x20c13b0b (legacy bytes,bytes). getAbiItem({ args: [1n] }) for foo(uint256) / foo(int256) returned whichever overload was last in the ABI.
  • After: both cases throw AbiItemAmbiguityError. A unique ERC-1271 ABI still encodes 0x1626ba7e. Existing address/string/bytes helper cases that are not actually addresses stay non-ambiguous.
SKIP_GLOBAL_SETUP=true pnpm test --run --project core \
  src/utils/abi/getAbiItem.test.ts \
  src/utils/abi/encodeFunctionData.test.ts \
  src/utils/abi/decodeFunctionResult.test.ts \
  src/utils/abi/prepareEncodeFunctionData.test.ts \
  src/utils/abi/encodeErrorResult.test.ts

92 tests passed.

Test plan

  • getAbiItem throws for bytes vs bytes32 (isValidSignature)
  • getAbiItem throws for uint256 vs int256
  • encodeFunctionData still encodes ERC-1271 when only bytes32,bytes is on the ABI
  • Nested address/bytes20 ambiguity tests still pass
  • Callers can disambiguate with a 4-byte functionName selector

Merge Danger

Door: two-way

Patch-level behavior change: previously silent last-wins now throws. Rollback is a revert. Callers who relied on ABI JSON order to pick bytes vs bytes32 (or uint vs int) need to pass a selector or trim the ABI. That is the same workaround already documented in discussion 1799.

Blast Radius: encoding

Wrong-selector calls become explicit errors. Unique overloads (mint(uint256) vs mint(string)) are unchanged.

Last-wins encoding could call the wrong function for bytes vs bytes32
and uint vs int overloads, including Safe ERC-1271 isValidSignature.
@changeset-bot

changeset-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 473484f

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 Oct 28, 2026

Copy link
Copy Markdown

@mortezashojaei is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

mortezashojaei and others added 2 commits October 28, 2026 21:04
Array overloads such as uint256[] and uint256[2] encode differently even when they accept the same value, so getAbiItem now throws instead of keeping the last match. The ambiguity error also says a selector can choose the overload.
@jxom
jxom merged commit a864b86 into wevm:main Nov 1, 2026
28 of 36 checks passed
@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]>
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