Skip to content

fix: reject tips above a zero maxFeePerGas - #5319

Merged
jxom merged 2 commits into
mainfrom
fix/tip-above-zero-fee-cap
Nov 1, 2026
Merged

jxom merged 2 commits into
mainfrom
fix/tip-above-zero-fee-cap

Conversation

@jxom

@jxom jxom commented Oct 27, 2026

Copy link
Copy Markdown
Member

Replaces #5313 and keeps @mortezashojaei's change as its own commit, with their authorship. Thank you for the fix and the detailed write-up.

Problem

EIP-1559 makes a transaction invalid when maxPriorityFeePerGas is greater than maxFeePerGas. The tip-vs-cap checks tested truthiness, so a maxFeePerGas of 0n skipped them and the transaction was signed anyway:

await account.signTransaction({
  chainId: 1,
  maxFeePerGas: 0n,
  maxPriorityFeePerGas: 76984525153045n,
})
// signs without error; the node rejects it at broadcast

Changes

From #5313:

  • assertTransactionEIP1559 and assertRequest now check that both fees are bigints instead of truthy. EIP-7702 and EIP-4844 transactions go through assertTransactionEIP1559, so they are covered too.
  • prepareTransactionRequest now throws MaxFeePerGasTooLowError before signing when maxFeePerGas: 0n is passed without a tip and Viem estimates the tip itself.
  • TipAboveFeeCapError and FeeCapTooLowError now print a 0n fee (= 0 gwei) instead of dropping it. FeeCapTooLowError also no longer prints a stray gwei when no fee is given.
  • null fees from untyped callers or raw RPC JSON are still skipped, as before, so formatting the error message can't crash.

Added in review:

  • FeeCapTooHighError now uses the same typeof === 'bigint' check as the other fee errors.
  • A call test for maxFeePerGas: 0n with a non-zero tip. It shows that read-only actions now throw TipAboveFeeCapError before the request reaches the node, as the changeset says.

Behavior note: call, estimateGas, createAccessList and simulateBlocks now reject a zero fee cap paired with a non-zero tip before the request is sent. Geth already rejects this combination in eth_call and eth_estimateGas, so only the source of the error changes.

Not included:

  • fillTransaction only applies the caller's fee preferences when the node returned a non-zero fee. That changes a different action's behavior, so it belongs in its own PR.
  • zkSync's EIP-712 serializer never compares the tip to the fee cap, at any value. That gap existed before this change and is left for a follow-up.

Testing

  • With the pure unit tests (fee error messages, assertRequest, assertTransaction, getNodeError): 60 pass. 7 of the new ones fail against main's source and pass with this change.
  • The new call snapshot was generated against an unreachable RPC URL. It throws before any request is sent.
  • Not run locally, because the environment had no Anvil: the prepareTransactionRequest and signTransaction tests from fix: reject tips above a zero maxFeePerGas #5313. On fix: reject tips above a zero maxFeePerGas #5313, CI cancelled those shards after an unrelated eth_getProof fork failure (distance to target block exceeds maximum proof window), so this PR's CI run is their first full run.
  • Biome is clean. pnpm check:types reports no errors in the changed files. The only errors come from contract artifacts that weren't generated here, plus follow-on errors in multicall.test.ts and readContract.test.ts.

Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ae0c775

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 27, 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 27, 2026 7:32am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T07:28:02.388494Z ae0c775 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.

@github-actions

Copy link
Copy Markdown
Contributor

Published [email protected] under the pr-5319 dist-tag, which follows this pull request until it closes.

pnpm add viem@pr-5319
pnpm add [email protected]

@jxom
jxom merged commit 3dffb81 into main Nov 1, 2026
41 checks passed
@jxom
jxom deleted the fix/tip-above-zero-fee-cap branch November 1, 2026 21:11
jxom added a commit to wevm/ox that referenced this pull request Nov 1, 2026
…s, and `AbiItem` (#561)

* fix: validate struct names and field types in `TypedData.assert`

Ports wevm/viem#5308 and wevm/viem#5370. A struct name must contain
only letters, digits, `_` and `$`, and must not be a Solidity type. A
field type must be a struct in `types` or an EIP-712 atomic or dynamic
type, so `uint`, `uint7` and `bytes0` throw the new
`TypedData.InvalidTypeError`. Every struct is checked, including structs
referenced only as array elements. `findTypeDependencies` strips only the
array suffix, so struct names with `$` are encoded.

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

* fix: reject a tip above a zero `maxFeePerGas` in transaction envelopes

Ports wevm/viem#5318 and wevm/viem#5319. `TxEnvelopeEip1559.assert` and
`TxEnvelopeTempo.assert` compared fees only when both were truthy, so a
zero `maxFeePerGas` skipped the check. `deserialize` for EIP-1559,
EIP-4844, EIP-7702, and Tempo envelopes reads an empty `maxFeePerGas` as
zero when a tip is set. `TipAboveFeeCapError` and `FeeCapTooHighError`
now show zero values.

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

* fix: treat indistinguishable overloads as ambiguous in `AbiItem.fromAbi`

Ports wevm/viem#5339. Distinct types that both match an argument, such
as `bytes32` and `bytes` or `uint256` and `int256`, and arrays of the
same element type with different shapes now throw
`AbiItem.AmbiguityError` instead of resolving to the last match. An
integer overload matches only a value in its range, and a fixed bytes
overload matches only a value of its size.

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

---------

Co-authored-by: Claude <[email protected]>
jxom added a commit to wevm/ox that referenced this pull request Nov 1, 2026
…d `AbiItem` (#560)

* fix: validate struct names and field types in `TypedData.assert`

Ports wevm/viem#5308 and wevm/viem#5370. A struct name must contain
only letters, digits, `_` and `$`, and must not be a Solidity type. A
field type must be a struct in `types` or an EIP-712 atomic or dynamic
type, so `uint`, `uint7` and `bytes0` throw the new
`TypedData.InvalidTypeError`. Every struct is checked, including structs
referenced only as array elements. `findTypeDependencies` strips only the
array suffix, so struct names with `$` are encoded.

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

* fix: reject a tip above a zero `maxFeePerGas` in transaction envelopes

Ports wevm/viem#5318 and wevm/viem#5319. `TxEnvelopeEip1559.assert` and
`TxEnvelopeTempo.assert` compared fees only when both were truthy, so a
zero `maxFeePerGas` skipped the check. `deserialize` for EIP-1559,
EIP-4844, EIP-7702, and Tempo envelopes reads an empty `maxFeePerGas` as
zero when a tip is set. `TipAboveFeeCapError` and `FeeCapTooHighError`
now show zero values.

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

* fix: treat indistinguishable overloads as ambiguous in `AbiItem.fromAbi`

Ports wevm/viem#5339. Distinct types that both match an argument, such
as `bytes32` and `bytes` or `uint256` and `int256`, and arrays of the
same element type with different shapes now throw
`AbiItem.AmbiguityError` instead of resolving to the last match. An
integer overload matches only a value in its range, and a fixed bytes
overload matches only a value of its size.

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

---------

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

This branch was successfully deployed

1 active deployment
Preview — ae0c7751 Deployed Oct 27, 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.

3 participants