NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.25k stars 1.4k forks source link

Wrong error message for unrecognized custom error #3646

Open k06a opened 1 year ago

k06a commented 1 year ago

Version of Hardhat

2.12.6

What happened?

I see error on test transaction, where should happen revert 0x863265dc. I see this selector inside the error.

  1) RangeAmountCalculator
       Fill by maker asset
         Revert with incorrect prices:
     Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (data="0x", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","gasLimit":{"type":"BigNumber","hex":"0x01baded8"},"to":"0x5FbDB2315678afecb367f032d93F642f64180aa3","data":"0xacaf53160000000000000000000000000000000000000000000000d8d726b7177a8000000000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000008ac7230489e80000","accessList":null}, error={"name":"TransactionExecutionError","_stack":"TransactionExecutionError: VM Exception while processing transaction: revert with unrecognized return data or custom error\n    at HardhatNode._manageErrors (/Users/k06a/Projects/limit-order-protocol/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1998:14)\n    at HardhatNode._gatherTraces (/Users/k06a/Projects/limit-order-protocol/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1690:30)\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at runNextTicks (node:internal/process/task_queues:64:3)\n    at listOnTimeout (node:internal/timers:538:9)\n    at processTimers (node:internal/timers:512:7)\n    at HardhatNode.runCall (/Users/k06a/Projects/limit-order-protocol/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:652:20)\n    at EthModule._callAction (/Users/k06a/Projects/limit-order-protocol/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:354:9)\n    at HardhatNetworkProvider.request (/Users/k06a/Projects/limit-order-protocol/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18)\n    at TracerWrapper.request (/Users/k06a/Projects/limit-order-protocol/node_modules/hardhat-tracer/src/wrapper.ts:36:16)","code":-32003,"_isProviderError":true,"data":"0x863265dc"}, code=CALL_EXCEPTION, version=providers/5.7.2)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
      at checkError (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:66:16)
      at EthersProviderWrapper.<anonymous> (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:642:20)
      at step (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
      at Object.throw (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
      at rejected (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at runNextTicks (node:internal/process/task_queues:64:3)
      at listOnTimeout (node:internal/timers:538:9)

Source: https://github.com/1inch/limit-order-protocol/actions/runs/4105167851/jobs/7081649960

Minimal reproduction steps

You can try to run test of the commit mentioned above:

yarn && yarn test:ci

Search terms

custom errors

fvictorio commented 1 year ago

I think there are two things going on here.

If you look at the nested error, it says "TransactionExecutionError: VM Exception while processing transaction: revert with unrecognized return data or custom error". This is part of a stack trace that ethers stringifies and puts in a single line, so it's not super helpful, but it's there. That error message should include the selector. The relevant line is here:

https://github.com/NomicFoundation/hardhat/blob/07e4693021aed05baa34a18f76475a7103a9ee04/packages/hardhat-core/src/internal/hardhat-network/provider/node.ts#L1992

The second problem is that ethers is showing a wrong error message, because there definitely is return data in the revert. Maybe we are not adding it properly in this scenario. My guess is that the easiest way to reproduce this is to call a transaction that reverts with some random 4 bytes (so it won't match any error) and see what Hardhat+Ethers do.