# Multiple swap lack slippage protection

BakerFi's Uniswap V3 _swap hardcodes amountOutMinimum to 0, exposing WETH conversions and debt repayment to sandwich/price manipulation.

- Payout: Audit contest
- Severity: high
- Program: BakerFi
- Found by: bin2chen
- Disclosed: 2024-06-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-bakerfi-findings/issues/32
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-bakerfi%3AH-04
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:oracle-manipulation

**Target:** Solidity strategy contracts using Uniswap V3 router (_swap, _convertFromWETH, _convertToWETH, _payDebt)
**Root cause:** _swap passes amountOutMinimum: 0 to exactInputSingle and callers pass amountOut=0, so no minimum output is enforced on any swap.
**Steps:**
1. Read UseSwapper._swap: exactInputSingle called with `amountOutMinimum: 0` instead of `params.amountOut`.
2. Confirm callers like _convertFromWETH pass `0` as Amount Out param.
3. Attacker observes pending swap tx in mempool and front-runs by moving pool price.
4. Victim swap executes at manipulated price, attacker back-runs to profit.
**How found:** Code review of the swap handler noticed the Uniswap docs' warning about amountOutMinimum=0 and traced that params.amountOut was never wired into the router call.
**Exploitation:** Sandwich attack: attacker front-runs the protocol's WETH->asset swap to skew Uniswap V3 pool price, victim's swap fills at bad rate with no minimum, attacker back-runs to capture the delta.
**Insight:** When auditing swap wrappers, check that the caller-supplied min-out parameter is actually forwarded to the router; a struct field existing doesn't mean it's used.

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

**Swap call with amountOutMinimum hardcoded to 0**

```
amountOut = _uniRouter.exactInputSingle(
                IV3SwapRouter.ExactInputSingleParams({
                    tokenIn: params.underlyingIn,
                    tokenOut: params.underlyingOut,
                    amountIn: params.amountIn,
@>                  amountOutMinimum: 0,   //@audit miss set params.amountOut
                    fee: fee,
                    recipient: address(this),
                    sqrtPriceLimitX96: 0
                })
            );
            if (amountOut == 0) {
                revert SwapFailed();
            }
```

**_convertFromWETH passes 0 as amountOut**

```
_swap(
                ISwapHandler.SwapParams(
                    wETHA(), // Asset In
                    ierc20A(), // Asset Out
                    ISwapHandler.SwapType.EXACT_INPUT, // Swap Mode
                    amount, // Amount In
                    //@audit miss slippage protection
@>                  0, // Amount Out 
                    _swapFeeTier, // Fee Pair Tier
```

