hardhat
hardhat copied to clipboard
Hardhat fails to extract stacktrace info from reverted transaction
Given the following error message:
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ]
(reason="VM Exception while processing transaction: reverted with reason string ''", method="estimateGas", transaction=
{"from":"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC","gasPrice":
{"type":"BigNumber","hex":"0x00"},"to":"0x663F3ad617193148711d28f5334eE4Ed07016602","value":
{"type":"BigNumber","hex":"0x65"},"data":"0x3e58c58c00000000000000000000000071c95911e9a5d330f4d621842ec243ee1343292e",
"accessList":null}, error={"stackTrace":[{"type":4,"sourceReference":
{"function":"send","contract":"SendFunction","sourceName":"contracts/test/SendFunction.sol","sourceContent":
"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.14;\n\ncontract SendFunction {\n
function send(address to) external payable {\n (bool success, bytes memory data) = to.call{value: msg.value}(\"x\");\n
if (!success) {\n revert(string(data));\n }\n }\n}\n","line":9,"range":[244,264]},"message":{"value":
{"type":"Buffer","data":
[8,195,121,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0]},"_selector":"08c379a0"},"isInvalidOpcodeError":false}],"data":"0x08c379a000000000000000000000000000000000
000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"},
code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
at checkError (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:78:20)
at EthersProviderWrapper.<anonymous> (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:603: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)
Hardhat's stacktrace shows no useful information. However the reverted transaction contains information about where the transaction reverted: error={"stackTrace": ...}
.
This issue is also being tracked on Linear.
We use Linear to manage our development process, but we keep the conversations on Github.
LINEAR-ID: b72b1d6d-1846-44b6-8a99-6ad088695c9c
@lukehutch can you provide a minimal reproducible example?
Closing for lack of MRE.
@fvictorio Sorry for the delay -- the MRE was right there in the error I posted, but admittedly it's not easy to read since you have to replace \n
with newlines and \"
with "
. Here is the extracted code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;
contract SendFunction {
function send(address to) external payable {
(bool success, bytes memory data) = to.call{value: msg.value}("x");
if (!success) {
revert(string(data));
}
}
}
Just compile and deploy this contract, and call send(someNonexistentAddress)
.
The transaction reverts with no data, since call
fails to find anything at the address. (Additionally even if there's a contract at the address, "x"
is not a correctly ABI-formatted payload.) This causes Hardhat to give the very long and cryptic error message shown, rather than actually extracting the stacktrace that is given in the error message, and displaying it as a normal stacktrace.
(Actually I now see there's an error in the code too, it should say revert(data)
rather than revert(string(data))
, but that doesn't affect the outcome.)
same issue here, I have to add gasLimit to see the errors
I have 20k lines of errors reported which makes debuging nearly impossible, is it possible to turn off estimate gas functionality?
I ran the reproduction steps provided by @lukehutch with the latest versions of hardhat, ethers and hardhat-ethers and I'm not running into this problem anymore. I believe this was happening with some older combination of Hardhat+ethers.js, but I believe we've fixed it since then.
@GopherJ are you using the latest version of each of those packages? If so, and if you are still having this problem, could you provide a minimal reproducible example?
I see that you've opened a new issue about that, so I'm going to close this one and we can continue discussing this in #3444.