Skip to content
Smart contracts Audit finding Advanced

Bid with high price effectively can end up with lower price

The removeExcessBids function reduces the lowest bidder's sellCouponAmount and buyReserveAmount proportionally using integer division, which introduces rounding errors that can alter the price ratio. An attacker can exploit this to make a high-priced bid end up with a lower effective price, or repeatedly increase their buyReserveAmount by 1 wei without changing sellCouponAmount, causing the protocol to lose reserve tokens.

ZoA Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/198

This issue has been acknowledged by the team but won't be fixed at this time.

Found by

ZoA

Summary

In the removeExcessBids function, when the total bid amount exceeds totalBuyCouponAmount, the contract reduces the sellCouponAmount and buyReserveAmount of the lowest-ranked bidder proportionally. This reduction introduces precision loss due to integer division, leading to a scenario where bids initially made at a high price effectively end up with a lower price..

Root Cause

On the line Auction.sol#L281, removeExcessBids function reduces sellCouponAmount and buyReserveAmount proportionally. However, the reduction uses integer arithmetic, causing rounding errors that alter the price ratio (sellCouponAmount / buyReserveAmount).

Internal Pre-conditions

No response

External Pre-conditions

No response

Attack Path

No response

PoC

  • Assume totalBuyCouponAmount = 10e18, slotSize = 1e18 and currentCouponAmount = 10e18(full charged).
  • The lowest bidder(bidder 1): buyReserveAmount = 1e8, sellCouponAmount = 1e18
  • bidder 2: bids with buyReserveAmount = 9e8, sellCouponAmount = 9e18
    • price is same as the bidder 1's but sellCouponAmount is larger.
    • bidder 1 is removed and bidder 2 enters the list.
    • bidder 2's values change:
      • amountToRemove = 8e18
      • proportion = (amountToRemove * 1e18) / sellCouponAmount = 888888888888888888
      • new sellCouponAmount = 1e18
      • new buyReserveAmount = 9e8 - [9e8 * proportion] / 1e18 = 1e8 + 1
  • Result: Bidder 2 has the lower price than Bidder 1.

Impact

  1. Bid with high price effectively can end up with lower price.
  2. The lowest bidder can repeat the same operation as above to increase the size of buyReserveAmount without changing sellCouponAmount. Attacker can either profit by 1wei(0.001 usd) which is more than the gas fee if the token is WBTC. In this case, even if the attacker's gain is not great due to gas fees, the protocol loses a lot of reserve tokens.

Mitigation

check whether the buyReserveAmount size increases before and after the bid.

Solidity
function bid(uint256 buyReserveAmount, uint256 sellCouponAmount) external auctionActive whenNotPaused returns(uint256) {
    ...
    uint256 totalSellReserveAmountBefore = totalSellReserveAmount;

    Bid memory newBid = Bid({
    ...
    removeExcessBids();

    uint256 totalSellReserveAmountAfter = totalSellReserveAmount;
    if(totalSellReserveAmountBefore < totalSellReserveAmountAfter) revert TotalSellReserveAmountIncreased();
    ...
}

The original report as published on Sherlock, by ZoA. 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 integer division in the proportional reduction of sellCouponAmount and buyReserveAmount causes rounding errors that change the price ratio.

What the attacker needed

Auction is active; Attacker can place bids

The fix

The mitigation suggests checking whether totalSellReserveAmount increases before and after the bid and reverting if it does.

How it was found

  1. Assume totalBuyCouponAmount = 10e18, slotSize = 1e18, and currentCouponAmount = 10e18 (full charged).
  2. The lowest bidder (bidder 1) has buyReserveAmount = 1e8 and sellCouponAmount = 1e18.
  3. Bidder 2 bids with buyReserveAmount = 9e8 and sellCouponAmount = 9e18, same price as bidder 1 but larger sellCouponAmount.
  4. Bidder 1 is removed and bidder 2 enters the list.
  5. Bidder 2's values change: amountToRemove = 8e18, proportion = (amountToRemove * 1e18) / sellCouponAmount = 888888888888888888, new sellCouponAmount = 1e18, new buyReserveAmount = 9e8 - [9e8 * proportion] / 1e18 = 1e8 + 1.
  6. Result: Bidder 2 has a lower price than Bidder 1.

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.

When too many bids are placed, the auction contract removes the lowest bidder by reducing their amounts proportionally. Because the contract uses whole-number division, the reduced amounts don't keep the same ratio, so a bidder who bid at a high price can end up with a lower effective price. An attacker can exploit this rounding error to gain a tiny amount of extra tokens or cause the protocol to lose funds.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by ZoA

View all

5 more disclosed reports, best first.

More from Plaza Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.