Skip to content

fix: preserve leading zeros in ENS Ethereum address fallback - #5436

Closed
mortezashojaei wants to merge 4 commits into
wevm:mainfrom
mortezashojaei:fix/ens-address-leading-zeros
Closed

mortezashojaei wants to merge 4 commits into
wevm:mainfrom
mortezashojaei:fix/ens-address-leading-zeros

Conversation

@mortezashojaei

@mortezashojaei mortezashojaei commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

getEnsAddress trims leading zeros in its address-response compatibility path, then requires 20 bytes. For coinType: 60n, this rejects valid leading-zero Ethereum addresses and throws for the zero address instead of returning null.

coinType: 60n, address response (20 or 32 bytes)
  trim padding
+ restore leading zeros to 20 bytes
  checksum address; return null for the zero address

Reuses pad, declares its error type, and names the address/ABI-word sizes. Other coin types and successful dynamic-bytes decoding keep their existing behavior. Includes a patch changeset describing both corrected behaviors.

Evidence

  • Before: the abi and raw regression rows fail on base source.
    After: all 28 ENS tests pass locally with the normal Anvil harness. Dynamic bytes have a separately named compatibility test. Additional controls cover other coin types, short/oversized data, and dirty padding.
  • pnpm check:types, the full pre-commit Biome check, and git diff --check passed locally.

CI for a41c5a0 completed: 20 jobs passed, four failed, and five core shards were cancelled by fail-fast. CI is not cleared for merge.

Comparison against exact base 9f083800:

  • Build: the same unpublished-package-file errors appear in main and the PR.
  • Tempo: the gateway snapshot failure also occurs in main's T13 and Tnext jobs.
  • Core: the latest nonce-too-low failures remain unresolved. Running the receipt suite on untouched main produced 37 passes and six different failures; that does not establish that the CI nonce failure is unrelated. The previous run's getProof proof-window error was separately reproduced on untouched main.

Merge Danger

Door: two-way

Blast Radius: ENS

The added interpretation is restricted to Ethereum (coinType: 60n). No new API or dependencies.

For coinType: 60n, the address-response path accepts every 32-byte word with a numeric value below 2^160, returning null for zero. This includes words that could instead be incomplete ABI offsets, lengths, or other scalars; the ambiguity is not limited to 0x20. Tests include 0x1, 0x20, and 0x40. Words at or above 2^160 are rejected by this path.

Whether to retain or remove the 32-byte compatibility branch is a maintainer decision. These tests establish decoding behavior, not what live gateways return. Universal malformed-response rejection is not promised.

Prepared with AI assistance; the checks above were run locally.

@vercel

vercel Bot commented Nov 6, 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.

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8eaa99a

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

@mortezashojaei mortezashojaei changed the title fix: preserve leading zeros in ENS address fallback fix: preserve leading zeros in ENS Ethereum address fallback Nov 6, 2026
@erkancamli

Copy link
Copy Markdown
Contributor

I know the description keeps other coin types as they are, so this may be out of scope, but in case it helps: I ran this branch (8eaa99a) with a small offline test: a custom transport that answers eth_call with a resolveWithGateways result, same shape as the new tests. The 60n cases are fixed. ENSIP-11 EVM coin types still fail for the same leading-zero addresses:

coinType 60n                     raw 0x0011…1111 -> 0x0011111111111111111111111111111111111111
coinType toCoinType(8453) (base) raw 0x0011…1111 -> AbiDecodingDataSizeTooSmallError: Data size of 20 bytes is too small for given parameters.
coinType toCoinType(8453) (base) abi 0x0011…1111 -> IntegerOutOfRangeError: Number "380599384721589301615542925186532036368732433n" is not in safe integer range

toCoinType(10) gives the same two errors. The getEnsAddress docs use coinType: toCoinType(base.id) as the example (site/pages/docs/ens/actions/getEnsAddress.md:61). ENSIP-11 says EVM chain addresses use the same 20-byte encoding as coin type 60.

Would it make sense to apply the padding to EVM coin types too? For example, coinType === 60n || (coinType >= 0x80000000n && coinType < 0x100000000n).

jxom commented Nov 8, 2026

Copy link
Copy Markdown
Member

Superseded by #5442, which keeps your commits and extends the fix to ENSIP-11 EVM chain coin types. Thanks @mortezashojaei!

@jxom jxom closed this Nov 8, 2026
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