returnHighestBidder is used in checking who the winner is, however the code
implemented in doing this was flawed as it missed updating highBid variable
for the current higest bid found so far before next iteration. Missing this
would cost function to simply return whoever was the last valid bidder
which is not what's intended
Proof of Concept
AuctionDemo:returnHighestBidder()
function returnHighestBidder(uint256 _tokenid) public view returns
(address) {
uint256 highBid = 0;
uint256 index;
for (uint256 i=0; i< auctionInfoData[_tokenid].length; i++) {
if (auctionInfoData[_tokenid][i].bid > highBid &&
auctionInfoData[_tokenid][i].status == true) {
index = i; // @audit-issue missing highBid update
}
}
if (auctionInfoData[_tokenid][index].status == true) {
return auctionInfoData[_tokenid][index].bidder;
} else {
revert("No Active Bidder");
}
}
Tools Used
Manaul Review
Recommended Mitigation Steps
Change function to account for the bid amount
function returnHighestBidder(uint256 _tokenid) public view returns
(address) {
uint256 highBid = 0;
uint256 index;
for (uint256 i=0; i< auctionInfoData[_tokenid].length; i++) {
if (auctionInfoData[_tokenid][i].bid > highBid &&
auctionInfoData[_tokenid][i].status == true) {
index = i;
+ highBid = auctionInfoData[_tokenid][i].bid;
}
}
if (auctionInfoData[_tokenid][index].status == true) {
return auctionInfoData[_tokenid][index].bidder;
} else {
revert("No Active Bidder");
}
}
Lines of code
https://github.com/code-423n4/2023-10-nextgen/blob/main/hardhat/smart-contracts/AuctionDemo.sol#L92
Vulnerability details
Impact
returnHighestBidder is used in checking who the winner is, however the code implemented in doing this was flawed as it missed updating highBid variable for the current higest bid found so far before next iteration. Missing this would cost function to simply return whoever was the last valid bidder which is not what's intended
Proof of Concept
AuctionDemo:returnHighestBidder()
Tools Used
Manaul Review
Recommended Mitigation Steps
Change function to account for the bid amount
Assessed type
Other