1

I am trying with hardhat to simulate and see the gas refund. Here is my 2 smart contracts for testing purpose:

pragma solidity ^0.8.9;



contract DaughterContract{
   function destruct()public {
        address payable addr = payable(address(msg.sender));
        selfdestruct(addr);
    }

}

import "hardhat/console.sol";

contract TestContract {

 
 DaughterContract public lastSMBuilt;

uint256 myNum=0;

function createSmartContract() public returns (DaughterContract) {
     DaughterContract daughter = new DaughterContract();
     lastSMBuilt=daughter;
     return daughter;
}

function destroy() public {
     lastSMBuilt.destruct();
}

 function expensiveTxWithDestroy() public {

  destroy();
    for(uint i=0; i<1995;i++){
       myNum=i;
    }
    }
}

1/ I call createSmartContract 2/ Then I call expensiveTxWithDestroy

If I comment the destroy call inside expensiveTxWithDestroy the overall cost in gas is lower. So refund is not happening. Am I doing something wrong?

2 Answers 2

3

Gas refunds for selfdestruct were removed with EIP-3529 which was included in the London hardfork in 2021. Not seeing a refund for selfdestruct is expected behavior.

3
  • Why were Gas refunds removed with EIP-3529? Weren't they implemented to free up Network space?
    – Danny B
    Aug 9, 2022 at 15:17
  • 1
    It is well explained in link above: avoid exploit.
    – Stefdelec
    Aug 9, 2022 at 19:57
  • 1
    @DannyB That is why they were implemented, yet, but practically speaking gas refunds for selfdestruct was not encouraging the freeing up of network space. It was encouraging the speculation on gas prices (in an extremely inefficient manner) via GAS tokens
    – natewelch_
    Aug 10, 2022 at 1:38
2

Unfortunately they removed gas refunds because it was filling the blockchain with space-consuming gastokens and transactions just to get some cheap gas back, which is not liked by ethereum developers.

In my opinion it should have been kept because it helped people use some cheap gas, but that's no longer possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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