# StrategyLeverage.harvest doesn't account flashloan fee

StrategyLeverage.harvest ignores flashloan fee when recomputing deployed amount, overstating collateral so protocol collects less management fee on profit.

- Payout: Audit contest
- Severity: medium
- Program: BakerFi
- Found by: rvierdiiev
- Disclosed: 2024-06-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-bakerfi-findings/issues/36
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-bakerfi%3AM-03
- Tags: area:web3 domain:web3 kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:flash-loan

**Target:** StrategyLeverage.sol harvest/_adjustDebt leverage strategy
**Root cause:** _adjustDebt repays deltaDebt via flashloan, reducing collateral by deltaDebt+fee, but newDeployedAmount is computed as if both debt and collateral dropped by only deltaDebt, overstating deployed capital.
**Steps:**
1. Position LTV exceeds max LTV; harvest() triggers _adjustDebt to repay extra debt.
2. _adjustDebt takes a flashloan and pays a fee, so collateral decreases by `deltaDebt + fee` while debt decreases by `deltaDebt`.
3. newDeployedAmount is computed as `collateral - debt` using deltaDebt for both, yielding a value larger than reality by `fee`.
4. Later profit accrual: if `profit < fee` protocol receives nothing; if `profit > fee` management fee is computed on `profit - fee`.
5. Result: protocol collects reduced fees.
**How found:** Code reading of harvest()/_adjustDebt: noticed flashloan fee is paid out of collateral but the newDeployedAmount formula only subtracts deltaDebt from both sides, so the fee is unaccounted.
**Insight:** When a function mutates position state via a flashloan, audit every downstream accounting formula for the fee term—collateral and debt deltas are asymmetric once fees are paid from collateral.

