Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract revert reasons can mimic node errors #2954

Open
fvictorio opened this issue May 2, 2022 · 7 comments
Open

Contract revert reasons can mimic node errors #2954

fvictorio opened this issue May 2, 2022 · 7 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@fvictorio
Copy link

Ethers Version

5.6.4

Search Terms

insufficient funds, insufficient funds for intrinsic transaction cost, error message

Describe the Problem

Given a contract with a require like this one:

require(false, "Insufficient funds")

Ethers will (wrongly) say that the error was "Error: insufficient funds for intrinsic transaction cost"

I guess there's some pattern matching going on with the returned error message.

This happens even with the hardhat network when a correct data is returned with the encoded error string.

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

@ricmoo
Copy link
Member

ricmoo commented May 2, 2022

Thanks! I’ll look into this asap.

@ricmoo ricmoo changed the title Bug Report Title Contract revert reasons can mimic node errors May 2, 2022
@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels May 12, 2022
@ricmoo
Copy link
Member

ricmoo commented May 14, 2022

This has been fixed in 5.6.6. Try it out and let me know if you still have any issues.

Thanks! :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels May 14, 2022
@fvictorio
Copy link
Author

I think this is working correctly when the gas is estimated, but the same problem shows up if you set a specific gas limit in the overrides 😢

@ricmoo
Copy link
Member

ricmoo commented May 17, 2022

I thought I tried that too? I’ll test it out again shortly.

@ricmoo
Copy link
Member

ricmoo commented May 18, 2022

I just tried out all combinations of "view" vs. "send" and "with" vs "without" a gasLimit, and all returned the appropriate error (CALL_EXCEPTION or UNPREDICTABLE_GAS_LIMIT, depending); none returned the mimicked INSUFFICIENT_FUNDS error.

Can you provide an example?

@fvictorio
Copy link
Author

It happens when using Hardhat's node, but it does not happen with geth --dev. I don't know why.

One difference I noticed is that, when using geth, I have to do:

const tx = await contract.f({ gasLimit: 1_000_000 }) // f reverts with "Insufficient funds" as its revert reason
await tx.wait()

But when using Hardhat's node, the transaction reverts immediately (before reaching tx.wait).

I should clarify that, while I'm using Hardhat's node, I'm running a script with plain ethers (no hardhat-ethers involved).

Does that help? I think it's just a matter of doing the tests you did but using Hardhat's node, but here's the script I used just in case:

const ethers = require("ethers");

async function main() {
  const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545")
  // private key of hardhat's second default account
  const signer = new ethers.Wallet("0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", provider)
  // address where I deployed the Foo contract, see below
  const contract = new ethers.Contract("0x8464135c8F25Da09e49BC8782676a84730C318bC", ['function f() public'], signer)

  const tx = await contract.f({ gasLimit: 1_000_000 });

  await tx.wait()
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

and the contract:

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

contract Foo {
  function f() public {
    require(false, "Insufficient funds");
  }
}

@se3000
Copy link

se3000 commented Aug 4, 2022

Just ran into this. The code has been unchanged for years. The tests have gone through some tooling changes over the years, but are mostly unchanged. Started failing when we bumped to the latest version of hardhat.

AssertionError: Expected transaction to be reverted with insufficient funds for payment, but other exception was thrown: Error: insufficient funds for intrinsic transaction cost [ See: https://links.ethers.org/v5-errors-INSUFFICIENT_FUNDS ] (error={"stackTrace":[{"type":4,"sourceReference":{"function":"updateFutureRounds","contract":"FluxAggregator","sourceName":"src/v0.6/FluxAggregator.sol","sourceContent":"...","line":263,"range":[9007,9108]},"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,30,105,110,115,117,102,102,105,99,105,101,110,116,32,102,117,110,100,115,32,102,111,114,32,112,97,121,109,101,110,116,0,0]},"_selector":"08c379a0"},"isInvalidOpcodeError":false}],"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e696e73756666696369656e742066756e647320666f72207061796d656e740000","transactionHash":"0x9bfe504c7424e176106affd152054a953f18c187db02f0da032c8fca4666a7e8"}, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS, version=providers/5.6.8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

3 participants