1

Deleting element from mapping exceeds block gas limit. I tried to increase gas limit to 10 millions, but there is no results

There is mapping:

mapping(address => bool) isSomebody;

There is function for deleting:

function deleteSomebody(address _address) {
    delete isSomebody[_address];
}

I also tried this variant:

function deleteSomebody(address _address) {
    isSomebody[_address] = false;
}

The most interesting, if i try to set isSomebody[_address] = true it works

P.S I use Remix

  • I can't reproduce this. Using your exact code (either function), each takes 26924 gas when passing in the address 0x0000000000000000000000000000000000000000000000000000000000000000. Can you share the exact message you see? A gas limit of 10 million would exceed the block gas limit, so don't do that. Set it to something like 100,000. – smarx Feb 7 '18 at 21:51
  • @smarx - You can reproduce this by using "Web3 Provider" environment in Remix while running TestRPC. – Adam Kipnis Feb 7 '18 at 21:55
  • Nope, can't reproduce this using the current version of ganache-cli either. @AdamKipnis – smarx Feb 7 '18 at 21:58
1

I think you're hitting a bug when using Remix with TestRPC (I'm assuming that's your node setup) having to do with low gas consumption causing issues. I wrote up an answer to this within the context of a longer question here (look about half way down).

To summarize - If you try to execute a transaction in which the estimated gas is below the 21000 minimum, Remix with TestRPC will fail. I'm not sure if this is an issue with Remix or with TestRPC. Either Remix doesn't send the gas limit to TestRPC (even though you are entering it in the Remix UI), and/or TestRPC's estimate gas is not returning a good estimate (at the very least, it shouldn't return less than 21000).

The reason why setting the bool to true works but delete/setting to false does not is because storing a non-zero value (true) to the state costs 20000 gas whereas setting it to the initial value either by explicitly setting it to false or by using delete (it's the same operation) only costs 5000 gas.

EDIT - Steps to reproduce:

1) Use this contract in Remix:

pragma solidity ^0.4.19;

contract Test {
    mapping(address => bool) isSomebody;

    function addSomebody(address _address) public {
        isSomebody[_address] = true;
    }

    function deleteSomebody(address _address) public {
        delete isSomebody[_address];
    }
}

2) Start TestRPC

3) Change Environment in Remix to "Web3 Provider" and connect to localhost.

4) Deploy the contract, call addSomebody, then delete the added address through deleteSomebody.

5) Tx will fail:

transact to Test.deleteSomebody pending ...  

transact to Test.deleteSomebody errored: Error: base fee exceeds gas limit
        at runCall (C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:69361:17)
        at C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:11327:24
        at replenish (C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:8420:17)
        at iterateeCallback (C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:8405:17)
        at C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:8380:16
        at C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:11332:13
        at C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:64434:16
        at replenish (C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:64381:25)
        at C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:64390:9
        at eachLimit (C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:64314:36)
        at C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:65494:16
        at VM.AsyncEventEmitter.emit (C:\Users\adamk\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:64085:3)

EDIT #2: From github.com/ethereumjs/ethereumjs-vm/issues/257:

When you clear storage you get gas refund, so, when ganache executes eth_estimateGas the estimated gas considers the gas refund and at the end the total gas is less than the base fee, this is why when executing the real transaction with a low gas limit ethereumjs-vm is throwing that error.

  • Your other answer pertains to an out of gas exception, while this seems to be about exceeding the block gas limit. Were you actually able to reproduce any sort of error with the provided code? If so, what error did you see? – smarx Feb 7 '18 at 22:01
  • Updated with steps I took. I should note that I am NOT on the latest version of TestRPC, so it may have bee fixed. – Adam Kipnis Feb 7 '18 at 22:15
  • Thanks; I'm able to reproduce that error following your repro steps with the current ganache-cli. – smarx Feb 7 '18 at 22:18
  • Thanks @smarx. Looks like my suspicion on the root cause is somewhat correct. Relevant comment: "When you clear storage you get gas refund, so, when ganache executes eth_estimateGas the estimated gas considers the gas refund and at the end the total gas is less than the base fee, this is why when executing the real transaction with a low gas limit ethereumjs-vm is throwing that error." – Adam Kipnis Feb 7 '18 at 22:42

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.