Skip to content

fix: reject compressed public keys in publicKeyToAddress - #5515

Merged
jxom merged 2 commits into
mainfrom
fix/public-key-to-address-compressed
Nov 15, 2026
Merged

jxom merged 2 commits into
mainfrom
fix/public-key-to-address-compressed

Conversation

@jxom

@jxom jxom commented Nov 15, 2026

Copy link
Copy Markdown
Member

Supersedes #5509 by @erkancamli; their commit is kept as is.

publicKeyToAddress dropped the first byte of the public key and hashed the rest, so a compressed public key (33 bytes) hashed only its x-coordinate and returned an address no key controls, without an error. A 64-byte raw key and other lengths also returned wrong addresses.

It now throws InvalidPublicKeyError unless the key is uncompressed (65 bytes with a 0x04 prefix), matching ox's Address.fromPublicKey, which also rejects compressed keys. Every internal caller (privateKeyToAccount, privateKeyToAddress, recoverAddress) already passes uncompressed keys.

On top of #5509:

  • the error's name uses the namespaced form, publicKeyToAddress.InvalidPublicKeyError;
  • the changeset is one sentence.

The import * from 'viem' (esm) size limit goes from 91.5 kB to 92 kB: main measured 91,488 B, 12 B under the old limit, and this change adds about 130 B.

erkancamli and others added 2 commits November 15, 2026 04:59
`publicKeyToAddress` dropped the first byte of the public key and hashed
the rest, so a compressed public key (33 bytes, as `secp256k1.getPublicKey`
returns by default and BIP-32 extended keys carry) hashed only the
x-coordinate and returned an address no key controls, without an error.

The address is derived from both coordinates, so the public key must be
uncompressed (65 bytes with a `0x04` prefix); anything else now throws
`InvalidPublicKeyError`, as ox's `Address.fromPublicKey` rejects
compressed public keys.

The new error pushes `import * from 'viem' (esm)` just over its budget,
so that limit goes from 91.5 kB to 92 kB.

Co-authored-by: jxom <[email protected]>
Errors colocated with the code that throws them use the namespaced form,
and the changeset is one sentence.

Co-authored-by: jxom <[email protected]>
@vercel

vercel Bot commented Nov 15, 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 15, 2026 5:05am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 19a1e6f

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 15, 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-15T05:03:51.077238Z 19a1e6f 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-5515 dist-tag, which follows this pull request until it closes.

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

@jxom
jxom merged commit fb1687a into main Nov 15, 2026
36 of 38 checks passed
@jxom
jxom deleted the fix/public-key-to-address-compressed branch November 15, 2026 05:18
@github-actions github-actions Bot mentioned this pull request Nov 15, 2026

This branch had an error being deployed

1 failed deployment
Preview — 19a1e6ff Deployed Nov 15, 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.

3 participants