4

I read the Contract's state after a selfdestruct thread, but it doesn't answer the question whether you can selfdestruct multiple times.

2 Answers 2

6

It may depend on what your definition of "contract" is. :-)

Once a contract is selfdestructed, there is no code at that address anymore, so it can't execute a SELFDESTRUCT again.

However, due to the existence of CREATE2, you can now potentially deploy new code to the same address as the previous contract. That new code could contain a SELFDESTRUCT opcode. This means that the same address can run a SELFDESTRUCT multiple times, but whether it's really the same "contract" or not is a question of how you define that term.

-1

Update

As per Steven's comment below, you *cannot* sefldestruct more than once because no SELFDESTRUCT opcode will be executed again (there's no code at that address anymore).


Yes, you can, with a few caveats:

  1. During the first selfdestruct, the state of the contract is erased and will remain like that forever. You will be able to call the methods without reverting though.
  2. The Ether balance will only get depleted the first time.

Let's see it in action:

pragma solidity 0.5.11;

contract Counter {

    uint256 public counter;

    function increment() external {
        counter = counter + 1;
    }

    function doSelfDestruct() external {
        selfdestruct(0x0000000000000000000000000000000000000000);
    }

    function() external payable {}
}

Steps:

  1. Deploy the contract on Remix.
  2. Call increment.
  3. Read counter. Should be 1.
  4. Transfer Ether to the contract (set around 30,000 gas).
  5. Call doSelfDestruct.
  6. The Ether balance and its state should both be gone.
  7. Call increment again.
  8. Read counter. Should be 0.
  9. Repeat steps #3 and #4. The balance should not be transferred again.
2
  • 3
    Although I agree that the answer is "yes", this example doesn't seem right to me. The second time you attempt to call doSelfDestruct(), no actual SELFDESTRUCT opcode execute. You can send whatever data you want to the contract address, but because there's no longer any code, no code will be executed.
    – user19510
    Sep 21, 2019 at 21:21
  • Thanks @smarx I updated the answer Sep 22, 2019 at 9:56

Your Answer

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

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