Today I learned about EIP-6780, probably the best approach to removing SELFDESTRUCT from the EVM.
I'll explain what it's supposed to do and how it affects current and future smart contracts, and share example code to illustrate when it works as expected and when it doesn't.
You can find the link below if you want to go through the EIP yourself.
However, this thread explains everything you need to know about its mechanics.
eips.ethereum.org/EIPS/eip-6780
It's important to understand how SELFDESTRUCT works right now.
SELFDESTRUCT:
- executes in the context of a contract (account with code)
- executes as `selfdestruct(receiver)`
- transfers all ether (not tokens) to the `receiver`
- removes all storage and code
EIP-6780 modifies SELFDESTRUCT to behave the same ONLY if the executing contract was created in the same transaction.
Because of how it behaves, we can refer to EIP-6780 as "Conditional SELFDESTRUCT".
If SELFDESTRUCT is executed in a different transaction, it will behave differently:
- will not delete storage or code
- transfers all ether to `receiver`
EIP-4758 is another proposal to change SELFDESTRUCT and has a different approach.
It wants to change SELFDESTRUCT to a SENDALL operation, effectively not removing any storage or code.
Its purpose is to transfer all ether to the `receiver` while retaining code and storage.
Because both approaches want to change the SELFDESTRUCT opcode, only one will be included in the next Ethereum upgrades.
I assume that EIP-6780 Conditional SELFDESTRUCT will be accepted because it retains the code and storage removal feature.
Snippet code created to explain the behavior of new EIP.
There is a weird quirk with how Ethereum works right now, and I honestly don't know if this will be changed when 6780 goes live.
Can you identify it? Can you explain it?
gist.github.com/cleanunicorn/b0a108a38c8bf0c9542e0c76e0e8342c