I create a contract and implement a cleanup function like this

modifier ownerOnly {
    if(msg.sender != owner) revert();

function cleanup() public ownerOnly {
    if(!canDelete()) { //perform validations
        SelfDestructError("Invalid state. Cannot destruct");

Now my question is since my contract does not implement selfdestruct/suicide/kill method. Can someone still call the "selfdestruct" and take away any balance from this contract using delegateCall, I did see this and I think its not possible for some other contract to just call a selfdestruct on mine. I would like to know if what I understand is correct?

1 Answer 1


You should be safe as the cleanup method seems to be only executable by the owner of the contract (has the onlyOwner modifier, which I guess checks msg.sender == owner).

What the linked article refers to is the possibility of another contract inadvertently calling a function on a second contract (which contains a selfdestruct call) using delegatecall, in which case the contract that gets killed is the caller instead of the contract that contains the code, because of execution context.

If your contract is not calling a function on another contract, you should be fine.

If another contract used delegatecall to execute your cleanup function (and somehow bypassed the onlyOwner modifier) the contract that would get killed would be theirs and not yours as explained in the question you linked to.

  • Thanks, I have updated the question with the modifier. my concern was around someone being able to call selfdestruct on my contract because that's part of the protocol and do I need to do something to disable it or restrict it. Or is that an invalid concern after all? Nov 26, 2017 at 5:05

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.