trufflesuite / ganache-cli-archive

Fast Ethereum RPC client for testing and development. See https://github.com/trufflesuite/ganache for current development.
https://www.trufflesuite.com/ganache
MIT License
3.36k stars 697 forks source link

eth_estimateGas inaccurate gas estimation under specific circumstances (attached Solidity sample). #592

Closed Enigmatic331 closed 5 years ago

Enigmatic331 commented 5 years ago

Current Behavior

With the below Solidity code, running eth_estimateGas on Ganache returns a slightly lower gas estimate compared to client implementations, subsequently during the execution of the code an out of gas error is encountered.

Expected Behavior

In both cases client implementations provided a gas estimate of 28579, slightly higher than what is consumed at 28537; Whereas Ganache CLI provided an estimate of exactly 28537. Suspect it might be something to do with gas refunds (where Ganache CLI returns the gas estimates based off the final gas used post-transaction, instead of the highest gas used during the transaction).

Steps to Reproduce (for bugs)

Solidity Code:

pragma solidity ^0.4.24;

contract BulkContract {

    address public balanceAddress;

    constructor() public {
        balanceAddress = new balanceContract();
    }

    function transaction() public {
        balanceContract t = balanceContract(balanceAddress);
        t.execute();
    }
}

contract balanceContract {

    // setting variable to non-zero
    // so we can work on a consistent gas limit from the get-go
    uint256 public counter = 1;

    constructor() public { }

    function execute() public {
        counter = counter + 1;
    }
}



Running estimates through Ganache CLI: Estimated gas amount isn't sufficient to complete transaction. image


Comparing this through a private testnet (Geth 1.8.2): image


Comparing this through Rinkeby: image

Your Environment

Feel free to let me know if you'd like any additional information at all. Thanks in advance - And thanks for the Truffle suite! :D

davidmurdoch commented 5 years ago

This should now be fixed in the latest beta tagged releases of ganache-cli and ganache-core.

This fix involved pretty significant code changes; check out the release notes for details.

We'd love it if you'd test this beta out to make sure things are good to go before we release to stable.

If you using ganache-cli, run:

npm install -g ganache-cli@beta

If you are using ganache-core, run:

npm install ganache-core@beta

Let us know if you discover any bugs with this new beta release! Thanks!

S3bb1 commented 5 years ago

Hi, sorry reopen this ticket. But trying out the above example still gives me a "Revert". Tested with ganache cli 6.4.4-beta.0

eth_sendTransaction

  Transaction: 0x9bb3f74771f1778dfa567fe33039014f4a3586bb8ea7cc55c5546a622ef8d75c
  Contract created: 0x3edd854c5fc429043a1ed2bbc8d656614f216732
  Gas usage: 180460
  Block Number: 1
  Block Time: Tue May 07 2019 07:23:21 GMT+0200 (GMT+02:00)
  Runtime Error: revert
Enigmatic331 commented 5 years ago

Hey Sebastian :)

I tested the examples above on v6.4.3 and v6.4.4-beta but seems to work fine though (much thanks to the Truffle team!) - Or I misunderstood and it was something else you were running?

image

S3bb1 commented 5 years ago

Hey Enigma :)

Thanks for your response! I've tested the contract in the issue ticket with Remix:

image

Before i ran ganache-cli without any arguments and i see the following response:

image

Enigmatic331 commented 5 years ago

Ah you're absolutely right Sebastian. I tested via Remix (also through Remix > Metamask on localhost:8545) and gotten the same issue too.

Looks like it might be reverting at the part where the contract attempts to create another contract - Will see if I could find anything, and open an issue later in the morning.

ADD: Yea... Had to manually increase the gas limit from its original estimates when I was on Metamask...

image

Transaction gas use:

image

S3bb1 commented 5 years ago

got it to work :) i've found another bug for the REVERT stuff from my private factory. I'll open another ticket