-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdrawal-patterns
35 lines (28 loc) · 976 Bytes
/
withdrawal-patterns
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
// Write a function that will return funds to two investors, john and tatianna without using a for loop!
function returnFunds() public onlyOwner returns(bool success) {
tatiana.transfer(contributedAmount);
john.transfer(contributedAmount);
return true;
}
contract Victim {
function isItAContract() public view returns(bool) {
// if there bytes of code greater than zero then it is a contract!
uint32 size;
address a = msg.sender;
// inline assembly accesses EVM Ethereum Virtual Machine at a low level
assembly {
// extcodesize retrieves the size of the code
size := extcodesize(a)
}
return(size > 0);
}
}
contract Attacker {
bool public trickedYou;
Victim victim;
constructor(address _v) public {
victim = Victim(_v);
trickedYou = !victim.isItAContract();
}
}
// note: if you call the address from the constructor there are no byte codes