fix: round base fee multiplier instead of ceiling it in fee estimation#4862
Open
Kropiunig wants to merge 2 commits into
Open
fix: round base fee multiplier instead of ceiling it in fee estimation#4862Kropiunig wants to merge 2 commits into
Kropiunig wants to merge 2 commits into
Conversation
`estimateFeesPerGas` and `fillTransaction` build an integer numerator for the base fee multiplier as `baseFeeMultiplier * 10 ** decimals`. That product is mathematically an exact integer, but floating-point error can push it slightly above the target (e.g. `1.09 * 100` evaluates to `109.00000000000001`). Using `Math.ceil` then rounds it up to `110`, silently applying a `1.10` multiplier instead of the requested `1.09` (also affects `1.11`, `1.12`, and others). `Math.round` recovers the intended integer in every case.
|
@Kropiunig 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: 3682860 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: |
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.
Summary
estimateFeesPerGas(andfillTransaction) apply thebaseFeeMultiplierusing fixed-point integer math:baseFeeMultiplier * denominatoris mathematically an exact integer — that is the whole purpose of derivingdecimals/denominatorfrom the number's decimal places. It only needs a guard because of floating-point error, butMath.ceilguards it in the wrong direction. When the float product lands just above the integer,Math.ceilbumps it to the next integer:1.09 * 100 === 109.00000000000001→Math.ceil→110(applies1.10, not1.09)1.11(→112),1.12(→113), and othersSo a caller that sets
baseFeeMultiplier: 1.09silently gets a1.10multiplier. It is inconsistent, too:1.15(114.999…) already works because its float error falls below the integer, which shows theceilis not an intentional round-up.Fix
Use
Math.roundinstead ofMath.ceil. The target is always an exact integer and the float error is far below0.5, soroundrecovers the intended value in every case (and matchesceilwhereverceilwas already correct, e.g.2.01). The same one-line fix applies to the duplicatedmultiplyFeehelper infillTransaction.Test
Extended the existing
args: chain \baseFeeMultiplier` override (value)test inestimateFeesPerGas.test.tswith a1.09case assertingmaxFeePerGas === baseFeePerGas * 109n / 100n + maxPriorityFeePerGas. It fails onmain(produces* 110n / 100n`) and passes with the fix.