Skip to content

Instantly share code, notes, and snippets.

@simon-something
Created December 8, 2021 13:23
Show Gist options
  • Save simon-something/4bd2f8e7e3ace37b348aa7a502bc64b4 to your computer and use it in GitHub Desktop.
Save simon-something/4bd2f8e7e3ace37b348aa7a502bc64b4 to your computer and use it in GitHub Desktop.
'selfdestruct but still working'
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Caller {
uint256 flag = 0;
event InsideBeforeDelegate();
event InsideAfterDelegate();
event OutsideAfterAllWtf();
function foo() external returns (uint256) {
flag++;
emit InsideBeforeDelegate();
address target = address(this);
(bool res, ) = target.delegatecall(abi.encodeWithSelector(Caller.bar.selector));
require(res, "FAIL_DELEGATE");
flag++;
emit InsideAfterDelegate();
this.lolz();
return flag;
}
function lolz() external {
require(msg.sender == address(this), "a la shaggy");
flag++;
emit OutsideAfterAllWtf();
}
event InsideBeforeDestruct();
event InsideAfterDestruct();
function bar() external {
flag++;
emit InsideBeforeDestruct();
selfdestruct(payable(address(0)));
flag++;
emit InsideAfterDestruct();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment