MetaMask / MetaMask/metamask-extension

[Bug]: gasLimit auto increased when sending erc20

Open
#19,318 4 comments 0 reactions 0 assignees View on GitHub
external-contributor Gas INVALID-ISSUE-TEMPLATE Sev2-normal team-confirmations type-enhancement
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

**Describe the bug**

when I send erc20 with MM, it uses gasLimit which 50% greater than `eth_estimateGas` return. I did some grep around and it seems to be a "feature". https://github.com/MetaMask/metamask-extension/issues/8771#issuecomment-759243828

However this become a bug in our evm network, where gasLimit has some specific encoding, so can't be altered randomly. I hope to make MM use exactly what `eth_estimateGas` return.

This 50% increase is a very opinionated operation that's only required for networks that has the gas underestimation issue. So I think there should either be a way to turn it off (make it default behaviour, but optional), or force enable it ONLY for certain networks that really need it.

So my question is:
- is there a way to turn this feature off? If not, it's a feature request.
- can someone please clarify when does MM auto increase gasLimit by 50%? Is it only for token transfer, or is it for all contract calls? If it's only for token transfers, I can probably do some workaround in our network, such as "divide gasLimit by 1.5 before `eth_estimateGas` return when sending erc20"

Thanks!

**Steps to reproduce**

1. start an evm network with ETH RPC locally
2. connect MM to localhost, try send erc20
3. local RPC logs show that `eth_estimateGas` returns `X`
4. on MM UI we can see `X * 1.5` as gasLimit

**Version**

10.30.4

**Build type**

None

**Browser**

Chrome

**Operating system**

MacOS

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Reproduce the ERC20 transfer on a local EVM network while comparing the RPC's eth_estimateGas result with the gasLimit shown in the MetaMask UI, then trace the gas-estimation path and contract-call handling. Done should include a decided behavior for networks that require the exact estimate and coverage for the relevant transfer or contract-call cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
blockchain
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.