# All supplied WETH to Aave as a deposit by a Strategy will be irrecoverable

StrategyLeverage deposits leftover WETH into Aave after debt repayment, but has no path to withdraw WETH, permanently locking those funds.

- Payout: Audit contest
- Severity: medium
- Program: BakerFi
- Found by: 0xStalin
- Disclosed: 2024-06-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-bakerfi-findings/issues/41
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-bakerfi%3AM-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** StrategyLeverage / StrategyAAVEv3 smart contracts
**Root cause:** _payDebt supplies swap leftovers (wethLefts) back to Aave via _supply, but the strategy only ever withdraws collateral from Aave, never WETH, so supplied WETH can never be retrieved.
**Steps:**
1. Call _payDebt; _swap with EXACT_OUTPUT returns output > debtAmount+fee, producing wethLefts
2. Code executes `if (wethLefts > 0) { _supply(wETHA(), wethLefts); }`
3. Strategy's only Aave withdrawal path (_withdraw) is invoked solely for collateral in _payDebt and _repayAndWithdraw
4. WETH supplied is stranded in Aave with no function to withdraw it
**How found:** Code reading of _payDebt's leftover-handling branch, then tracing all callers of StrategyAAVEv3._withdraw to confirm only collateral is ever withdrawn, never WETH.
**Exploitation:** Not an attacker-driven exploit; any debt repayment where the swap yields excess WETH causes the strategy to deposit that WETH into Aave, permanently losing it from the strategy.
**Insight:** When a contract supplies an asset to a lending pool, verify a matching withdraw path exists for that same asset; leftover-balance 'sweep back to pool' logic is a common way to strand funds.

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

**PoC code showing leftover WETH supplied to Aave**

```
uint256 wethLefts = output > (debtAmount + fee) ? output - (debtAmount + fee) : 0;

      //@audit-issue => If any leftover WETH, it deposits them onto Aave!
      //@audit-issue => Once the WETH is deposited in Aave, the Strategy won't be able to pull it out.
      if (wethLefts > 0) {
          _supply(wETHA(), wethLefts);
      }
```

**Suggested fix replacing supply with repay**

```
if (wethLefts > 0) {
    -     _supply(wETHA(), wethLefts);
    +     _repay(wETHA(), wethLefts);
      }
```

