MetaMask / MetaMask/metamask-extension
[Bug]: gas estimation for bundled txn simulations is being set wrong, causing bundled transactions with variable gas costs across blocks to fail/revert.
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
### Describe the bug
we notice on our platform that a number of users have issues swapping when using bundled metamask transactions.
these transactions are quotes returned by third party routers, and typically pass both their and our simulation apis, however, fail on metamask.
### Expected behavior
i expect these routes to be executable. they execute with no issue when we set our own gas limits not bundling. but i can't set a gas limit when sending calls to bundle, so i can't get through the failed simulations with not enough gas.
### Screenshots/Recordings
_No response_
### Steps to reproduce
perform a bundled txn on a 7702 activated chain for some complex route (like say, 1inch)
### Error messages or log output
here is some req/resp to the simulation api from the extension for a failing bundle. these are easy to find and i am trying to do some investigation myself.
```shell
[
{
"call": 1,
"description": "Initial simulation with explicit gas and callTrace - SUCCEEDS",
"request": {
"id": "900",
"jsonrpc": "2.0",
"method": "infura_simulateTransactions",
"params": [
{
"withCallTrace": true,
"withLogs": true,
"transactions": [
{
"data": "0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a650000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000000000000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000038807ed23790000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000042000000000000000000000000000000000000060000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba510000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000319be7cd705d390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002310000000000000000000000000000000000000000000000000002130001b05120111111125421ca6dc452d289314280a0f8842a65833589fcd6edb6e08f4c7c32d4f71b54bda0291301449fda64bd000000000000000000000000000000000000000020211852efdf43eb383f73550000000000000000000000004446adc0b8136ffc55ddb7a488ba5509ace2a5ef0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000baa5cc21fd487b8fcc2f632f3f4e8d37262a0842000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000eda2aa95a19169df0000000000000000000000000000000000000000000000000000000001c9c3800000000000000000000000000000afa5ea006a0c0755fd29e1d2454c98d1a6e38c18878bd98da3e41508d6668898558fa0eb1e199b40d5316297200715139ede62718287f281eadde5a6e91f02207d46c67deb79155e49c4d76acffbf95619d40000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000315cde0f791406ee63c1e580b5f0b4ae66c14f7efaa9aa1468e8fc536a3e288cbaa5cc21fd487b8fcc2f632f3f4e8d37262a0842111111125421ca6dc452d289314280a0f8842a65000000000000000000000000000000eb6c05d5000000000000000000000000000000000000000000000000",
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"gas": "0x5f302",
"maxFeePerGas": "0x17d7840",
"maxPriorityFeePerGas": "0x4dceb6",
"to": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"value": "0x0"
}
],
"withGas": true,
"withDefaultBlockOverrides": true
}
]
},
"response": {
"jsonrpc": "2.0",
"result": {
"transactions": [
{
"return": "0x",
"status": "0x1",
"gasUsed": "0x4d42c",
"gasLimit": "0x5f302",
"fees": [
{
"maxFeePerGas": "0x17d7840",
"maxPriorityFeePerGas": "0x4dceb6",
"l1Fee": "0x1758e46ff",
"gas": "0x5f302",
"balanceNeeded": "0x8deeaedf77f",
"currentBalance": "0x1f335264bb1a95",
"error": ""
}
],
"stateDiff": {},
"feeEstimate": 3195989667400,
"baseFeePerGas": 5000000,
"gasCost": "3195989667400"
}
],
"blockNumber": "0x2c0d51e"
},
"id": "900"
}
},
{
"call": 2,
"description": "Sandwich simulation (balanceOf before/after swap) - SUCCEEDS",
"request": {
"id": "901",
"jsonrpc": "2.0",
"method": "infura_simulateTransactions",
"params": [
{
"transactions": [
{
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"to": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"data": "0x70a08231000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba51"
},
{
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"to": "0x4200000000000000000000000000000000000006",
"data": "0x70a08231000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba51"
},
{
"data": "0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a650000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000000000000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000038807ed23790000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000042000000000000000000000000000000000000060000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba510000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000319be7cd705d390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002310000000000000000000000000000000000000000000000000002130001b05120111111125421ca6dc452d289314280a0f8842a65833589fcd6edb6e08f4c7c32d4f71b54bda0291301449fda64bd000000000000000000000000000000000000000020211852efdf43eb383f73550000000000000000000000004446adc0b8136ffc55ddb7a488ba5509ace2a5ef0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000baa5cc21fd487b8fcc2f632f3f4e8d37262a0842000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000eda2aa95a19169df0000000000000000000000000000000000000000000000000000000001c9c3800000000000000000000000000000afa5ea006a0c0755fd29e1d2454c98d1a6e38c18878bd98da3e41508d6668898558fa0eb1e199b40d5316297200715139ede62718287f281eadde5a6e91f02207d46c67deb79155e49c4d76acffbf95619d40000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000315cde0f791406ee63c1e580b5f0b4ae66c14f7efaa9aa1468e8fc536a3e288cbaa5cc21fd487b8fcc2f632f3f4e8d37262a0842111111125421ca6dc452d289314280a0f8842a65000000000000000000000000000000eb6c05d5000000000000000000000000000000000000000000000000",
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"gas": "0x5f302",
"maxFeePerGas": "0x17d7840",
"maxPriorityFeePerGas": "0x4dceb6",
"to": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"value": "0x0"
},
{
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"to": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"data": "0x70a08231000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba51"
},
{
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"to": "0x4200000000000000000000000000000000000006",
"data": "0x70a08231000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba51"
}
],
"withGas": true,
"withDefaultBlockOverrides": true
}
]
},
"response": {
"jsonrpc": "2.0",
"result": {
"transactions": [
{
"return": "0x00000000000000000000000000000000000000000000000000000000094a9dd1",
"status": "0x1",
"gasUsed": "0x79ce",
"gasLimit": "0x7b2f"
},
{
"return": "0x0000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"gasUsed": "0x5d51",
"gasLimit": "0x5ea3"
},
{
"return": "0x",
"status": "0x1",
"gasUsed": "0xee2ca",
"gasLimit": "0x100187"
},
{
"return": "0x000000000000000000000000000000000000000000000000000000000780da51",
"status": "0x1",
"gasUsed": "0x79ce",
"gasLimit": "0x7b2f"
},
{
"return": "0x0000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"gasUsed": "0x5d51",
"gasLimit": "0x5ea3"
}
],
"blockNumber": "0x2c0d4b5"
},
"id": "901"
}
},
{
"call": 3,
"description": "Gas estimation via suggestFees (no explicit gas) - SUCCEEDS with gasLimit 0x5f32e",
"request": {
"id": "902",
"jsonrpc": "2.0",
"method": "infura_simulateTransactions",
"params": [
{
"transactions": [
{
"data": "0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a650000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000000000000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000038807ed23790000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000042000000000000000000000000000000000000060000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba510000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000319be7cd705d390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002310000000000000000000000000000000000000000000000000002130001b05120111111125421ca6dc452d289314280a0f8842a65833589fcd6edb6e08f4c7c32d4f71b54bda0291301449fda64bd000000000000000000000000000000000000000020211852efdf43eb383f73550000000000000000000000004446adc0b8136ffc55ddb7a488ba5509ace2a5ef0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000baa5cc21fd487b8fcc2f632f3f4e8d37262a0842000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000eda2aa95a19169df0000000000000000000000000000000000000000000000000000000001c9c3800000000000000000000000000000afa5ea006a0c0755fd29e1d2454c98d1a6e38c18878bd98da3e41508d6668898558fa0eb1e199b40d5316297200715139ede62718287f281eadde5a6e91f02207d46c67deb79155e49c4d76acffbf95619d40000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000315cde0f791406ee63c1e580b5f0b4ae66c14f7efaa9aa1468e8fc536a3e288cbaa5cc21fd487b8fcc2f632f3f4e8d37262a0842111111125421ca6dc452d289314280a0f8842a65000000000000000000000000000000eb6c05d5000000000000000000000000000000000000000000000000",
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"to": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"value": "0x0"
}
],
"suggestFees": {
"withTransfer": true,
"withFeeTransfer": true,
"with7702": true
}
}
]
},
"response": {
"jsonrpc": "2.0",
"result": {
"transactions": [
{
"return": "0x",
"status": "0x1",
"gasUsed": "0x4d352",
"gasLimit": "0x5f32e",
"fees": [
{
"maxFeePerGas": "0x89778c",
"maxPriorityFeePerGas": "0xf4244",
"l1Fee": "0x171738b7a",
"gas": "0x5f32e",
"balanceNeeded": "0x3335c62ddd0",
"currentBalance": "0x1f335264bb1a95",
"error": "",
"tokenFees": [
{
"token": {
"address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"symbol": "USDC",
"decimals": 6
},
"balanceNeededToken": "0x3b63",
"currentBalanceToken": "0x780da51",
"serviceFee": "0xf65",
"rateWei": "0x1a9e5e4e65d66",
"error": "",
"feeRecipient": "0xe3478b0bb1a5084567c319096437924948be1964",
"totalGas": "0x8ec1c",
"isDelegationFee": true,
"exchangeRateProvider": "oneinch"
},
{
"token": {
"address": "0x4200000000000000000000000000000000000006",
"symbol": "wETH",
"decimals": 18
},
"balanceNeededToken": "0x67127e01b8b",
"currentBalanceToken": "0x31dbb17cb7564e",
"serviceFee": "0x1ab8f142d11",
"rateWei": "0xde0b6b3a7640000",
"error": "",
"feeRecipient": "0xe3478b0bb1a5084567c319096437924948be1964",
"totalGas": "0x8e040",
"isDelegationFee": true,
"exchangeRateProvider": "oneinch"
},
{
"token": {
"address": "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf",
"symbol": "cbBTC",
"decimals": 8
},
"balanceNeededToken": "0x14",
"currentBalanceToken": "0x46e",
"serviceFee": "0x5",
"rateWei": "0x1f41eaf30ceb8ff93",
"error": "",
"feeRecipient": "0xe3478b0bb1a5084567c319096437924948be1964",
"totalGas": "0x93fc9",
"isDelegationFee": true,
"exchangeRateProvider": "oneinch"
}
]
}
],
"feeEstimate": 1897452316242,
"baseFeePerGas": 5000000
}
],
"blockNumber": "0x2c0d51f"
},
"id": "902"
}
},
{
"call": 4,
"description": "Re-simulation with gas from call 3 baked in - FAILS with out of gas due to pool state change",
"request": {
"id": "903",
"jsonrpc": "2.0",
"method": "infura_simulateTransactions",
"params": [
{
"withCallTrace": true,
"withLogs": true,
"transactions": [
{
"data": "0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a650000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000000000000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000038807ed23790000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000042000000000000000000000000000000000000060000000000000000000000004c3ccc98c01103be72bcfd29e1d2454c98d1a6e3000000000000000000000000b770b86b1544edf51bbf82dd01e8e867607dba510000000000000000000000000000000000000000000000000000000001c9c38000000000000000000000000000000000000000000000000000319be7cd705d390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002310000000000000000000000000000000000000000000000000002130001b05120111111125421ca6dc452d289314280a0f8842a65833589fcd6edb6e08f4c7c32d4f71b54bda0291301449fda64bd000000000000000000000000000000000000000020211852efdf43eb383f73550000000000000000000000004446adc0b8136ffc55ddb7a488ba5509ace2a5ef0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000baa5cc21fd487b8fcc2f632f3f4e8d37262a0842000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000eda2aa95a19169df0000000000000000000000000000000000000000000000000000000001c9c3800000000000000000000000000000afa5ea006a0c0755fd29e1d2454c98d1a6e38c18878bd98da3e41508d6668898558fa0eb1e199b40d5316297200715139ede62718287f281eadde5a6e91f02207d46c67deb79155e49c4d76acffbf95619d40000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000315cde0f791406ee63c1e580b5f0b4ae66c14f7efaa9aa1468e8fc536a3e288cbaa5cc21fd487b8fcc2f632f3f4e8d37262a0842111111125421ca6dc452d289314280a0f8842a65000000000000000000000000000000eb6c05d5000000000000000000000000000000000000000000000000",
"from": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"gas": "0x5f302",
"maxFeePerGas": "0x17d7840",
"maxPriorityFeePerGas": "0x4dceb6",
"to": "0xb770b86b1544edf51bbf82dd01e8e867607dba51",
"value": "0x0"
}
],
"withGas": true,
"withDefaultBlockOverrides": true
}
]
},
"response": {
"jsonrpc": "2.0",
"result": {
"transactions": [
{
"error": "execution reverted",
"return": "0x",
"status": "0x0",
"gasUsed": "0x5abd6",
"fees": [
{
"maxFeePerGas": "0x17d7840",
"maxPriorityFeePerGas": "0x4dceb6",
"l1Fee": "0x1758e46ff",
"gas": "0x5f302",
"balanceNeeded": "0x8deeaedf77f",
"currentBalance": "0x1f335264bb1a95",
"error": ""
}
],
"stateDiff": {
"post": {
"0x4200000000000000000000000000000000000011": {
"balance": "0x3ec3acdbdacf09b98"
},
"0x4200000000000000000000000000000000000019": {
"balance": "0x12486d6831e69c4ff"
},
"0xb770b86b1544edf51bbf82dd01e8e867607dba51": {
"balance": "0x1f2fe872c414f1",
"nonce": "0x7f"
}
},
"pre": {
"0x4200000000000000000000000000000000000011": {
"balance": "0x3ec3acc0469443d74"
},
"0x4200000000000000000000000000000000000019": {
"balance": "0x12486d4d2701f1d7f"
},
"0xb770b86b1544edf51bbf82dd01e8e867607dba51": {
"balance": "0x1f335264bb1a95",
"nonce": "0x7e"
}
}
},
"feeEstimate": 3753565947300,
"baseFeePerGas": 5000000,
"gasCost": "3753565947300"
}
],
"blockNumber": "0x2c0d520"
},
"id": "903"
}
}
]
```
### Where was this bug found?
Live version (from official store)
### Version
13.30.0
### Build type
None
### Browser
Chrome
### Operating system
Linux
### Hardware wallet
_No response_
### Additional context
i am only reporting the os i am on, but multiple (10+) users across both macos and windows on chrome have observed this exact same behavior.
### Severity
_No response_
Contributor guide
Research direction
Start by reproducing the bundled transaction on a 7702-activated chain using the infura_simulateTransactions requests and responses in the issue. Compare gas limits and gasUsed across the explicit-gas, sandwich, and suggestFees simulations; done means variable-cost bundled routes receive enough gas and no longer fail or revert.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100