ape icon indicating copy to clipboard operation
ape copied to clipboard

Catch and re-throw w/ `CustomError` if `ErrorABI` match detected

Open fubuloubu opened this issue 1 year ago • 6 comments

Overview

If an error with a contract is encoded using Solidity's custom error feature, currently ape displays this message:

ERROR: (ContractLogicError) custom error e0b4aa5a:00000000000000000000000000000000…00000000000000000000000000030931 (64 bytes)

This is not enough to actually be able to decode into a CustomError object (available from ContractInstance._errors_)

Further, if the data is available, there is not an easy way to decode that exception from bytes back into the custom error type

Specification

Add method to catch a contract logic error and instead generate a CustomError type that gets re-thrown

Dependencies

This may impact/simplify the custom error reverts checking logic that the testing-only reverts manager employs

fubuloubu avatar Apr 27 '24 22:04 fubuloubu

We should be doing this already. What provider are you using? (changed to bug because this feature exists and works for many cases)

antazoey avatar Apr 30 '24 13:04 antazoey

@wavey0x or @fp-crypto had this issue I think

fubuloubu avatar Apr 30 '24 20:04 fubuloubu

@wavey0x or @fp-crypto had this issue I think

I try to repro tomorrow with providers i know they use but otherwise that is the most desired info I need as each provider shows the hex different and we have to make sure we are passing expected-styles to compiler.enrich_error for it to work, lots of players in this game!

antazoey avatar Apr 30 '24 22:04 antazoey

I have tried on:

  • foundry
  • eth tester
  • geth (dev)
  • hardhat
  • ethereum:local:http://127.0.0.1:8545 (pointed it various local nodes)

using solidity v0.8.24... and I am getting custom errors just fine.

more info please :))) Ill keep trying to repro.

antazoey avatar May 01 '24 17:05 antazoey

here we encode WRAP_ETH(dev, 1 ether). the first one should work, the second should fail with InsufficientETH().

from ape import Contract, accounts

def main():
    universal_router = Contract('0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD')
    dev = accounts.test_accounts[0]
    for value in [10**18, 0]:
        receipt = universal_router.execute('0x0b', ['0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000de0b6b3a7640000'], sender=dev, value=value)
        receipt.show_trace()
ape run bug --network :mainnet-fork

it shows this for me

Screenshot 2024-05-01 at 23 54 50

banteg avatar May 01 '24 19:05 banteg