Skip to content

Instantly share code, notes, and snippets.

@minaminao
Last active December 26, 2023 22:50
Show Gist options
  • Save minaminao/f282f365b8e5be71842825b94b4a5949 to your computer and use it in GitHub Desktop.
Save minaminao/f282f365b8e5be71842825b94b4a5949 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
contract SelfDestructSuccessTest is Test {
function testSecure() public {
Secure secure = new Secure();
Exploit exploit = new Exploit();
secure.f{value: 1 ether}(address(exploit));
}
}
contract Secure {
function f(address target) public payable {
(bool success,) = target.call{value: msg.value}("");
require(success); // `true` even if `selfdestruct` is used
}
}
contract Exploit {
fallback() external payable {
selfdestruct(payable(address(0)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment