# When harvesting a strategy and adjusting the debt, all the leftover collateral that is not used to swap the withdrawn collateral from Aave for WETH to repay the flashloan will be locked and lost in the Strategy contract

Hardcoded 500 fee tier in UniQuoter quote plus self-transfer of leftover collateral leaves excess user collateral permanently locked in StrategyLeverage during debt adjustment.

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

**Target:** StrategyLeverage._payDebt / UseSwapper._swap (Aave+Uniswap+Balancer flashloan)
**Root cause:** UniQuoter quote uses hardcoded fee tier 500 while the actual swap uses _swapFeeTier; when the configured pool fee is lower, the quote overestimates required collateral, and the leftover is self-transferred to the contract instead of re-supplied to Aave.
**Steps:**
1. Configure strategy with a Uniswap pool fee tier lower than 500 (e.g. 100).
2. Trigger harvest/debt adjustment so _payDebt computes deltaDebt and takes a Balancer WETH flashloan.
3. _payDebt calls `uniQuoter().quoteExactOutputSingle(QuoteExactOutputSingleParams(ierc20A(), wETHA(), debtAmount+fee, 500, 0))` — quote assumes 0.05% pool.
4. _withdraw(ierc20A(), amountIn, address(this)) withdraws the overestimated collateral amount from Aave.
5. _swap executes `exactOutputSingle` with `fee=_swapFeeTier` (lower), consuming less collateral than withdrawn.
6. UseSwapper sees `amountIn < params.amountIn` and does `IERC20(underlyingIn).safeTransfer(address(this), params.amountIn - amountIn)`, stranding the difference in the Strategy.
**How found:** Code review of _payDebt noticed the UniQuoter call hardcodes fee 500 while the swap uses _swapFeeTier, then traced the leftover handling in UseSwapper._swap to the self-transfer.
**Exploitation:** No attacker action needed; each harvest/debt adjustment with a sub-500 fee pool leaks user collateral into the Strategy contract balance where it is unrecoverable, and some ERC20s revert on self-transfer breaking harvest entirely.
**Insight:** When a quote and the actual swap are parameterized separately, check that every fee/tier/slippage parameter matches between quote and execution; mismatches silently over-withdraw and the 'refund' path (self-transfer) is a common place value gets stranded.

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

**Hardcoded 500 fee in UniQuoter quote**

```
(uint256 amountIn, , , ) = uniQuoter().quoteExactOutputSingle(
          //@audit-issue => The computed `amountIn` is based on a pool with fees of 0.05%!
          IQuoterV2.QuoteExactOutputSingleParams(ierc20A(), wETHA(), debtAmount + fee, 500, 0)
      );
```

**Self-transfer of leftover collateral after swap**

```
if (amountIn < params.amountIn) {
                IERC20(params.underlyingIn).safeTransfer(address(this), params.amountIn - amountIn);
```

