-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathReentrancy.sol
30 lines (24 loc) · 871 Bytes
/
Reentrancy.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
pragma solidity ^0.4.17;
contract SimpleDeposit {
mapping (address => uint) balances;
event LogDepositMade(address from, uint amount);
modifier minAmount(uint amount) {
require(msg.value >= amount);
_;
}
function SimpleDeposit() public payable {
balances[msg.sender] = msg.value;
}
function deposit() public payable minAmount(1 ether) {
balances[msg.sender] += msg.value;
LogDepositMade(msg.sender, msg.value);
}
function getBalance() public view returns (uint balance) {
return balances[msg.sender];
}
function withdrawBalance() public {
uint amount = balances[msg.sender];
require(msg.sender.call.value(amount)()); // caller's code is executed and can re-enter withdrawBalance again
balances[msg.sender] = 0; // INSECURE - user's balance must be reset before the external call
}
}