Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi/api, accounts/abi/bind: Cap highest gas limit by account balance for 1559 fee parameters #23309

Merged
merged 5 commits into from Aug 10, 2021

Conversation

@lightclient
Copy link
Member

@lightclient lightclient commented Jul 31, 2021

Currently, you can call eth_estimateGas with EIP-1559 fee parameters and it won't cap the gas limits it tries based on the account balance. This can cause an ErrInsufficientFunds to be propagated back to the users if they can't afford the initial hi * maxFeeCapPerGas + value.

Before:

$ curl http://localhost:8645 -H 'Content-Type: application/json' -d '{"method":"eth_estimateGas","id":1,"jsonrpc":"2.0", "params":[{"type":"0x2","maxFeePerGas":"0xb2d05e00","maxPriorityFeePerGas":"0xb2d05e00","value":"0x2386f26fc10000","from":"0xe77162b7d2ceb3625a4993bab557403a7b706f18","to":"0xe77162b7d2ceb3625a4993bab557403a7b706f18","data":"0x"}]}' | jq .
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32000,
    "message": "err: insufficient funds for gas * price + value: address 0xe77162b7D2CEb3625a4993Bab557403a7B706F18 have 50000000000000000 want 54943570000000000 (supplied gas 14981190)"
  }
}

After:

$ curl http://localhost:8645 -H 'Content-Type: application/json' -d '{"method":"eth_estimateGas","i
d":1,"jsonrpc":"2.0", "params":[{"type":"0x2","maxFeePerGas":"0xb2d05e00","maxPriorityFeePerGas":"0xb2d05e00","value":"0x2386f26fc10
000","from":"0xe77162b7d2ceb3625a4993bab557403a7b706f18","to":"0xe77162b7d2ceb3625a4993bab557403a7b706f18","data":"0x"}]}' | jq .
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x5208"
}

Note that these request are against a Gorli node.

Copy link
Contributor

@rjl493456442 rjl493456442 left a comment

Thanks for catching it, lgtm.

@karalabe
Copy link
Member

@karalabe karalabe commented Aug 2, 2021

Do we need to duplicate this for the simulated backend too?

@rjl493456442
Copy link
Contributor

@rjl493456442 rjl493456442 commented Aug 2, 2021

Right, I think we need to port the change to the accounts/abi/bind/backends.

@lightclient lightclient force-pushed the fix-estimate-gas branch from 3b26cd1 to 2309bf7 Aug 2, 2021
@lightclient
Copy link
Member Author

@lightclient lightclient commented Aug 2, 2021

@rjl493456442 @karalabe I ported this to the simulated backend and added a test for it, but because the simulated backend grants the account a balance of 2**256-1 it doesn't fail the same way as the it does in the ethapi.

from := stateDB.GetOrNewStateObject(call.From)
from.SetBalance(math.MaxBig256)

It will, however, return a gas value even if the account can't afford it. This is different than how legacy fee estimates are evaluated -- if the account can't afford the estimated gas, the call normally returns an error gas required exceeds allowance (X).

Feel free to drop the last two commits as you see fit.

@lightclient lightclient changed the title Cap highest gas limit by account balance for 1559 fee parameters internal/ethapi/api, accounts/abi/bind: Cap highest gas limit by account balance for 1559 fee parameters Aug 2, 2021
@GregTheGreek
Copy link
Contributor

@GregTheGreek GregTheGreek commented Aug 3, 2021

Is this going to get in before London? Do we know what ranges might look like for small wallet balances? This could block a lot of wallets from submitting transactions if they have something like:

try {
  const gas = web3.eth.estimateGas(...)
  // send tx
} catch (e) {
  // skips sending transaction
}

@GregTheGreek
Copy link
Contributor

@GregTheGreek GregTheGreek commented Aug 3, 2021

For example, I know Argent wallet does this

holiman
holiman approved these changes Aug 4, 2021
Copy link
Contributor

@holiman holiman left a comment

LGTM

@karalabe
Copy link
Member

@karalabe karalabe commented Aug 10, 2021

Pushed a minor naming nitpick so internal variables are using the Go API style and the error message used the RPC API style. Otherwise LGTM

@karalabe karalabe merged commit a879c42 into ethereum:master Aug 10, 2021
0 of 2 checks passed
@karalabe karalabe added this to the 1.10.7 milestone Aug 10, 2021
reds pushed a commit to reds/go-ethereum that referenced this issue Aug 28, 2021
…balance for 1559 fee parameters (ethereum#23309)

* internal/ethapi/api: cap highest gas limit by account balance for 1559 fee parameters

* accounts/abi/bind: port gas limit cap for 1559 parameters to simulated backend

* accounts/abi/bind: add test for 1559 gas estimates for the simulated backend

* internal/ethapi/api: fix comment

* accounts/abi/bind/backends, internal/ethapi: unify naming style

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
i-norden added a commit to vulcanize/go-ethereum that referenced this issue Sep 10, 2021
…balance for 1559 fee parameters (ethereum#23309)

* internal/ethapi/api: cap highest gas limit by account balance for 1559 fee parameters

* accounts/abi/bind: port gas limit cap for 1559 parameters to simulated backend

* accounts/abi/bind: add test for 1559 gas estimates for the simulated backend

* internal/ethapi/api: fix comment

* accounts/abi/bind/backends, internal/ethapi: unify naming style

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
atif-konasl added a commit to lukso-network/pandora-execution-engine that referenced this issue Oct 15, 2021
…balance for 1559 fee parameters (ethereum#23309)

* internal/ethapi/api: cap highest gas limit by account balance for 1559 fee parameters

* accounts/abi/bind: port gas limit cap for 1559 parameters to simulated backend

* accounts/abi/bind: add test for 1559 gas estimates for the simulated backend

* internal/ethapi/api: fix comment

* accounts/abi/bind/backends, internal/ethapi: unify naming style

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants