-
Notifications
You must be signed in to change notification settings - Fork 0
/
testreentrancy.sol
43 lines (37 loc) · 1.06 KB
/
testreentrancy.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
contract Crowdsale { function echidna_alwaystrue() public returns (bool) { return(true); }
uint256 goal = 10000 * 10**18;
uint256 raised = 0;
uint256 closeTime;
address owner;
mapping(address => uint256) deposits;
uint256 phase; // 0: active, 1: success, 2: refund
constructor() public {
closeTime = now + 30 days;
owner = msg.sender;
}
function invest() public payable {
require(phase == 0 && raised < goal);
deposits[msg.sender] += msg.value;
raised += msg.value;
}
function setPhase(uint256 newPhase) public {
require((newPhase == 1 && raised >= goal) ||
(newPhase == 2 && raised < goal
&& now >= closeTime));
phase = newPhase;
}
function setOwner(address newOwner) public {
// require(msg.sender == owner);
owner = newOwner;
}
function withdraw() public {
require(phase == 1);
owner.transfer(raised);
}
function refund() public {
// require(phase == 2);
raised += msg.value;
msg.sender.transfer(deposits[msg.sender]);
deposits[msg.sender] = 0;
}
}