Ganache-cli: REVERT opcode when calling a method of a created contract within a transaction

Created on 7 May 2019  路  7Comments  路  Source: trufflesuite/ganache-cli

Related to #592

When creating a "Factory" pattern contract and call a function of the newly created contract directly, the transaction is REVERTED

Expected Behavior

The transaction should not fail and execute correctly. (Remix VM works!)

Current Behavior

Transaction REVERT's

Steps to Reproduce (for bugs)

Code Sample:

pragma solidity ^0.4.24;

contract BulkContract {

    address public balanceAddress;

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

    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;
    }
}

when you create the BulkContract the constructor creates a new balanceContract and calls the execute method directly after the creation. The transaction fails with REVERT. In The OpCodes it seems that he checks if Code is available on the new contract and can't find the stuff on the address and fails:

last few lines of the opcodes

USH1
DUP8
DUP1
EXTCODESIZE 0xb930d93715ca899dab71f45b347068c61dea0e81
ISZERO 0x0
DUP1
ISZERO 0x1
PUSH2
JUMPI 0x0 0x9e
PUSH1
DUP1
REVERT 0x0 0x0

Your Environment

  • Version used: Ganache CLI v6.4.4-beta.0 (ganache-core: 2.5.6-beta.0)
  • Version of Truffle/Remix/Other tools used:
  • NodeJS Version: 11
bug

Most helpful comment

@S3bb1, thanks for the reminder ping! :-)

This is likely due to a gas estimation bug in Ganache-core. @nicholasjpaterno
is working on a fix now and one of us will follow up when we have a fix ready.

All 7 comments

ping? :)

@S3bb1, thanks for the reminder ping! :-)

This is likely due to a gas estimation bug in Ganache-core. @nicholasjpaterno
is working on a fix now and one of us will follow up when we have a fix ready.

Thx @davidmurdoch for the response. If you have any questions or need additional feedback, i will provide it :)

Thanks for your patience @S3bb1! Can you try testing again with this branch: https://github.com/trufflesuite/ganache-core/tree/gas-estimation ?

Thanks @nicholasjpaterno for the update. For the example contract it works now :) i will try it with a complex example and see if it works also :)

@S3bb1 Thanks for testing! Please let me know if you find a case where this is failing! Certain cases will always fail with any estimation logic: for example the state changes between the estimate and transaction or with certain contrived cases like branching on a condition like gasLeft - which of course changes between an estimate and the transaction itself. However, my hope is that this truly is an exact "estimate" now for all practical use cases. So while the estimate in many cases will be greater than the gasUsed, sending even 1 less unit of gas should result in a failure.

Closing this for now. Please reopen if this is in error!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kumavis picture kumavis  路  3Comments

ralph-pichler picture ralph-pichler  路  6Comments

DavidKuennen picture DavidKuennen  路  4Comments

leopoldjoy picture leopoldjoy  路  3Comments

redshark1802 picture redshark1802  路  4Comments