# Uniswap v3 pool token balance proportion does not necessarily correspond to the price, and it is easy to manipulate.

USSDRebalancer derives USSD/DAI price from Uniswap v3 pool token balances, which don't track price and are cheaply manipulable, causing underflow reverts and oversized collateral sells.

- Payout: Contest reward
- Severity: high
- Program: USSD
- Credited: 0xRan4212
- Disclosed: 2023-05-15
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-05-USSD-judging/issues/808
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-05-USSD%3AH-9
- Tags: domain:web3 impact:funds-loss impact:integrity kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos vuln:oracle-manipulation

**Target:** USSDRebalancer.getSupplyProportion() / rebalance() against Uniswap v3 USSD/DAI and WETH/DAI pools
**Root cause:** getSupplyProportion() treats Uniswap v3 pool token balances as a price proxy, but v3 concentrated liquidity means reserve ratio does not equal price and accumulated fees sit in balances unaffected by price.
**Steps:**
1. Read USSDRebalancer.sol L83-L107: getSupplyProportion() reads USSD and DAI balanceOf of the v3 pool.
2. Observe L97 computes `USSDamount - DAIamount`; when ownval < 1e6 - threshold, USSDamount < DAIamount and the subtraction underflows, reverting rebalance().
3. To exploit over-peg: add single-sided DAI liquidity in DAI/USSD pool at extreme range (1 DAI == 1000-2000 USSD).
4. Manipulate WETH collateral price upward; place JIT limit-order liquidity at higher price in WETH/DAI pool.
5. Call `rebalance() -> SellUSSDBuyCollateral()`; inflated DAIamount vs USSDamount mints/sells far more USSD than needed, filling the attacker's limit order.
6. Reverse WETH/DAI price and withdraw the step-1 liquidity.
**How found:** Code review of getSupplyProportion() recognizing that Uniswap v3 concentrated liquidity and fee accrual break the v2 assumption that reserve ratio equals price; traced the underflow at L97 and constructed a manipulation path.
**Exploitation:** Attacker positions single-sided DAI liquidity at an absurd price range and JIT limit orders in the collateral pool, then triggers rebalance() so the protocol mints and sells excess USSD into the attacker's orders at manipulated prices, then unwinds positions.
**Escalation:** Chaining collateral price manipulation with the balance-ratio mispricing amplifies protocol collateral sold at manipulated prices.
**Insight:** Never use Uniswap v3 pool balanceOf ratios as a price oracle — concentrated ranges and accrued fees decouple reserves from price; check peg logic for subtraction underflow when the assumed ordering of amounts flips.
