# PerpDepository.netAssetDeposits variable can prevent users to withdraw with underflow error

PerpDepository's netAssetDeposits counter tracks base-asset amounts, so when redemption price differs from deposit price, withdrawals underflow and users cannot redeem UXD.

- Payout: Contest reward
- Severity: medium
- Program: Uxd
- Credited: rvierdiiev
- Disclosed: 2022-12-27
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-01-uxd-judging/issues/97
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-01-uxd%3AM-13
- Tags: domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** PerpDepository.sol deposit/withdraw accounting
**Root cause:** netAssetDeposits is incremented by deposited base-asset amount but decremented by the base-asset amount returned at redemption; since UXD minted/redeemed amounts are price-dependent, the counter can go negative.
**Steps:**
1. User deposits 1 WETH at $1200; 1200 UXD minted, netAssetDeposits=1.
2. WETH price drops to $1100.
3. User redeems 1200 UXD, receiving 1200/1100=1.09 WETH.
4. `_withdrawAsset` checks `amount > netAssetDeposits` (1.09 > 1) and reverts with InsufficientAssetDeposits/underflow.
**How found:** Code reading of `_depositAsset`/`_withdrawAsset`: noticed the counter mixes base-asset units with price-dependent UXD redemption amounts, then constructed a price-drop scenario to trigger underflow.
**Insight:** When an accounting variable is incremented in one unit (deposit asset) but decremented in a price-derived unit (redeemed asset), divergence is inevitable; check any net/total counter for unit mismatch across price changes.
