Skip to content
Business logic Audit finding Intermediate

Highest bidder can withdraw his collateral due to a missing check in _cancelAllBids

The function that cancels all bids for a bidder lacked the check present in the single-bid cancel function that prevents the highest bidder from cancelling. This allowed the highest bidder to withdraw their collateral and still win the auction without paying.

0rpse Follow with 0xKartikgiri00, 0xPwned and 47 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-02-radicalxchange-judging/issues/14

Found by

0rpse, 0xKartikgiri00, 0xPwned, 0xShitgem, 0xboriskataa, 0xbrivan, 14si2o_Flint, 404666, AMOW, Aamirusmani1552, AgileJune, Al-Qa-qa, Atharv, CarlosAlbaWork, DMoore, DenTonylifer, Dots, FSchmoede, FassiSecurity, FastTiger, Krace, Marcologonz, SovaSlava, Tendency, Tricko, aycozynfada, cats, cawfree, cocacola, cu5t0mPe0, dipp, ethernal, fugazzi, ge6a, jah, jasonxiale, ke1caM, koreanspicygarlic, kuprum, ljj, merlin, mrBmbastic, neocrao, neon2835, offside0011, psb01, pseudoArtist, pynschon, sammy, sandy, tedox, thank_you, theFirstElder, theOwl, thisvishalsingh, turvec, valentin2304, zraxx, zzykxx

Summary

A bidder with the highest bid cannot cancel his bid since this would break the auction. A check to ensure this was implemented in _cancelBid.

However, this check was not implemented in _cancelAllBids, allowing the highest bidder to withdraw his collateral and win the auction for free.

Vulnerability Detail

The highest bidder should not be able to cancel his bid, since this would break the entire auction mechanism.

In _cancelBid we can find a require check that ensures this:

Solidity
        require(
            bidder != l.highestBids[tokenId][round].bidder,
            'EnglishPeriodicAuction: Cannot cancel bid if highest bidder'
        );

Yet in _cancelAllBids, this check was not implemented.

Solidity
     * @notice Cancel bids for all rounds
     */
    function _cancelAllBids(uint256 tokenId, address bidder) internal {
        EnglishPeriodicAuctionStorage.Layout
            storage l = EnglishPeriodicAuctionStorage.layout();

        uint256 currentAuctionRound = l.currentAuctionRound[tokenId];

        for (uint256 i = 0; i <= currentAuctionRound; i++) {
            Bid storage bid = l.bids[tokenId][i][bidder];

            if (bid.collateralAmount > 0) {
                // Make collateral available to withdraw
                l.availableCollateral[bidder] += bid.collateralAmount;

                // Reset collateral and bid
                bid.collateralAmount = 0;
                bid.bidAmount = 0;
            }
        }
    }

Example: User Bob bids 10 eth and takes the highest bidder spot. Bob calls cancelAllBidsAndWithdrawCollateral.

The _cancelAllBids function is called and this makes all the collateral from all his bids from every round available to Bob. This includes the current round <= and does not check if Bob is the current highest bidder. Nor is l.highestBids[tokenId][round].bidder reset, so the system still has Bob as the highest bidder.

Then _withdrawCollateral is automatically called and Bob receives his 10 eth back.

The auction ends. If Bob is still the highest bidder, he wins the auction and his bidAmount of 10 eth is added to the availableCollateral of the oldBidder.

If there currently is more than 10 eth in the contract (ongoing auctions, bids that have not withdrawn), then the oldBidder can withdraw 10 eth. But this means that in the future a withdraw will fail due to this missing 10 eth.

Impact

A malicious user can win an auction for free.

Additionally, either the oldBidder or some other user in the future will suffer the loss.

If this is repeated multiple times, it will drain the contract balance and all users will lose their locked collateral.

Code Snippet

https://github.com/sherlock-audit/2024-02-radicalxchange/blob/main/pco-art/contracts/auction/EnglishPeriodicAuctionInternal.sol#L416-L436

https://github.com/sherlock-audit/2024-02-radicalxchange/blob/main/pco-art/contracts/auction/EnglishPeriodicAuctionInternal.sol#L380-L413

https://github.com/sherlock-audit/2024-02-radicalxchange/blob/main/pco-art/contracts/auction/EnglishPeriodicAuctionInternal.sol#L468-L536

Tool used

Manual Review

Recommendation

Implement the require check from _cancelBid to _cancelAllBids.

Discussion

sherlock-admin3

The protocol team fixed this issue in the following PRs/commits: https://github.com/RadicalxChange/pco-art/pull/9

zzykxx

The highest bidder can't cancel his bid on an active auction round anymore while still being able to cancel his bids on previous rounds.

sherlock-admin2

The Lead Senior Watson signed off on the fix.

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

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 _cancelAllBids function did not include the same require check as _cancelBid to prevent the highest bidder from cancelling.

What the attacker needed

Be the highest bidder; call cancelAllBidsAndWithdrawCollateral

The fix

The protocol team fixed this issue by adding the require check from _cancelBid to _cancelAllBids.

How it was found

  1. Bob bids 10 ETH and becomes the highest bidder.
  2. Bob calls cancelAllBidsAndWithdrawCollateral.
  3. The _cancelAllBids function makes all his collateral available, including the current round, without checking if he is the highest bidder.
  4. The _withdrawCollateral function is called and Bob receives his 10 ETH back.
  5. The auction ends and Bob is still the highest bidder, so he wins.
  6. The bid amount is added to the previous highest bidder's available collateral, causing a future withdrawal to fail.

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 an auction, the highest bidder's money is held as a deposit. Normally, they cannot take it back while they are winning, because that would break the auction. Here, a second function that cancels all bids at once forgot to block the highest bidder, so they could take their money back and still win without paying.

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 by 0rpse

View all

23 more disclosed reports, best first.

More from RadicalxChange

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.