Starknet Auction

First Flight #26
Beginner FriendlyNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Bid Amount Overwritten on Multiple Bids

Description:

  • Location in Code: The bid function.

  • When a bidder places multiple bids, their previous bid amount is overwritten in the bid_values mapping.

  • Bidders can only withdraw their last bid amount, losing previous bids if they are not the highest bidder.

Impact:

  • Bidders lose funds from previous bids if they do not win.

  • Discourages participation, affecting the competitiveness of the auction.

Proof of Code:

fn bid(ref self: ContractState, amount: u64) {
// ...
// Overwrites previous bid amount
self.bid_values.entry(sender).write(amount);
// ...
}

Recommendation:

  • Accumulate total bid amounts for each bidder to ensure they can withdraw the full amount if they lose.

  • Modify the bid function to sum the bids.

Corrected Code:

fn bid(ref self: ContractState, amount: u64) {
// ...
let previous_bid = self.bid_values.entry(sender).read();
let total_bid = previous_bid + amount;
self.bid_values.entry(sender).write(total_bid);
// ...
}
Updates

Lead Judging Commences

bube Lead Judge 9 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Wrong bid amount in `bid` function

In the `bid` function the bid values are stored using `self.bid_values.entry(sender).write(amount)` directly, but this overwrites any previous bids made by the same bidder. Therefore if a participant makes 2 or more bids, the participant can then withdraw only the last value of the last bid. That is incorrect, the protocol should save all bids and a participant should withdraw the value of the all unsuccessful bids.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.