# Wrong direction of rounding in redeem may lead to drain if exchange rate grows large

Malda mToken redeemUnderlying rounds shares down, letting first depositor inflate exchange rate and drain funds by burning zero shares.

- Payout: Audit contest
- Severity: medium
- Program: Malda
- Found by: cergyk
- Disclosed: 2025-07-22
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2025-07-malda-judging/issues/81
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-07-malda%3AM-1
- 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:share-inflation

**Target:** mToken contract (Compound v2 fork)
**Root cause:** In __redeem, redeemTokens = div_(redeemAmountIn, exchangeRate) rounds down, pulling fewer shares than the underlying amount requested. Combined with mint rounding and initial share burn, this allows exchange rate manipulation.
**Steps:**
1. First depositor mints at least 20 wei to initialize totalSupply=1000 shares (exchangeRate=0.02).
2. Repeat: mint 1 wei (mints 50 shares), then redeem 25 shares twice (sends 0 underlying). Each iteration increases totalUnderlying by 1 wei, totalSupply unchanged, raising exchangeRate.
3. Repeat ~980 times to reach exchangeRate ≈ e.
4. When exchangeRate > e, mint X wei to mint 0 shares, doubling exchangeRate every 1000 iterations.
5. Reach exchangeRate = 1e6 * e (e.g., ~20 iterations for USDC).
6. Wait for new depositors, then call redeemUnderlying(1e6) repeatedly; each call burns 0 shares and drains 1e6 underlying.
**How found:** Code review of Compound v2 fork identified rounding direction error in redeem; recognized potential for exchange rate manipulation when combined with mint rounding and initial share burn.
**Exploitation:** Attacker becomes first depositor, inflates exchange rate via repeated mint/redeem cycles costing ~$5 gas, then drains funds from subsequent depositors by redeeming underlying while burning zero shares.
**Escalation:** Exchange rate inflation is exponential after reaching e, enabling large-scale drain with minimal capital.
**Insight:** In Compound v2 forks, check rounding direction in redeem: shares should round up to prevent exchange rate inflation attacks, especially when initial share burn and mint rounding allow manipulation.

