The following code is part of a Smart Contract I'm working with:

   function noComplain() allowed(receiver, stage.keyRevealed) public {

    // function complain about wrong hash of file
    function complainAboutRoot(bytes32 _Zm, bytes32[depth] memory _proofZm) allowed(receiver, stage.keyRevealed) public {
        require (vrfy(2 * (n - 1), _Zm, _proofZm));
        require (cryptSmall(2 * (n - 1), _Zm) != fileRoot);

As you can see, there are multiple contract methods calling selfdestruct. I would expect that only a single call to e.g. noComplain would be allowed, since the the contract should be destroyed after that (yeah, I know, the code is still there, but the state should be lost etc, right?).

When working with the contract, I discovered that I can call complainAbouRoot after noComplain, also vice versa and even noComplain multiple times without getting an error (tx receipt says "status=1").

How can that be? How can I discover if a smart contract has been destroyed? What is selfdestruct actually good for if it doesn't block further calls?

  • I was testing a simplified version of this in Remix and seems that subsequent transactions succeed even if the contract has been self-destroyed - the transactions just don't do anything. You can see this by adding events and see that they don't get emitted after the contract has been destroyed. I'm really not sure why the subsequent transactions succeed. – Lauri Peltonen May 20 at 5:54

As Laurie mentioned, the effect of selfdestruct() is that it creates a void. Users and contracts may think there is a contract there (because there was) and they may assume that success means the functions worked as expected, but ...

As you have discovered on your own, calling the non-existent function in the non-existent contract returns true because there is nothing to do. I would discourage the use of selfdestruct because there are better patterns in almost all cases.

Have a look at this explainer: https://blog.b9lab.com/selfdestruct-is-a-bug-9c312d1bb2a5

Hope it helps.

| improve this answer | |

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.