onflow / flow-evm-gateway

FlowEVM Gateway implements an Ethereum-equivalent JSON-RPC API for EVM clients to use
https://developers.flow.com/evm/about
Apache License 2.0
11 stars 9 forks source link

Investigate gas estimation error #468

Closed m-Peter closed 1 month ago

m-Peter commented 1 month ago

The following was posted on discord:

(error={"reason":"execution reverted","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","error":{"reason":"processing response error","code":"SERVER_ERROR","body":"{"jsonrpc":"2.0","id":49,"error":{"code":3,"message":"execution reverted","data":"0x"}}\n","error":{"code":3,"data":"0x"},"requestBody":"{"method":"eth_estimateGas","params":[{"type":"0x2","maxFeePerGas":"0x59682f00","maxPriorityFeePerGas":"0x59682f00","from":"0xc00e18c4a42ded744fd65ff40836b0fd3e5b7f02","to":"0x1c72f448e5b76c1840c4d9342b6fce5af15e293b","data":"0xa59ac6dd0000000000000000000000006553a672e5837e2f96e3e5662a6935888e0c614000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"}],"id":49,"jsonrpc":"2.0"}","requestMethod":"POST","url":"https://testnet.evm.nodes.onflow.org"}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.7.0)
but when I set gasLimit to a specific value, the transaction fails. 
my tx:https://evm-testnet.flowscan.io/tx/0x745fa88666e3a3329db7b041ad5edab62d1190230292c648260cf361e787c8bd
sideninja commented 1 month ago

Looking into this I can see the transaction you linked as failed seems like it didn't fail due to insufficient gas.

curl https://testnet.evm.nodes.onflow.org \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_getTransactionByHash","params":["0x745fa88666e3a3329db7b041ad5edab62d1190230292c648260cf361e787c8bd"],"id":1,"jsonrpc":"2.0"}'

{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x6cb84c4ea2b433fdebf36a5e57c85ecdbe61340b526b9920243ed63dadacd99d","blockNumber":"0x166755","from":"0xc00e18C4A42dEd744fd65Ff40836B0Fd3E5b7f02","gas":"0xc3500","gasPrice":"0x59682f00","maxFeePerGas":"0x59682f00","maxPriorityFeePerGas":"0x59682f00","hash":"0x745fa88666e3a3329db7b041ad5edab62d1190230292c648260cf361e787c8bd","input":"0xa59ac6dd0000000000000000000000006553a672e5837e2f96e3e5662a6935888e0c6140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002540be400","nonce":"0x24","to":"0x1C72f448E5B76c1840C4d9342B6FcE5aF15e293b","transactionIndex":"0x0","value":"0x0","type":"0x2","accessList":[],"chainId":"0x221","v":"0x0","r":"0x8d0a235af2a161c64c95b8685b18fa43e26085cdf952560c30e6d570e2388184","s":"0x68f21eb73cc018c1a285cafc081d59e7873a44252127a18bcaca8777f12bad47","yParity":"0x0"}}
curl https://testnet.evm.nodes.onflow.org \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_getTransactionReceipt","params":["0x745fa88666e3a3329db7b041ad5edab62d1190230292c648260cf361e787c8bd"],"id":1,"jsonrpc":"2.0"}'
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x6cb84c4ea2b433fdebf36a5e57c85ecdbe61340b526b9920243ed63dadacd99d","blockNumber":"0x166755","contractAddress":null,"cumulativeGasUsed":"0x99d1","effectiveGasPrice":"0x59682f00","from":"0xc00e18C4A42dEd744fd65Ff40836B0Fd3E5b7f02","gasUsed":"0x99d1","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","status":"0x0","to":"0x1C72f448E5B76c1840C4d9342B6FcE5aF15e293b","transactionHash":"0x745fa88666e3a3329db7b041ad5edab62d1190230292c648260cf361e787c8bd","transactionIndex":"0x0","type":"0x2"}}

As seen the gas limit set was 800000 and the actual used gas was 39377. So the reason your transaction failed must be related to interaction with the contract.

About the first error:

(error={"reason":"execution reverted","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","error":{"reason":"processing response error","code":"SERVER_ERROR","body":"{"jsonrpc":"2.0","id":49,"error":{"code":3,"message":"execution reverted","data":"0x"}}\n","error":{"code":3,"data":"0x"},"requestBody":"{"method":"eth_estimateGas","params":[{"type":"0x2","maxFeePerGas":"0x59682f00","maxPriorityFeePerGas":"0x59682f00","from":"0xc00e18c4a42ded744fd65ff40836b0fd3e5b7f02","to":"0x1c72f448e5b76c1840c4d9342b6fce5af15e293b","data":"0xa59ac6dd0000000000000000000000006553a672e5837e2f96e3e5662a6935888e0c614000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"}],"id":49,"jsonrpc":"2.0"}","requestMethod":"POST","url":"https://testnet.evm.nodes.onflow.org"}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.7.0)

That I believe is also result of the transaction failing to interact with the contract and reverting.

From quick looking at the contract you are calling it seems like you are calling buy method but there's no method I see on that contract.