2

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

[...]
   function noComplain() allowed(receiver, stage.keyRevealed) public {
        selfdestruct(sender);
    }

    // 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);
        selfdestruct(receiver);
    }
[...]

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?

1
  • 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. Commented May 20, 2020 at 5:54

1 Answer 1

1

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.

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.