Skip to content

fix: accept EIP-155 v in recoverPublicKey - #5430

Merged
jxom merged 1 commit into
mainfrom
fix/recover-public-key-eip155-v
Nov 6, 2026
Merged

jxom merged 1 commit into
mainfrom
fix/recover-public-key-eip155-v

Conversation

@jxom

@jxom jxom commented Nov 6, 2026

Copy link
Copy Markdown
Member

Supersedes #5423 (thanks @wavebyrd — credited as co-author).

recoverPublicKey (and so recoverAddress) only accepts a v of 0, 1, 27 or 28, so a signature object with an EIP-155 v throws Invalid yParityOrV value. This shows up with legacy transactions from getTransaction, since formatTransaction drops yParity for them.

#5423 fixed this after Number(v), which loses the low bit for v > 2^53 (chain IDs ≥ 2^52). Those inputs went from throwing to silently recovering the wrong public key. This PR derives parity from the bigint v instead (v % 2n), matching serializeSignature / signatureToCompactSignature.

Raw hex/bytes signatures are unchanged and still accept only 0, 1, 27 or 28 as the final byte, consistent with parseSignature.

Tests

The new eip-155 v test covers v = 37n / 38n (yParity 0 / 1) and chainId = 2^60 for both parities.


Generated by Claude Code

Derive the recovery bit from a signature object's EIP-155 `v`
(`chainId * 2 + 35 + yParity`) using bigint arithmetic, so parity stays
correct for chain IDs beyond `Number.MAX_SAFE_INTEGER`. Raw hex/bytes
signatures are unchanged and still only accept 0, 1, 27 or 28.

Supersedes #5423.

Co-authored-by: wavebyrd <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D3nmWhKptpqjwDfCp3LrqB
@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ea6b10f

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 Nov 6, 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 6, 2026 6:07am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T06:05:52.992622Z ea6b10f 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.

@jxom
jxom merged commit 6c017d5 into main Nov 6, 2026
12 of 39 checks passed
@jxom
jxom deleted the fix/recover-public-key-eip155-v branch November 6, 2026 06:08

This branch had an error being deployed

1 failed deployment
Preview — ea6b10f9 Deployed Nov 6, 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.

2 participants