Skip to content

fix: encode legacy v above 255 in Transaction.toRpc - #691

Open
gomesalexandre wants to merge 1 commit into
wevm:mainfrom
gomesalexandre:fix_legacy_tx_torpc_v
Open

gomesalexandre wants to merge 1 commit into
wevm:mainfrom
gomesalexandre:fix_legacy_tx_torpc_v

Conversation

@gomesalexandre

Copy link
Copy Markdown
Contributor

Transaction.toRpc encoded v with { size: 1 } for every transaction type. A legacy EIP-155 v is chainId * 2 + 35 + yParity, so it passes 255 from chain ID 110 on (110 with an odd y, every chain from 111) and toRpc threw Hex.IntegerOutOfRangeError. That covers Polygon (v 309/310), Base (v 0x422d/0x422e), Arbitrum, Optimism and so on. Block.toRpc sends every full transaction through Transaction.toRpc, so one legacy transaction makes the whole block throw.

execution-apis types the two vs differently (src/schemas/transaction.yaml):

  • TransactionLegacySigned.v is uint (^0x(0|[1-9a-f][0-9a-f]*)$), with no size limit.
  • the 2930 / 1559 / 4844 / 7702 signed v is byte (^0x[0-9a-f]{1,2}$).

So legacy now encodes v with no size, and typed transactions keep the single byte. The typed snapshots ("v": "0x00") are unchanged. TxEnvelopeLegacy.toRpc and TransactionRequest.toRpc already encode v without a size, so this matches them.

I ran Transaction.toRpc(Transaction.fromRpc(tx)) on every legacy transaction in a live latest block from publicnode:

chain before after
Polygon 0 of 11 legacy txs (Number 309 is not in safe 8-bit unsigned integer range), and Block.toRpc of the full block throws 10 of 10 in the next block, v is the node's v, and Block.toRpc is ok
Base legacy tx v=0x422d throws, and so does Block.toRpc of the full block Block.toRpc is ok
Ethereum 64 of 64 64 of 64

The new test round-trips a real Polygon legacy transaction (v: '0x136'). It throws on main and passes with this change. The two legacy behavior: nullish / behavior: pending fixtures use v: 0, and their snapshots go from "0x00" to "0x0", which is the uint form.

If you'd rather drop { size: 1 } for every type, that works too, since byte also accepts 0x0, and the zod typed schemas already emit 0x0. It only changes more snapshots, so I kept this PR to legacy.

The same { size: 1 } is on 0.x (Hex.fromNumber(transaction.v, { size: 1 }) in src/core/Transaction.ts), so it probably wants the same fix there.

🤖 Generated with Claude Code

`Transaction.toRpc` encoded `v` with `size: 1` for every transaction
type. A legacy EIP-155 `v` is `chainId * 2 + 35 + yParity`, so from
chain ID 110 on (Polygon, Base, Arbitrum, ...) it passes 255 and `toRpc`
threw `Hex.IntegerOutOfRangeError`. `toRpc(fromRpc(tx))` failed on real
legacy transactions from those chains. execution-apis types the legacy
`v` as `uint` and the typed `v` as `byte`, so legacy now encodes it
without a size and typed transactions keep the single byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@gomesalexandre is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant