Skip to content

fix: raise TipAboveFeeCapError when parsing a zero maxFeePerGas - #5316

Closed
mortezashojaei wants to merge 10 commits into
wevm:mainfrom
mortezashojaei:fix/parse-tip-above-zero-fee-cap
Closed

mortezashojaei wants to merge 10 commits into
wevm:mainfrom
mortezashojaei:fix/parse-tip-above-zero-fee-cap

Conversation

@mortezashojaei

Copy link
Copy Markdown
Contributor

Stacked on #5313; until it merges, review only the last commit (aa115c2). On main, assertTransactionEIP1559 still skips a 0n fee cap, so this fix needs #5313.

Summary

RLP encodes 0 as 0x, and the EIP-1559, EIP-7702 and EIP-4844 parsers drop 0x fields. A zero fee cap came back as undefined, so assertTransactionEIP1559 skipped the tip check and a transaction with a tip above a zero fee cap parsed without error.

 parseTransactionEIP1559 / EIP7702 / EIP4844
-  if maxFeePerGas is not 0x
-    decode maxFeePerGas
+  if maxFeePerGas is not 0x, or maxPriorityFeePerGas is not 0x
+    decode maxFeePerGas (0x as 0n)
   assertTransactionEIP1559(transaction)   // now throws TipAboveFeeCapError

The parsed output changes only when the tip is non-empty and the fee cap is zero. With canonical encoding, those transactions are invalid anyway. If both fees are 0x, the output is unchanged.

Evidence

  • Before: parseTransaction(0x02 + rlp([1, 0, tip = 1, maxFeePerGas = 0x, ...])) returned { maxPriorityFeePerGas: 1n } with no fee cap (same for 0x03 and 0x04). The new error tests failed with "function didn't throw".
    After: all three throw TipAboveFeeCapError: The provided tip (maxPriorityFeePerGas = 0.000000001 gwei) cannot be higher than the fee cap (maxFeePerGas = 0 gwei).
  • A new zero fees test (both fees 0x) keeps the output it had before the fix: no fee fields.
  • CI=true pnpm test --run src/utils/transaction src/zksync/serializers.test.ts src/accounts/utils/signTransaction.test.ts: 220 passed, including the existing round trips.

Merge Danger

Door: two-way

Blast Radius: small

parseTransaction now rejects serialized type-2, type-3 and type-4 transactions whose tip is above a zero fee cap. Nodes already reject these.

@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa115c2

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

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

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

commit: aa115c2

jxom commented Oct 27, 2026

Copy link
Copy Markdown
Member

Thanks @mortezashojaei! Superseded by #5318, which keeps your commit and adds a follow-up: the 0n fee cap now keys on the decoded tip rather than the raw field, so a malformed or 0x00 tip no longer adds maxFeePerGas: 0n. It also adds zero-fee tests for EIP-7702 and EIP-4844. Closing this one in favor of it.


Generated by Claude Code

@jxom jxom closed this Oct 27, 2026
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