Repository navigation
fix: reject compressed public keys in publicKeyToAddress - #5509
Closed
erkancamli wants to merge 1 commit into
Closed
erkancamli wants to merge 1 commit into
erkancamli wants to merge 1 commit into
Conversation
`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.
|
@erkancamli is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 654026c 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 |
Member
|
Thanks @erkancamli! Superseded by #5515, which keeps your commit and adds a small follow-up (namespaced error name, one-sentence changeset). |
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.
publicKeyToAddressdrops the first byte of the key and hashes the rest. For a compressed public key (33 bytes, whichsecp256k1.getPublicKeyreturns by default and BIP-32 extended keys carry) that hashes only the x-coordinate, and it returns an address no key controls, with no error:ox rejects compressed keys in
Address.fromPublicKey(wevm/ox#624). This does the same: anything other than an uncompressed key (65 bytes with the0x04prefix) throws the newInvalidPublicKeyError, exported next topublicKeyToAddressfromviem/accountsandviem/utilsand added to the errors glossary. Uncompressed keys produce the same addresses as before. I used a length and prefix check rather than importing ox'sPublicKey, which would add about 2.4 kB gzip toprivateKeyToAccount.Tests
publicKeyToAddress.test.tscovers a compressed key and a 64-byte key without the0x04prefix; they fail onmain(8d3f29e) and pass with the change. The export snapshots are updated. biome andtscare clean. The new error putsimport * from 'viem'(esm) just over its size limit, so that limit goes from 91.5 kB to 92 kB; the cjs bundle stays under its limit. A changeset is included.