-
Notifications
You must be signed in to change notification settings - Fork 28
/
00-basic.sol
41 lines (30 loc) · 1.01 KB
/
00-basic.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Vulnerable {
mapping (address => uint256) balance;
mapping (address => bool) vip;
function deposit() external payable {
balance[msg.sender] += msg.value;
}
function withdrawAll() external {
// Checks!
require(balance[msg.sender] > 0, "Not enough funds");
// Interactions D: VULNERABLE!!
(bool success, ) = payable(msg.sender).call{value: balance[msg.sender]}("");
require(success, "Low level call failed");
// Effects :(
balance[msg.sender] = 0;
}
function withdrawSome(uint256 amount) external {
// Checks!
require(balance[msg.sender] >= amount, "Not enough funds");
// Interactions D: VULNERABLE!!... but exploitable?
(bool success, ) = payable(msg.sender).call{value: balance[msg.sender]}("");
require(success, "Low level call failed");
// Effects :(
balance[msg.sender] -= amount;
}
function userBalance (address _user) public view returns (uint256) {
return balance[_user];
}
}