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

Calling eth_estimateGas opts to fallback estimation when a contract revert is executed #2830

Closed
victor-yanev opened this issue Aug 15, 2024 · 0 comments · Fixed by #2834
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@victor-yanev
Copy link
Contributor

victor-yanev commented Aug 15, 2024

Description

Many frameworks depend on eth_call and eth_estimateGas after sending a transaction which reverts to retrieve the revert reason for their sent transaction.

Currently, calling eth_estimateGas on a function which reverts against our relay will return the following error from the mirror-node:

Error raised while fetching estimateGas from mirror-node: {"detail":"","data":"0x858d70bd","statusCode":400}

which contains the revert reason in the "data" field of the thrown error.

What we currently do is treat it as a regular error from the mirror node and we opt to the fallback estimations instead of returning the revert reason to the user to give him context of what is happening (as other ETH clients would for eth_estimateGas)

Steps to reproduce

  1. send a transaction which calls a reverting contract function through eth_sendRawTransaction
  2. send an eth_estimateGas request with the unsigned transaction body and the block number from the receipt of the executed transaction

Expected:

  • should return the error code for contract revert and the ABI-encoded revert reason from the contract call in the "data" field of the error.

Example with custom error thrown in solidity:

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -32000,
        "message": "Execution reverted",
        "data": "0x858d70bd"
    }
}

If the returned reason is encoded as a generic Error(string)(prefixed with 0x08c379a) and not a custom error, we can decode it and append it to the message to be consistent with hyperledger/besu#5706:

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -32000,
        "message": "Execution reverted: ERC20: transfer amount exceeds balance",
        "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002645524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63650000000000000000000000000000000000000000000000000000"
    }
}

Actual:

  • ignores the error from mirror node (which contains the revert reason) and returns a hardcoded fallback gas estimation

Additional context

TRACE (relay-eth/85 on 5f4099310571): [Request ID: 9ebee5c9-3cae-4a92-b4a8-76e73666c865] estimateGas(transaction={"from":"0x17b2b8c63fa35402088640e426c6709a254c7ffb","to":"0x498825bf0af4ffaa3f2cc4ea176d6df7fed8bde2","gas":"0x61a80","gasPrice":"0x0","value":"0x0","data":"0xf8a8fd6d"}, _blockParam=undefined)
DEBUG (mirror-node/85 on 5f4099310571): [Request ID: 9ebee5c9-3cae-4a92-b4a8-76e73666c865] [POST] contracts/call Contract Revert: ( StatusCode: '400', StatusText: '', Detail: 'undefined',Data: '{"_status":{"messages":[{"message":"CONTRACT_REVERT_EXECUTED","detail":"","data":"0x858d70bd"}]}}')
ERROR (relay-eth/85 on 5f4099310571): [Request ID: 9ebee5c9-3cae-4a92-b4a8-76e73666c865] Error raised while fetching estimateGas from mirror-node: {"detail":"","data":"0x858d70bd","statusCode":400}
WARN (relay-eth/85 on 5f4099310571): [Request ID: 9ebee5c9-3cae-4a92-b4a8-76e73666c865] Returning predefined gas for contract call: 0x7a120
INFO (rpc-server/85 on 5f4099310571): [Request ID: 9ebee5c9-3cae-4a92-b4a8-76e73666c865] [POST]: eth_estimateGas 200 13 ms

Hedera network

No response

Version

v0.54.0

Operating system

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant