forked from Cyfrin/aderyn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendEtherNoChecks.sol
103 lines (70 loc) · 1.81 KB
/
SendEtherNoChecks.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
////// GOOD ////////////////
contract SendEtherNoChecks2 {
function callAndSendNativeEth(address x) internal {
(bool success,) = x.call{value: 10}("calldata");
if (!success) {
revert();
}
}
modifier mod1(address x) {
callAndSendNativeEth(x);
_;
}
// Start Here
function func1(address x) external mod1(x) {
func2();
}
function func2() internal view {
require(msg.sender == address(0x11));
}
}
/////////// BAD ///////////////
// Sending eth from func1 in the following contracts is not safe because there is no check on any address
// before sending native eth.
/// BAD
contract SendEtherNoChecks3 {
function callAndSendNativeEth(address x) internal {
(bool success,) = x.call{value: 10}("calldata");
if (!success) {
revert();
}
}
modifier mod1(address x) {
callAndSendNativeEth(x);
_;
}
// Start Here
function func1(address x) external mod1(x) {
}
}
// BAD
contract SendEtherNoChecks4 {
uint256 public constant BAL = 100;
function transferBalance(address x) internal {
payable(x).transfer(BAL);
}
modifier mod1(address x) {
transferBalance(x);
_;
}
// Start Here
function func1(address x) external mod1(x) {
}
}
// BAD
contract SendEtherNoChecks5 {
uint256 public constant BAL = 100;
function sendBalance(address x) internal {
(bool success) = payable(x).send(BAL);
require(success, "Unable to send balance");
}
modifier mod1(address x) {
sendBalance(x);
_;
}
// Start Here
function func1(address x) external mod1(x) {
}
}