Skip to content
Race condition Audit finding Intermediate

Bidders might lose funds due to possible racing condition between settleWithBuyout and placeBid

The settleWithBuyout and placeBid functions can both be called at the same timestamp, allowing a bidder to place a bid that is then ignored when settleWithBuyout executes, causing the bidder to lose their funds.

oakcobalt Follow with oakcobalt

Originally disclosed on Code4rena

Submitted by oakcobalt, also found by oakcobalt

In AuctionWithBuyoutLoanLiquidator.sol, settleWithBuyout and placeBid are allowed at an overlapping timestamp (_auction.startTime + _timeForMainLenderToBuy). This allows settleWithBuyout and placeBid to be settled at the same block.

When placeBid tx settles at _auction.startTime + _timeForMainLenderToBuy before settleWithBuyout tx, the bidder will lose their funds. Because settleWithBuyout will always assume no bids are placed, it will directly transfer out the collateral NFT token and delete the auction data from storage.

    function settleWithBuyout(
        address _nftAddress,
        uint256 _tokenId,
        Auction calldata _auction,
        IMultiSourceLoan.Loan calldata _loan
    ) external nonReentrant {
...
        uint256 timeLimit = _auction.startTime + _timeForMainLenderToBuy;
 |>       if (timeLimit < block.timestamp) {
            revert OptionToBuyExpiredError(timeLimit);
        }
...

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/AuctionWithBuyoutLoanLiquidator.sol#L63C1-L66C10

    function _placeBidChecks(address _nftAddress, uint256 _tokenId, Auction memory _auction, uint256 _bid)
        internal
        view
        override
    {
...
        uint256 timeLimit = _auction.startTime + _timeForMainLenderToBuy;
|>        if (timeLimit > block.timestamp) {
            revert OptionToBuyStilValidError(timeLimit);
        }

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/AuctionWithBuyoutLoanLiquidator.sol#L129

Recommended Mitigation Steps

Consider to only allow buyout strictly before the timeLimit if (timeLimit <= block.timestamp) {//revert.

0xend (Gondi) confirmed

Gondi mitigated:

Strict to >=.

Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.


The original report as published on Code4rena, by oakcobalt. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The time check in settleWithBuyout uses a strict less-than comparison, while placeBid uses a strict greater-than comparison, so both allow the exact boundary timestamp.

Impact

A bidder could lose their bid funds if their transaction is settled just before the buyout settlement at the overlapping timestamp.

What the attacker needed

Auction reaches the exact boundary timestamp; Bidder places bid at that timestamp; Buyout settles after the bid in the same block

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In this auction contract, there is a time window where two different actions are allowed at the exact same moment. If a bidder places a bid at that moment, but the seller's buyout action happens first, the bidder's money is taken but they get nothing because the auction is closed and the collateral is transferred away.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by oakcobalt

View all

50 more disclosed reports, best first.

More from Gondi Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.