forked from crytic/not-so-smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_dos.sol
41 lines (34 loc) · 1.02 KB
/
list_dos.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
pragma solidity ^0.4.15;
contract CrowdFundBad {
address[] private refundAddresses;
mapping(address => uint) public refundAmount;
function refundDos() public {
for(uint i; i < refundAddresses.length; i++) {
require(refundAddresses[i].transfer(refundAmount[refundAddresses[i]]));
}
}
}
contract CrowdFundPull {
address[] private refundAddresses;
mapping(address => uint) public refundAmount;
function withdraw() external {
uint refund = refundAmount[msg.sender];
refundAmount[msg.sender] = 0;
msg.sender.transfer(refund);
}
}
//This is safe against the list length causing out of gas issues
//but is not safe against the payee causing the execution to revert
contract CrowdFundSafe {
address[] private refundAddresses;
mapping(address => uint) public refundAmount;
uint256 nextIdx;
function refundSafe() public {
uint256 i = nextIdx;
while(i < refundAddresses.length && msg.gas > 200000) {
refundAddresses[i].transfer(refundAmount[i]);
i++;
}
nextIdx = i;
}
}