internal/ethapi: return code 3 from call/estimateGas even if a revert reason was not returned#31456
Conversation
…even if a revert reason was not supplied
|
I will add some additional test coverage with this PR if we agree that the changes here are ok. |
|
l |
There was a problem hiding this comment.
Pull Request Overview
This PR updates the error handling in the ethapi package so that both DoCall and DoEstimateGas consistently return a revertError when a revert occurs, regardless of whether revert data is provided.
- Updates condition checks in Call and DoEstimateGas to use errors.Is(err, vm.ErrExecutionReverted) instead of checking the length of the revert data.
- Ensures uniform error reporting across eth_call and eth_estimateGas methods.
gballet
left a comment
There was a problem hiding this comment.
LGTM but as you said, tests are needed. Also, refer to the PR that prompted you to work on this.
|
This PR was prompted by #31444 . I think there was some confusion with the other PR because currently we define the default rpc error code and a constant for the revert error code to have the same value of So right now, when receiving an rpc error (of a generic type) from a revert w/o revert data, where the error contains said error code and the message "execution reverted", it could lead to the assumption that the error is a revert error type. |
… reason was not returned (ethereum#31456)
… reason was not returned (ethereum#31456)
… reason was not returned (ethereum#31456)
… reason was not returned (ethereum#31456)
… reason was not returned (ethereum#31456)
… reason was not returned (ethereum#31456)
BREAKING: RPC error codes changed - EActorNotFound (from 3 to 11), EExecutionReverted (from 11 to 3). Mismatched client/server versions will deserialize these errors as the wrong Go type, breaking errors.Is/As checks. Swap EExecutionReverted and EActorNotFound positions so that EExecutionReverted gets code 3, the de facto Ethereum standard for execution reverted errors. This enables proper error decoding by Ethereum tooling like viem, ethers.js, and other RPC clients. Error code 3 was introduced in geth v1.9.15 and is now expected by most Ethereum ecosystem tooling for automatic ABI decoding of revert reasons from the error data field. Ref: ethereum/go-ethereum#21083 Ref: ethereum/go-ethereum#31456 Ref: ethereum/go-ethereum#21886 Ref: https://github.com/wevm/viem/blob/6c11882938673e939830027f47ed73e907f2b90e/src/utils/errors/getContractError.ts Ref: https://www.quicknode.com/docs/ethereum/error-references Ref: https://docs.metamask.io/services/reference/ethereum/json-rpc-methods/eth_call/
BREAKING: RPC error codes changed - EActorNotFound (from 3 to 11), EExecutionReverted (from 11 to 3). Mismatched client/server versions will deserialize these errors as the wrong Go type, breaking errors.Is/As checks. Swap EExecutionReverted and EActorNotFound positions so that EExecutionReverted gets code 3, the de facto Ethereum standard for execution reverted errors. This enables proper error decoding by Ethereum tooling like viem, ethers.js, and other RPC clients. Error code 3 was introduced in geth v1.9.15 and is now expected by most Ethereum ecosystem tooling for automatic ABI decoding of revert reasons from the error data field. Ref: ethereum/go-ethereum#21083 Ref: ethereum/go-ethereum#31456 Ref: ethereum/go-ethereum#21886 Ref: https://github.com/wevm/viem/blob/6c11882938673e939830027f47ed73e907f2b90e/src/utils/errors/getContractError.ts Ref: https://www.quicknode.com/docs/ethereum/error-references Ref: https://docs.metamask.io/services/reference/ethereum/json-rpc-methods/eth_call/
Currently we only return a
revertErrorfromBlockchainAPI.(DoCall,EstimateGas)when execution reverts with non-empty revert reason.If the revert data is empty, the RPC response is constructed with a generic
errCodeDefaultcode here.By altering the behavior to return a
revertErrorfromDoCall/DoEstimateGasupon revert regardless of whether there was a reason supplied, we consistently return the same revert error code whenever a revert occurs frometh_estimateGas/eth_call.Steps to Verify this PR is Correct
Using the genesis files I have attached in this gist:
Spin up a dev-mode instance of Geth. The genesis contains an account
0x1000000000000000000000000000000000000001which when called will revert with no data.In a separate terminal:
which on master outputs:
with this PR:
Now repeat the process again, except this time instantiating the datadir with
genesis-nonempty-revert.json: The0x1000000000000000000000000000000000000001account now contains code that reverts with a single byte of revert data.On master, and this PR:
The same instructions can be repeated except with
eth_callinstead ofeth_estimateGasand produce the same results as above.