Repository navigation
fix: reject tips above a zero maxFeePerGas - #5313
Closed
mortezashojaei wants to merge 9 commits into
Closed
mortezashojaei wants to merge 9 commits into
mortezashojaei wants to merge 9 commits into
Conversation
|
@mortezashojaei is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 59e8230 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
…n fee cap guards
This was referenced Oct 27, 2026
Member
|
Thanks @mortezashojaei, this is a solid fix with a great write-up. We're landing it through #5319, which keeps your commit as-is with your authorship and adds two small follow-ups: Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EIP-1559 makes a transaction invalid when
maxPriorityFeePerGasis greater thanmaxFeePerGas, and nodes reject it (Geth:max priority fee per gas higher than max fee per gas). Viem checks for this inassertTransactionEIP1559, but the check tests truthiness, so amaxFeePerGasof0nskips it and the transaction is serialized and signed:The same input with
maxFeePerGas: 1nthrowsTipAboveFeeCapErroras expected. The late failure costs a wasted signature (relevant for remote signers such as a KMS) and a confusing error instead of the usual fail-fast one.The same check runs when validating requests and preparing transactions, so this fixes it in signing, request validation and the related error messages:
assertTransactionEIP1559: checks that both fees are bigints instead of truthy. EIP-7702 and EIP-4844 transactions call this function too.assertRequest: same check. This matters for JSON-RPC accounts, where Viem never serializes locally and the request went straight to the wallet.prepareTransactionRequest: whenmaxFeePerGas: 0nis passed without a tip, the tip is estimated but theMaxFeePerGasTooLowErrorguard was skipped. It now throws before signing.TipAboveFeeCapError: the message dropped a fee of0n. Both the tip and the fee cap now print it (= 0 gwei), sincegetNodeErrorpasses whatever the caller supplied.The checks use
typeof x === 'bigint'rather than!== undefined, so anullfee from an untyped caller or raw RPC JSON is still skipped like before. With!== undefined,1n > nullistrueand building the error message crashed informatGwei. That includesgetNodeError, which passes the caller's request fields intoTipAboveFeeCapError. When a field is left out, the checks are still skipped, so partial requests keep working, and0nwith0nstill passes.assertRequestalso runs in read-only actions (call,estimateGas,createAccessList,simulateBlocks, Linea'sestimateGas, zkSync'sassertEip712Requestand Tempo'ssimulate). AmaxFeePerGasof0nwith a non-zero tip now throwsTipAboveFeeCapErrorthere before reaching the node. Geth already rejects that combination ineth_callandeth_estimateGas(maxFeePerGas (0) < maxPriorityFeePerGas (...)), so only the error source changes.FeeCapTooLowErrorhad the same truthiness check in its message. It is most likely to be hit with a0nfee cap, and dropped the value while keeping the unit, printing(`maxFeePerGas` gwei). It now prints= 0 gwei, and a missing fee prints(`maxFeePerGas`).maxFeePerGas: 0nwith no tip fails before signing on bothprepareTransactionRequestpaths, but with different errors. When Viem estimates fees itself, it throwsMaxFeePerGasTooLowError. When the node supportseth_fillTransaction, the node fills the tip, Viem's fee estimation is skipped, and the finalassertRequestthrowsTipAboveFeeCapError.Added the reproduction above as a
signTransactiontest, plus zero fee cap tests for EIP-1559, EIP-7702, EIP-4844,assertRequest, bothprepareTransactionRequestpaths and thegetNodeErrormessage. Each fails onmainand passes with this change. Theeth_fillTransactiontest was run against Anvil 1.7.1, the version CI pins; older Anvil lacks the method and falls back to Viem's own fee step. Added0nmessage tests forFeeCapTooLowErrorand for a zero tip inTipAboveFeeCapError, and tests that0nwith0nstill passesassertTransactionEIP1559andassertRequest, which zero-gas private chains depend on. Addednullfee cap tests forassertRequestandTipAboveFeeCapError(whichgetNodeErrorbuilds from the caller's request); both crash with!== undefinedand pass with this change. The existingFeeCapTooLowErrorsnapshot without a fee was updated to drop the straygwei. The rest of the transaction utils, errors, Celo, zkSync and OP Stack serializer tests pass unchanged, andpnpm check:typesand Biome are clean.Not included:
fillTransactiononly applies the caller's fee preferences when the node returned a non-zero fee. That changes the behavior of a different action, so it is better as its own PR.