optimism icon indicating copy to clipboard operation
optimism copied to clipboard

EVM incompatibility when a contract selfdestructs and sends its balance to itself

Open maraoz opened this issue 3 years ago • 1 comments

Describe the bug I was playing around with Optimism yesterday and I found that if a contract selfdestructs and sends the remaining balance to itself, that balance remains on the contract after it is destroyed. This is different from the EVM behavior, which in that case leaves the contract with 0 balance, effectively destroying some ether.

I later found that @saurik already reports this on his "Attacking an Ethereum L2 with Unbridled Optimism" blog post. Maybe this EVM discrepancy should be added to Known Issues page on the docs? I don't think fixing it merits a hard fork, it seems inocuous.

To Reproduce Steps to reproduce the behavior:

  1. Deploy a contract that has some function which selfdestructs the contract sending remaining balance to itself. eg:
contract Suicidal {
    constructor() payable {
      selfdestruct(payable(address(this)));
    }
}
  1. Deploy that contract and execute the selfdestruct op.
  2. Check the contract's balance
  3. Should be 0, but it's not.

Expected behavior EVM equivalence would require this scenario to leave the contract with 0 balance.

maraoz avatar May 23 '22 22:05 maraoz

I agree that this should be included in Known Issues. Note that this will be fixed as part of the Bedrock upgrade. It's strongly recommended that you do not write contract logic based on this behavior, since it's not the expected behavior on Ethereum and will be removed in Bedrock.

smartcontracts avatar May 24 '22 07:05 smartcontracts