# Bid with high price effectively can end up with lower price

Integer-division rounding in Auction.removeExcessBids lets a high-priced bid end up priced lower, and lets the lowest bidder repeatedly inflate buyReserveAmount by 1 wei.

- Payout: Audit contest
- Severity: medium
- Program: Plaza Finance
- Found by: ZoA
- Disclosed: 2024-12-16
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/198
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-plaza-finance%3AM-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:precision-loss

**Target:** Auction.sol removeExcessBids bid accounting
**Root cause:** removeExcessBids reduces sellCouponAmount and buyReserveAmount proportionally using integer division, so rounding alters the sell/buy price ratio of the lowest bidder.
**Steps:**
1. Set totalBuyCouponAmount=10e18, slotSize=1e18, currentCouponAmount=10e18 (full).
2. Bidder1 bids buyReserveAmount=1e8, sellCouponAmount=1e18.
3. Bidder2 bids buyReserveAmount=9e8, sellCouponAmount=9e18 (same price, larger sell).
4. Bidder1 removed; bidder2's amountToRemove=8e18, proportion=(8e18*1e18)/9e18=888888888888888888.
5. New sellCouponAmount=1e18, new buyReserveAmount=9e8-(9e8*proportion)/1e18=1e8+1.
6. Bidder2 now has lower price than bidder1; lowest bidder can repeat to inflate buyReserveAmount by 1 wei per iteration.
**How found:** Code review of removeExcessBids proportional reduction, noticing integer division rounding changes the price ratio; constructed a numeric example with two bidders at equal price.
**Exploitation:** Attacker repeatedly bids as the lowest bidder to trigger proportional reduction rounding, gaining 1 wei of buyReserveAmount per iteration without changing sellCouponAmount; profitable when reserve token is high-value (e.g. WBTC) and drains protocol reserve tokens.
**Insight:** When a function proportionally shrinks two amounts that define a price ratio, integer division rounds each independently and can invert the ratio; check whether the derived price can move against the bidder's intent after partial removal.

## Proof of concept (copied exactly from the original report)

**PoC of proportional reduction rounding error**

```
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`
```

