cgewecke / hardhat-gas-reporter

Gas Usage Analytics for Hardhat
MIT License
412 stars 57 forks source link

delete keyword only increses gas cost #118

Closed migoldfinger closed 7 months ago

migoldfinger commented 2 years ago

Hello,

I think I found something strange Based on the documentation when I use delete on contract variables gas should be refunded. I tested this with the following function

function die() override public
    {
        require(block.number > _finalBlock, "Pulsar: Can only be killed after final block"); // solhint-disable-line reason-string
        uint256 remainingAmount = _token.balanceOf(address(this));
        _token.burn(remainingAmount);
        delete _amountPhase1;
        delete _amountPhase2;
        delete _amountPhase3;
        delete _amountPhase4;
    }

The deleted values are private uint256. The Function without the 4 delete statements uses 29946 gas after adding the delete statemens the function uses 45972 gas, and that seems wrong.

cgewecke commented 7 months ago

Apologies for the delay responding to this. I highly recommend this guide to gas consumption at wolfio for a window onto how the gas accounting works.

https://github.com/wolflo/evm-opcodes/blob/main/gas.md

The gas-reporter has no influence on what the gas consumption is ... it just reads and sorts receipts.