I am working with the following function and state vars:

struct TimeRestriction {
   uint256 fromTime;
   uint256 toTime;

mapping (address => TimeRestriction) public whitelist;

function modifyWhitelist(address _investor, uint256 _fromTime, uint256 _toTime) public withPerm(WHITELIST) {

    //Passing a _time == 0 into this function, is equivalent to removing the _investor from the whitelist

    whitelist[_investor] = TimeRestriction(_fromTime, _toTime);
    emit LogModifyWhitelist(_investor, now, msg.sender, _fromTime, _toTime);

I can currently call into this function successfully, and write to the blockchain. I can even call into it and update the values to any timestamp. But for some strange reason when I try to pass 0 values to this function, it will fail. I get the following error:

Error: Transaction dry run failed: Invalid JSON RPC response: {"id":470,"jsonrpc":"2.0"} .

Then when I dug into it some more I got this error:

Error:Returned error: base fee exceeds gas limit.

Then by increasing the tx gas amount by 25%, I see:

Error:Returned error: VM Exception while processing transaction: out of gas

And then when I increase the tx gas amount by 100%, it actually works. (note that I am using the web3 estimate gas function from web3 1.0.0-beta.30)

Does anyone know what is going on here? It seems to me like setting these values to zero is costing significantly more gas, but from reading up it seems that setting to zero is supposed to refund gas, and cost you less.

Does it have something to do with it being a struct inside of a mapping? I have hit a dead end here

Here is my environment: Ganache CLI v6.1.0 (ganache-core: 2.1.0) Chrome Version 65.0.3325.181 Truffle version 4.1.3^


I tracked it down, see a detailed list of issues from ganache, geth, and metamask here: https://github.com/PolymathNetwork/polymath.js/issues/6

But basically, ganache does not use the binary search for gas estimate that geth and metamask do. The gas estimate returns the actual gas estimate, which is lower, because of the refund. However the EVM requires you still send gasEstimated + gasRefunded with the transaction, and then you get it refund when it is completed.

So ganache ends up estimating a correct value with refund implemented, but the EVM doesn't won't accept that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.