require(msg.sender != previousBidder, "Already highest bidder");
emit AuctionSettled(tokenId, msg.sender, listing.seller, msg.value);
uint256 timeLeft = 0;
if (listing.auctionEnd > block.timestamp) {
timeLeft = listing.auctionEnd - block.timestamp;
}
@> if (timeLeft < S_AUCTION_EXTENSION_DURATION) {
listing.auctionEnd =
listing.auctionEnd +
@> S_AUCTION_EXTENSION_DURATION;
emit AuctionExtended(tokenId, listing.auctionEnd);
}
}
function test_ExcessiveAuctionDuration() public {
_mintNFT();
_listNFT();
uint256 extensionDuration = market.S_AUCTION_EXTENSION_DURATION();
console.log("=== EXCESSIVE AUCTION DURATION BUG ===");
console.log(
"Auction extension duration:",
extensionDuration,
"seconds (15 minutes)"
);
vm.prank(BIDDER_1);
market.placeBid{value: 2 ether}(TOKEN_ID);
BidBeastsNFTMarket.Listing memory listing = market.getListing(TOKEN_ID);
uint256 firstAuctionEnd = listing.auctionEnd;
console.log("First bid - Auction ends at:", firstAuctionEnd);
console.log(
"Time until end:",
firstAuctionEnd - block.timestamp,
"seconds"
);
vm.warp(firstAuctionEnd - 60);
vm.prank(BIDDER_2);
market.placeBid{value: 3 ether}(TOKEN_ID);
listing = market.getListing(TOKEN_ID);
uint256 secondAuctionEnd = listing.auctionEnd;
console.log(
"Second bid (1min before end) - New end:",
secondAuctionEnd
);
console.log(
"Time added:",
secondAuctionEnd - firstAuctionEnd,
"seconds"
);
console.log(
"Total auction duration so far:",
secondAuctionEnd - block.timestamp,
"seconds"
);
vm.warp(secondAuctionEnd - 600);
uint256 timeBeforeBid = block.timestamp;
vm.prank(BIDDER_1);
market.placeBid{value: 4 ether}(TOKEN_ID);
listing = market.getListing(TOKEN_ID);
uint256 thirdAuctionEnd = listing.auctionEnd;
vm.expectRevert("Auction has not ended");
market.settleAuction(TOKEN_ID);
console.log(
"settleAuction reverts - auction still active as long as there will be a new bidder... no limit"
);
}
// Add maximum auction duration constant
+ uint256 public constant S_MAX_AUCTION_DURATION = 24 hours; //Or more
// In placeBid function, modify the time extension logic:
} else {
// code here ....
if (timeLeft < S_AUCTION_EXTENSION_DURATION) {
// Calculate new end time with maximum duration limit
+ uint256 newEndTime = listing.auctionEnd + S_AUCTION_EXTENSION_DURATION;
+ uint256 maxAllowedEnd = listing.startTime + S_MAX_AUCTION_DURATION;
// Enforce maximum auction duration
+ if (newEndTime > maxAllowedEnd) {
listing.auctionEnd = maxAllowedEnd;
+ } else {
listing.auctionEnd = newEndTime;
+ }
emit AuctionExtended(tokenId, listing.auctionEnd);
}
}