Categories
Cryptocurrency Ethereum Mastering Development

Why can I call contract methods containing a selfdestruct multiple times?

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?

Leave a Reply

Your email address will not be published. Required fields are marked *