Related to #592
When creating a "Factory" pattern contract and call a function of the newly created contract directly, the transaction is REVERTED
The transaction should not fail and execute correctly. (Remix VM works!)
Transaction REVERT's
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
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!
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.