Skip to content
Business logic Audit finding Intermediate

Bidder Funds Can Become Unrecoverable Due to 1 second Overlap in participateToAuction() and claimAuction()

A bidder can place a bid at the exact second the auction ends, after the winner has already claimed the auction, causing the bidder's funds to become stuck in the contract with no way to refund them.

HChang26 Follow with immeas, sces60107 and 30 others

Originally disclosed on Code4rena

Submitted by HChang26, also found by immeas, sces60107, phoenixV110, Neon2835, tnquanghuy0512, c3phas, lsaudit, MrPotatoMagic, ayden, volodya, oakcobalt, Kow, DeFiHackLabs, t0x1c, xAriextz, ubl4nk, peanuts, oualidpro, 0x3b, 0xMAKEOUTHILL, merlin, 0xSwahili, innertia, mojito_auditor, 0xarno, Haipls, Eigenvectors, alexfilippov314, Nyx, ohm, Zac, and ABA

Lines of code

https://github.com/code-423n4/2023-10-nextgen/blob/main/smart-contracts/AuctionDemo.sol#L57 https://github.com/code-423n4/2023-10-nextgen/blob/main/smart-contracts/AuctionDemo.sol#L104

Impact

Bidder funds may become irretrievable if the participateToAuction() function is executed after claimAuction() during a 1-second overlap.

Proof of Concept

The protocol allows bidders to use the participateToAuction() function up to the auction’s end time.

    function participateToAuction(uint256 _tokenid) public payable {
      ->require(msg.value > returnHighestBid(_tokenid) && block.timestamp <= minter.getAuctionEndTime(_tokenid) && minter.getAuctionStatus(_tokenid) == true);
        auctionInfoStru memory newBid = auctionInfoStru(msg.sender, msg.value, true);
        auctionInfoData[_tokenid].push(newBid);
    }

However, the issue arises when an auction winner immediately calls claimAuction() right after the auction concludes, creating a 1-second window during which both claimAuction() and participateToAuction() can be executed.

    function claimAuction(uint256 _tokenid) public WinnerOrAdminRequired(_tokenid,this.claimAuction.selector){
      ->require(block.timestamp >= minter.getAuctionEndTime(_tokenid) && auctionClaim[_tokenid] == false && minter.getAuctionStatus(_tokenid) == true);
        auctionClaim[_tokenid] = true;
        uint256 highestBid = returnHighestBid(_tokenid);
        address ownerOfToken = IERC721(gencore).ownerOf(_tokenid);
        address highestBidder = returnHighestBidder(_tokenid);
        for (uint256 i=0; i< auctionInfoData[_tokenid].length; i ++) {
            if (auctionInfoData[_tokenid][i].bidder == highestBidder && auctionInfoData[_tokenid][i].bid == highestBid && auctionInfoData[_tokenid][i].status == true) {
                IERC721(gencore).safeTransferFrom(ownerOfToken, highestBidder, _tokenid);
                (bool success, ) = payable(owner()).call{value: highestBid}("");
                emit ClaimAuction(owner(), _tokenid, success, highestBid);
            } else if (auctionInfoData[_tokenid][i].status == true) {
                (bool success, ) = payable(auctionInfoData[_tokenid][i].bidder).call{value: auctionInfoData[_tokenid][i].bid}("");
                emit Refund(auctionInfoData[_tokenid][i].bidder, _tokenid, success, highestBid);
            } else {}
        }
    }

The issue arises when claimAuction() is executed before participateToAuction() within this 1-second overlap. In such a scenario, the bidder’s funds will become trapped in AuctionDemo.sol without any mechanism to facilitate refunds. Both cancelBid() and cancelAllBids() functions will revert after the auction’s conclusion, making it impossible for bidders to recover their funds.

Recommended Mitigation Steps

    function participateToAuction(uint256 _tokenid) public payable {
-       require(msg.value > returnHighestBid(_tokenid) && block.timestamp <= minter.getAuctionEndTime(_tokenid) && minter.getAuctionStatus(_tokenid) == true);
+       require(msg.value > returnHighestBid(_tokenid) && block.timestamp < minter.getAuctionEndTime(_tokenid) && minter.getAuctionStatus(_tokenid) == true);
        auctionInfoStru memory newBid = auctionInfoStru(msg.sender, msg.value, true);
        auctionInfoData[_tokenid].push(newBid);
    }

Assessed type

Context

a2rocket (NextGen) confirmed via duplicate issue #962

0xsomeone (judge) commented:

The Warden has clearly specified what the vulnerability is, has provided a recommended course of action that aligns with best practices, and has specified all aspects of the contract that would fail for the user if they tried to reclaim their lost funds.

The likelihood of this exhibit manifesting in practice is relatively low (requires a block.timestamp that exactly matches the auction). In the post-merge PoS Ethereum that the project intends to deploy, blocks are guaranteed to be multiples of 12 and can only be manipulated as multiples of it.

The impact is high, as the funds of the user are irrecoverably lost even with administrative privileges as no rescue mechanism exists, rendering this exhibit a medium severity issue.

Note: For full discussion, see here.


The original report as published on Code4rena, by HChang26. 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 participateToAuction function allows bids when the block timestamp is less than or equal to the auction end time, while claimAuction can be called at the same timestamp, creating a one-second window where a bid can be placed after the auction has been claimed.

Impact

Bidder funds become permanently stuck in the contract with no refund mechanism, even for administrators, though the likelihood is low because it requires a block timestamp exactly equal to the auction end time.

What the attacker needed

Auction ends at a specific timestamp; attacker can submit a bid at that exact timestamp; winner claims auction first

How it was found

  1. Wait until the auction end time is reached.
  2. Call claimAuction to claim the auction as the winner.
  3. In the same block or a block with the same timestamp, call participateToAuction with a higher bid.
  4. The bid is accepted but the auction is already claimed, so the funds are stuck.
  5. Attempt to cancel the bid using cancelBid or cancelAllBids, which will revert because the auction has ended.

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 a smart contract auction, a bidder sends money to the contract to place a bid. If the bid is placed at the exact moment the auction ends, after the winner has already taken the prize, the contract has no way to give that money back, so it is lost forever.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from NextGen

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.