Last active
December 26, 2023 22:50
-
-
Save minaminao/f282f365b8e5be71842825b94b4a5949 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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