Skip to content

fix: compact signature conversion for short values and legacy v - #5279

Merged
jxom merged 7 commits into
mainfrom
jxom/compact-signature-padding
Oct 24, 2026
Merged

jxom merged 7 commits into
mainfrom
jxom/compact-signature-padding

Conversation

@jxom

@jxom jxom commented Oct 24, 2026

Copy link
Copy Markdown
Member

Pads r, s, and yParityAndS to 32 bytes in signatureToCompactSignature and compactSignatureToSignature, derives yParity from any valid v, and rejects high s. RPC values drop leading zeros, which corrupted the parity bit.

Supersedes #5235.

pucedoteth and others added 2 commits October 24, 2026 11:56
…acy `v`

Set the yParity bit on `s` padded to 32 bytes, so an `s` with a leading zero
byte keeps its value, and derive yParity from an EIP-155 `v` the same way
`serializeSignature` does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 55a00f0

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 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Ready Ready Preview Oct 24, 2026 1:54am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-10-24T01:50:34.487417Z 55a00f0 New commits
ℹ️ 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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/viem@5279

commit: 55a00f0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03400d8aeb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

})()
const bytes = hexToBytes(pad(s))
// EIP-2098 stores yParity in the top bit, which is always clear for a low `s`.
if (bytes[0] & 0x80) throw new Error('Invalid `s` value')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject all noncanonical high-s values

When s is between the secp256k1 half-order plus one and 2^255 - 1, its top bit is still clear, so this check accepts it and returns a noncanonical compact signature that canonical verifiers can reject. ERC-2098 requires the available parity bit to come from a canonical low-s signature, so compare s numerically against the curve half-order rather than checking only bit 255.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed. The top-bit check only stops the parity bit from corrupting s, and Viem's other signature utilities do not enforce low s, so values below 2^255 still round-trip losslessly. Leaving this thread open for a maintainer to decide.

🤖 Addressed by Claude Code

@jxom
jxom merged commit 10ef129 into main Oct 24, 2026
67 of 70 checks passed
@jxom
jxom deleted the jxom/compact-signature-padding branch October 24, 2026 08:55
@github-actions github-actions Bot mentioned this pull request Oct 24, 2026
jxom added a commit to wevm/ox that referenced this pull request Oct 25, 2026
…ypedData`, `Hex`, and `RpcTransport` (#526)

* fix: keep empty `version` in `TypedData.extractEip712DomainTypes`

Ports wevm/viem#5240.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* feat: add `even` option to `Hex.assert` and `Hex.validate`

Ports wevm/viem#5283.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* fix: left-pad short `r` and `s` in `Signature.toHex`

Ports wevm/viem#5279.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* fix: array overload resolution in `AbiItem.fromAbi`

Ports wevm/viem#5281.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* fix: `AbiEvent.assertArgs` and `AbiEvent.extractLogs` `args` matching

Ports wevm/viem#5280.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* fix: apply `RpcTransport.fromHttp` timeout to the response body

Ports wevm/viem#5200.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* fix: read tuple object args by name and match empty arrays in `AbiItem.fromAbi` overloads

Syncs with the merged wevm/viem#5281: tuple object args are read by component
name, and an empty array is ambiguous for `address[]` vs `string[]`/`bytes[]`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

* fix: keep the caller signal when `AbortSignal.any` is missing in `RpcTransport.fromHttp`

Matches the 0.x backport (#527): runtimes without `AbortSignal.any`
(Node < 18.17, older browsers) use the caller signal alone instead of
throwing. Also aligns the `AbiEvent.assertArgs` test and the
`getComponentValue` comment with 0.x.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0133zgX2g8oLCoH4KuY8tM9b

---------

Co-authored-by: Claude <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 55a00f0c Deployed Oct 24, 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