Solidity – Practical Use Cases for ‘Self-destruct’ in Smart Contracts

contract-designerasure-codesselfdestruct

According to solidity.readthedocs.io (Link) here is the definition of Self-destruct:

"Definition: The only way to remove code from the blockchain is
when a contract at that address performs the Selfdestruct operation.
The remaining Ether stored at that address is sent to a designated
target and then the storage and code is removed from the state."

While this definition sounds allowing possibility of erasure feature (that is one of the main challenges of incompatibility of GDPR (General Data Protection Regulation) with the blockchain. (Link to Right to erasure in GDPR)); however after definition of Self-destruct , there are following Note and Warning:

"Note: Even if a contract’s code does not contain a call to
Selfdestruct, it can still perform that operation using
delegatecall or callcode."

"Warning: Even if a contract is removed by Selfdestruct, it is
still part of the history of the blockchain and probably retained by
most Ethereum nodes. So using Selfdestruct is not the same as
deleting data from a hard disk."

What does exactly Self-destruct give us and how can it help us ?

Best Answer

First, a small correction. Everything is not reversible, you can't reverse a self-destruct. The quote simply means that the data still exists in the blockchain history even if the contract wouldn't exist anymore in the latest block. So no data is ever removed from the blockchain (history).

I can think of at least a few use cases for self-destruct:

1) When a contract is no longer needed, you can self-destruct it. This way you can be sure nobody can send transactions to it and nobody can interact with it. Even if the contract itself is rendered useless by code (by updating some status variable for example), there may be for example security holes left in it.

2) Force the contracts' users to start using a new contract as the old one simply doesn't exist anymore. For example when you are switching from an old token contract to a new one.

3) A "last resort" backdoor to a contract. If the contract doesn't work as you thought it would and you have included functionality for selfdestruct, you can just remove it and create a better one.

Related Topic