# Rounding error in WUSDA can result in loss of user funds, especially when manipulated by an attacker

WUSDA._usdaToWUSDA floor-rounds to zero; attacker flash-loans sUSD to inflate USDA supply, front-runs a victim's deposit so it mints almost no WUSDA, then withdraws the victim's USDA.

- Payout: Contest reward
- Severity: high
- Program: Amphora Protocol
- Credited: giovannidisiena
- Disclosed: 2024-04-22
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2023-07-amphora-findings/issues/256
- Library page: https://bugbountylibrary.com/r/c4%3A2023-07-amphora%3AH-03
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:race-window technique:source-review vuln:business-logic vuln:flash-loan vuln:precision-loss vuln:share-inflation

**Target:** WUSDA vault contract (deposit/withdraw share math)
**Root cause:** _usdaToWUSDA computes (_usdaAmount * MAX_wUSDA_SUPPLY) / _totalUsdaSupply with floor division and no zero-check, so small amounts relative to total supply round down to 0 shares.
**Steps:**
1. Victim calls `WUSDA::deposit(9.9e22)` (99,000 USDA) with total USDA supply 1M.
2. Attacker front-runs with `WUSDA::deposit(3.3e22)` receiving 33,000 WUSDA.
3. Attacker takes 39M sUSD flash loan and deposits into USDA, inflating total supply to ~40M.
4. Victim's tx executes: `_wusdaAmount = 9.9e22 * 1e25 / 4e25 = 2.475e22` (24,750 WUSDA instead of 99,000).
5. Attacker back-runs with `WUSDA::withdraw(132e21)`, burning only 33,000 WUSDA and receiving 132,000 USDA.
6. Attacker redeems USDA for sUSD, repays flash loan, keeps ~90,000 USDA profit.
**How found:** Code reading of the share conversion formula; recognized floor division with no zero-check and reasoned that total supply is manipulable within a block via flash loan.
**Exploitation:** Flash-loan sUSD to inflate USDA total supply within one block, sandwich a victim's deposit so their shares round down, then withdraw more USDA than WUSDA burned and redeem for sUSD.
**Escalation:** Single-block supply inflation via flash loan amplifies the rounding loss from dust to ~75% of victim deposit.
**Insight:** Share-conversion math that divides by a flash-loan-manipulable total supply is sandwichable: check whether deposit/withdraw share price can be moved within one block and whether rounding can hit zero.
