Skip to content
Business logic Audit finding Advanced

Bidders' funds may become locked due to inconsistent price order checks in MaxPriorityQueue and the _claimBid function

The MaxPriorityQueue orders bids by comparing cross-multiplied amounts, while the claim function checks a rounded price, so a bid with the marginal price but a smaller bid ID can claim even though it is not a winner. This lets early bidders take base tokens, leaving later winners unable to claim and locking their quote tokens.

ether_sky Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-axis-finance-judging/issues/83

Found by

ether_sky

Summary

In the MaxPriorityQueue, bids are ordered by decreasing price. We calculate the marginal price, marginal bid ID, and determine the auction winners. When a bidder wants to claim, we verify that the bid price of this bidder exceeds the marginal price. However, there's minor inconsistency: certain bids may have marginal price and a smaller bid ID than marginal bid ID and they are not actually winners. As a result, the auction winners and these bidders can receive base tokens. However, there is a finite supply of base tokens for auction winners. Early bidders who claim can receive base tokens, but the last bidders can not.

Vulnerability Detail

The comparison for the order of bids in the MaxPriorityQueue is as follow: if q1 * b2 < q2 * b1 then bid (q2, b2) takes precedence over bid (q1, b1).

Solidity
function _isLess(Queue storage self, uint256 i, uint256 j) private view returns (bool) {
    uint64 iId = self.bidIdList[i];
    uint64 jId = self.bidIdList[j];
    Bid memory bidI = self.idToBidMap[iId];
    Bid memory bidJ = self.idToBidMap[jId];
    uint256 relI = uint256(bidI.amountIn) * uint256(bidJ.minAmountOut);
    uint256 relJ = uint256(bidJ.amountIn) * uint256(bidI.minAmountOut);
    if (relI == relJ) {
        return iId > jId;
    }
    return relI < relJ;
}

And in the _calimBid function, the price is checked directly as follow: if q * 10 ** baseDecimal / b >= marginal price, then this bid can be claimed.

Solidity
function _claimBid(
    uint96 lotId_,
    uint64 bidId_
) internal returns (BidClaim memory bidClaim, bytes memory auctionOutput_) {
    uint96 price = uint96(
        bidData.minAmountOut == 0
            ? 0 // TODO technically minAmountOut == 0 should be an infinite price, but need to check that later. Need to be careful we don't introduce a way to claim a bid when we set marginalPrice to type(uint96).max when it cannot be settled.
            : Math.mulDivUp(uint256(bidData.amount), baseScale, uint256(bidData.minAmountOut))
    );
    uint96 marginalPrice = auctionData[lotId_].marginalPrice;
    if (
        price > marginalPrice
            || (price == marginalPrice && bidId_ <= auctionData[lotId_].marginalBidId)
    ) { }
}

The issue is that a bid with the marginal price might being placed after marginal bid in the MaxPriorityQueue due to rounding.

Solidity
q1 * b2 < q2 * b1, but mulDivUp(q1, 10 ** baseDecimal, b1) = mulDivUp(q2, 10 ** baseDecimal, b2)

Let me take an example. The capacity is 10e18 and there are 6 bids ((4e18 + 1, 2e18) for first bidder, (4e18 + 2, 2e18) for the other bidders. The order in the MaxPriorityQueue is (2, 3, 4, 5, 6, 1). The marginal bid ID is 6. The marginal price is 2e18 + 1. The auction winners are (2, 3, 4, 5, 6). However, bidder 1 can also claim because it's price matches the marginal price and it has the smallest bid ID. There are only 10e18 base tokens, but all 6 bidders require 2e18 base tokens. As a result, at least one bidder won't be able to claim base tokens, and his quote tokens will remain locked in the auction house.

The Log is

Solidity
marginal price     ==>   2000000000000000001
marginal bid id    ==>   6

paid to bid  1       ==>   4000000000000000001
payout to bid  1     ==>   1999999999999999999
*****
paid to bid  2       ==>   4000000000000000002
payout to bid  2     ==>   2000000000000000000
*****
paid to bid  3       ==>   4000000000000000002
payout to bid  3     ==>   2000000000000000000
*****
paid to bid  4       ==>   4000000000000000002
payout to bid  4     ==>   2000000000000000000
*****
paid to bid  5       ==>   4000000000000000002
payout to bid  5     ==>   2000000000000000000
*****
paid to bid  6       ==>   4000000000000000002
payout to bid  6     ==>   2000000000000000000

Please add below test to the test/modules/auctions/EMPA/claimBids.t.sol

Solidity
function test_claim_nonClaimable_bid()
    external
    givenLotIsCreated
    givenLotHasStarted
    givenBidIsCreated(4e18 + 1, 2e18)           // bidId = 1
    givenBidIsCreated(4e18 + 2, 2e18)           // bidId = 2
    givenBidIsCreated(4e18 + 2, 2e18)           // bidId = 3
    givenBidIsCreated(4e18 + 2, 2e18)           // bidId = 4
    givenBidIsCreated(4e18 + 2, 2e18)           // bidId = 5
    givenBidIsCreated(4e18 + 2, 2e18)           // bidId = 6
    givenLotHasConcluded
    givenPrivateKeyIsSubmitted
    givenLotIsDecrypted
    givenLotIsSettled
{
    EncryptedMarginalPriceAuctionModule.AuctionData memory auctionData = _getAuctionData(_lotId);

    console2.log('marginal price     ==>  ', auctionData.marginalPrice);
    console2.log('marginal bid id    ==>  ', auctionData.marginalBidId);
    console2.log('');

    for (uint64 i; i < 6; i ++) {
        uint64[] memory bidIds = new uint64[](1);
        bidIds[0] = i + 1;
        vm.prank(address(_auctionHouse));
        (Auction.BidClaim[] memory bidClaims,) = _module.claimBids(_lotId, bidIds);
        Auction.BidClaim memory bidClaim = bidClaims[0];
        if (i > 0) {
            console2.log('*****');
        }
        console2.log('paid to bid ', i + 1, '      ==>  ', bidClaim.paid);
        console2.log('payout to bid ', i + 1, '    ==>  ', bidClaim.payout);
    }
}

Impact

Code Snippet

https://github.com/sherlock-audit/2024-03-axis-finance/blob/cadf331f12b485bac184111cdc9ba1344d9fbf01/moonraker/src/lib/MaxPriorityQueue.sol#L109-L120 https://github.com/sherlock-audit/2024-03-axis-finance/blob/cadf331f12b485bac184111cdc9ba1344d9fbf01/moonraker/src/modules/auctions/EMPAM.sol#L347-L350

Tool used

Manual Review

Recommendation

In the MaxPriorityQueue, we should check the price: Math.mulDivUp(q, 10 ** baseDecimal, b).

Discussion

Oighty

Believe this is valid due to bids below marginal price being able to claim, which would result in a winning bidder not receiving theirs. Need to think about the remediation a bit more. There are some other precision issues with the rounding up.

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/Axis-Fi/moonraker/pull/146

10xhash

The protocol team fixed this issue in the following PRs/commits: Axis-Fi/moonraker#146

Fixed Now same computation is used for queue and marginal price calculations

sherlock-admin4

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by ether_sky. 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

Likely the queue ordering uses exact cross-multiplication while the claim check uses a rounded price, so bids with equal rounded price but different exact ratios are treated inconsistently.

Impact

At least one winning bidder cannot claim base tokens, and their quote tokens remain locked in the auction house.

What the attacker needed

Auction with multiple bids; bids with close prices causing rounding; bidders claim after settlement

The fix

The protocol team fixed this issue by using the same computation for queue and marginal price calculations.

How it was found

  1. Create an auction with capacity 10e18 and six bids: one bid of (4e18+1, 2e18) and five bids of (4e18+2, 2e18).
  2. Conclude, decrypt, and settle the auction.
  3. Each bidder calls claimBids for their bid ID.
  4. Observe that all six bidders receive base tokens, but only five are winners, so one winner cannot claim.

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, bids are ranked by price. The code that ranks bids uses one calculation, but the code that lets a bidder claim winnings uses a slightly different, rounded calculation. Because of this mismatch, a bidder who should not win can still claim, using up the limited reward tokens so that a real winner cannot claim and their money stays stuck.

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 ether_sky

View all

11 more disclosed reports, best first.

More from Axis Finance

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.