ethereum-optimism / developers

This repository is to serve as a place where builders on every level of the OP Stack can come to collaborate.
Creative Commons Zero v1.0 Universal
73 stars 45 forks source link

[Application Development] Gas oracle returns 0 base fees #246

Closed andy-uphold closed 9 months ago

andy-uphold commented 9 months ago

Discussed in https://github.com/ethereum-optimism/developers/discussions/224

Originally posted by **bejitono** February 1, 2024 ### Did you check the documentation? - [X] Yes ### Did you check for duplicate questions? - [X] Yes ### Issue Description We are doing an eth_call to read the `baseFee` from the gas oracle contract `0x420000000000000000000000000000000000000F` which has worked fine until today but is now returning a base fee of 0. We're doing the same on Base which currently works fine. ### Additional Information Example request: `{"method":"eth_call","params":[{"data":"0x6ef25c3a","to":"0x420000000000000000000000000000000000000f"},"latest"],"jsonrpc":"2.0","id":1}` ### Feedback _No response_
andy-uphold commented 9 months ago

Can we get some more information on the real issue here?

Making a call on a contract that requires passing in gas information is VERY strange.

I find it hard to believe that geth is to blame for this - can you show us how geth is enforcing this? - as this would severely limit how calls are made.

From experimenting with this, because you pass in the maxFeePerGas, the call is now requiring that you actually have enough fees to pay for the transaction, which is very frustrating.

I have also noticed that this is only a problem when I have made the call via alchemy or mainnet.optimism.io endpoints, whereas:

https://optimistic.etherscan.io/address/0x420000000000000000000000000000000000000f#readProxyContract

is fine.

sbvegan commented 9 months ago

It's not really an "issue", it's a change in behavior of upstream geth's rpc api and a new quirk that JSON-RPC API callers need to handle. This is the context I got from client engineers:

Yeah I think this is actually correct behaviour from geth - executing a transaction with 0 gas price as you’re trying to do in eth_call will effect the EVM context being created because it’s not a realistic situation post EIP1559. You can imagine some contracts subtracting the base fee from the gas price to find the inclusion fee that would hit underflow errors if the base fee wasn’t set to zero when there’s no gas price.

Here's the base fee being explicitly set to 0 when using eth_call in our code:

https://github.com/ethereum-optimism/op-geth/blob/ea06bb79963e6fd091ff6e1b8b24e7e4355ff334/core/vm/evm.go#L135-L142

where NoBaseFee gets set:

https://github.com/ethereum-optimism/op-geth/blob/75ee01e842954cfacc19aff7061ece6960fd15a1/internal/ethapi/api.go#L1175

and here's the upstream geth code:

https://github.com/ethereum-optimism/op-geth/commit/470dba8fc1890938a65bbf4293a4759a9b9615a1

andy-uphold commented 9 months ago

Thanks for the reply :)

Don't you think it's an issue when a user has to have a certain amount of funds in their account in order to call a read-only method on a contract?

If this is due to an Optimism specific fork of geth, then this should be fixed there, right?

andy-uphold commented 9 months ago

The issue really is that you are asking people to set a value in their request which is at least as big as the value that they want to know.

This is especially an issue as passing in an arbitrarily large value (ideally max uint256 to cover all eventualities) to get the lower precise value is not possible due to needing funds.

sbvegan commented 9 months ago

What funding do you need? These are just requests that I've made from my terminal. Its not connected to an account at all. op-geth is a minimal diff from geth and we aim to keep the upstream code mostly the same with our implementation.

Your Request

$ curl https://mainnet.optimism.io \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_call","params":[{"data":"0x6ef25c3a","to":"0x420000000000000000000000000000000000000f"},"latest"],"jsonrpc":"2.0","id":1}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   239  100   103  100   136    394    520 --:--:-- --:--:-- --:--:--   919
{
  "jsonrpc": "2.0",
  "result": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "id": 1
}

Request with small gasPrice

$ curl https://mainnet.optimism.io \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_call","params":[{"data":"0x6ef25c3a","to":"0x420000000000000000000000000000000000000f", "gasPrice":"0x1"},"latest"],"jsonrpc":"2.0","id":1}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   373  100   219  100   154    674    473 --:--:-- --:--:-- --:--:--  1151
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "err: max fee per gas less than block base fee: address 0x0000000000000000000000000000000000000000, maxFeePerGas: 1, baseFee: 99969359 (supplied gas 50000000)"
  },
  "id": 1
}

Request with gasPrice

curl https://mainnet.optimism.io \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_call","params":[{"data":"0x6ef25c3a","to":"0x420000000000000000000000000000000000000f", "gasPrice":"0x100000000"},"latest"],"jsonrpc":"2.0","id":1}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   265  100   103  100   162    368    579 --:--:-- --:--:-- --:--:--   949
{
  "jsonrpc": "2.0",
  "result": "0x0000000000000000000000000000000000000000000000000000000005fdb229",
  "id": 1
}