-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestrictEoA.sol
41 lines (35 loc) · 1007 Bytes
/
RestrictEoA.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pragma solidity ^0.8.0;
contract test {
bool public hack;
//allow only EOA to interact, block contracts from calling
function try_to_hack() external {
uint256 size;
address addr = msg.sender;
assembly {
size := extcodesize(addr)
}
require(size == 0, "only EOA can access further");
hack = true;
}
//allow only EOA to interact, block contracts from calling
function try_to_hack_1() external {
require(tx.origin == msg.sender, "only EOA can access further");
hack = true;
}
function reset_variable() external {
//anyone can reset, we dont care
hack = false;
}
}
contract hacker {
constructor(address _addr) {
//possible to access !
test(_addr).try_to_hack();
//will revert
//test(_addr).try_to_hack_1();
}
function callTest(address _addr) external {
//will revert
test(_addr).try_to_hack();
}
}