Skip to content

ethapi,backends: Export revertError for EstimateGas failures #27539

Description

@Willyham

Rationale

Assume a simple contract which may revert with a custom error:

pragma solidity ^0.8.20;

contract Foo {
   uint256 public bar = 0;
   error CustomError(); 
 
   function setBar(uint256 bar_) public {
      if (bar_ > 100) {
        revert CustomError();
      }
     bar = bar_;
   }
}

Calling EstimateGas on the function when bar_ > 100 will cause either a *backends.revertError or *ethapi.revertError to be returned, depending on the network being used. This error struct contains the message execution reverted along with the reason field set to the 4byte selector of CustomError. This is the expected behaviour.

However, because the revertError type is not exported, callers cannot inspect the reason field without resorting to unsafe pointers. It would be very helpful (almost crucial) in code to be able to determine the reason for a failure.

I understand there is a larger issue around custom errors for non-gas-estimations being tracked here #26823.

Implementation

On the face of it it seems like a relatively simple change to export these structs to they may be inspected by callers. A further improvement would then be to update abigen to produce code which can map the selectors to some kind of enum/const of the custom errors, but this can be tackled later.

I am happy to implement this feature if it seems directionally correct.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions