-
Notifications
You must be signed in to change notification settings - Fork 0
/
engAuctionRenentancyAttack.sol
68 lines (43 loc) · 1.34 KB
/
engAuctionRenentancyAttack.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
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract EnglishAuction{
address payable public seller;
uint256 public timeToEnd;
bool public running;
address public highestBidder;
uint public highestBid;
mapping(address => uint256) public deposits;
constructor(){
seller = payable(msg.sender);
}
function startAuction() public{
require(!running);
require(seller == msg.sender);
running = true;
timeToEnd = block.timestamp + 1 minutes;
}
function bid() public payable{
require(running);
require(msg.value > highestBid);
deposits[msg.sender] += msg.value;
//payable(highestBidder).transfer(highestBid);
highestBidder = msg.sender;
highestBid = msg.value;
}
function win() public{
require(running);
require(timeToEnd <= block.timestamp);
running = false;
seller.transfer(highestBid);
}
function takeOut() public {
require(msg.sender != highestBidder);
require(deposits[msg.sender]!=0);
(bool tryToSend,) = msg.sender.call{value: deposits[msg.sender]}("");
require(tryToSend);
deposits[msg.sender] = 0;
}
function getBalance() public view returns(uint256){
return deposits[msg.sender];
}
}