-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample13.sol
More file actions
26 lines (21 loc) · 919 Bytes
/
Copy pathexample13.sol
File metadata and controls
26 lines (21 loc) · 919 Bytes
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
pragma solidity ^0.4.21;
contract Reentrancy {
mapping (address => uint) private userBalances;
function withdrawBalance() public {
uint amountToWithdraw = userBalances[msg.sender];
require(msg.sender.call.value(amountToWithdraw)()); // At this point, the caller's code is executed, and can call withdrawBalance again
userBalances[msg.sender] = 0;
}
function withdrawBalanceSafer() public {
uint amountToWithdraw = userBalances[msg.sender];
userBalances[msg.sender] = 0;
require(msg.sender.call.value(amountToWithdraw)()); // The user's balance is already 0, so future invocations won't withdraw anything
}
function withdrawBalanceLocalMod() public {
uint amountToWithdraw = userBalances[msg.sender];
uint local_count;
userBalances[msg.sender] = 0;
require(msg.sender.call.value(amountToWithdraw)());
amountToWithdraw = 0;
}
}