# What is missing slippage protection?

URL: https://shield.quillaudits.com/learn/vulnerabilities/missing-slippage-protection/

Missing slippage protection means a swap, deposit or withdrawal runs at whatever price the pool offers when the transaction lands, with no minimum output and no deadline set in advance. A searcher who sees it pending moves the price first and trades back after, a sandwich, and the difference comes out of the swap. Let the caller pass a minimum amount out and a deadline, compute that minimum off-chain or from a price one trade can't move, and check both in the contract that swaps.

Last updated 3 December 2026. 6 minute read. By the QuillAudits Team.

## How does a missing slippage check get exploited?

An AMM pays less the further the pool has moved against you. The [ethereum.org page on MEV](https://ethereum.org/developers/docs/mev/) explains how searchers spot a large pending DEX trade, buy right before it and sell right after. A swap with `amountOutMin` set to 0 accepts any outcome, so a searcher can:

1. Buy the token your transaction is about to buy, which pushes its price up.
2. Let your swap execute at the worse price, which it accepts.
3. Sell back into the price your swap pushed up further, and keep the difference.

The same gap shows up in less obvious places:

- Protocol swaps that anyone can trigger. A `harvest` or `rebalance` that sells the protocol's own tokens with no minimum can be called by the attacker, in the same transaction as the trades that move the pool.
- A minimum computed on chain from the same pool. Reading the pool's current price to set `amountOutMin` checks the price against itself, after it has already been moved.
- No deadline, or `block.timestamp` as the deadline. The transaction stays valid indefinitely and can be held until the price is bad.
- Liquidity and vault operations. Adding or removing liquidity, zaps and vault deposits that swap inside all need their own minimums.

## What does vulnerable code look like?

**Vulnerable: a public harvest that swaps with a minimum of 0 (illustrative, not audited code)** `AnyPriceCompounder.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
}

interface IRouter {
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

contract AnyPriceCompounder {
    IRouter public immutable router;
    IERC20 public immutable reward;
    IERC20 public immutable asset;

    constructor(IRouter router_, IERC20 reward_, IERC20 asset_) {
        router = router_;
        reward = reward_;
        asset = asset_;
    }

    // Anyone can call this, in the same transaction as a trade that moves the pool.
    function harvest() external {
        uint256 amount = reward.balanceOf(address(this));
        require(reward.approve(address(router), amount), "approve failed");
        address[] memory path = new address[](2);
        path[0] = address(reward);
        path[1] = address(asset);
        // A minimum of 0 accepts any price, and block.timestamp as the deadline
        // is always "now", so it never expires either.
        router.swapExactTokensForTokens(amount, 0, path, address(this), block.timestamp);
    }
}
```

The attacker borrows, sells into the pool to push the reward token's price down, calls `harvest`, which sells the protocol's rewards at that depressed price, then buys back. In a Foundry test with a mock router, `harvest` accepted 10% of the fair output without complaint.

## How do you fix it?

**Fixed: a keeper-only harvest with a minimum, an oracle floor and a real deadline (illustrative, not audited code)** `BoundedCompounder.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
}

interface IRouter {
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

// Your own price adapter, backed by a source one trade can't move (not the pool you swap in).
interface IQuoteOracle {
    function quote(address tokenIn, address tokenOut, uint256 amountIn) external view returns (uint256);
}

contract BoundedCompounder {
    IRouter public immutable router;
    IERC20 public immutable reward;
    IERC20 public immutable asset;
    IQuoteOracle public immutable oracle;
    address public immutable keeper;
    uint256 public constant MAX_SLIPPAGE_BPS = 100; // accept at most 1% below the oracle quote

    constructor(IRouter router_, IERC20 reward_, IERC20 asset_, IQuoteOracle oracle_, address keeper_) {
        router = router_;
        reward = reward_;
        asset = asset_;
        oracle = oracle_;
        keeper = keeper_;
    }

    // The keeper computes minOut off-chain and picks a deadline a few minutes out.
    function harvest(uint256 minOut, uint256 deadline) external {
        require(msg.sender == keeper, "only keeper");
        uint256 amount = reward.balanceOf(address(this));
        // Second line of defense: never accept less than the oracle allows,
        // even if the keeper's own minimum is wrong.
        uint256 quoted = oracle.quote(address(reward), address(asset), amount);
        require(minOut >= quoted * (10_000 - MAX_SLIPPAGE_BPS) / 10_000, "minOut too low");
        require(reward.approve(address(router), amount), "approve failed");
        address[] memory path = new address[](2);
        path[0] = address(reward);
        path[1] = address(asset);
        // The router reverts if the output is below minOut or the deadline has passed.
        router.swapExactTokensForTokens(amount, minOut, path, address(this), deadline);
    }
}
```

- Take the minimum from the caller. Users and keepers compute the expected output off-chain, subtract a tolerance and pass it in, and the router reverts below it. Uniswap's swapping guide points to the price the trader saw off-chain as the basis for the minimum, and says a minimum computed on chain needs an oracle ([Uniswap](https://developers.uniswap.org/docs/protocols/v2/guides/swapping)).
- Add a floor from a price one trade can't move. The fixed contract refuses any minimum more than 1% below its oracle's quote, so a bug or a compromised keeper can't sell far below that price.
- Limit who can trigger protocol swaps. A keeper-only harvest can't be bundled with an attacker's own trades, and sending it through a private transaction relay keeps it out of the public mempool.
- Use a real deadline. Pass a timestamp a few minutes ahead, chosen off-chain. `block.timestamp` as the deadline is always the current time, so it never expires.
- Cover every leg. Multi-hop swaps, liquidity removals and zaps need a minimum on what the user finally receives, because a minimum on the first step alone leaves the rest open.

In the same test, the fixed contract rejected a minimum below its oracle floor, the router rejected the swap at the manipulated price, and only the keeper's call at a fair price went through.

## How has slippage protection failed in a real exploit?

| Protocol | Rhea Finance |
| --- | --- |
| Date | 16 April 2026 |
| Chain | NEAR |
| Loss | about $18.4M, of which about $11.2M had been returned or frozen by 17 April 2026 |
| What happened | Rhea Finance checked the swap route of a new margin position, in its Burrowland contract, by adding up the `min_amount_out` of every action in the route. According to [rekt.news](https://alpha.rekt.news/rhea-finance-rekt), it summed all of them, treating intermediate hops as if they were final deliveries, and it rolled back a margin operation only when a swap failed entirely. The attacker deployed fake tokens with pools of its own and opened margin positions whose routes ran through them, so the summed minimum passed the check while the protocol received a tiny fraction of it. Each position was worth far less than its debt, and the forced liquidations that followed drained the reserve pool. Rhea's post-mortem put the loss at $18.4M, more than double the first estimate, as [The Block reported](https://www.theblock.co/post/397961/rhea-finance-exploit-losses-18-4-million-double-initial-estimates). |
| Sources | [rekt.news](https://alpha.rekt.news/rhea-finance-rekt), [The Block](https://www.theblock.co/post/397961/rhea-finance-exploit-losses-18-4-million-double-initial-estimates) |

Rhea checked the sum of each step's minimum and never compared what the route finally delivered with it, the gap the cover-every-leg fix above closes. Rhea runs on NEAR, not an EVM chain, so its code is outside what QuillShield audits today, which is Solidity in Foundry projects. The lesson carries over unchanged to Solidity routers and zaps.

## How should a contract choose the minimum?

| Approach | Protects against | Weak spot |
| --- | --- | --- |
| 0, or no minimum | Nothing | Any sandwich takes the whole difference |
| Computed on chain from the same pool | Nothing | The pool has already moved when it is read |
| Passed in by the user, computed off-chain | Sandwiches beyond the user's tolerance | A tolerance set too wide, or a front end with a bad default |
| A floor from an oracle the trade can't move | A missing or careless user minimum | The oracle's own staleness and deviation |
| Both a user minimum and an oracle floor | Both of the above | More code to review, and both need fresh prices |

## What should a reviewer check?

- Find every swap, liquidity add or removal, zap and vault deposit or withdrawal that converts between assets.
- Does each one take a minimum output from the caller, or derive it from a price the same transaction can't move?
- Is any minimum hardcoded to 0, or computed from the pool being traded in?
- Does each one take a deadline from the caller, and is the deadline ever set to `block.timestamp` inside the contract?
- Who can trigger protocol-owned swaps such as harvests and rebalances, and can they do it in the same transaction as other trades?
- For multi-step flows, is the minimum checked on what the user finally receives?
- Do tests move the pool price before the call and expect a revert?

## How does QuillShield check for missing slippage protection?

Slippage bugs live in the plumbing around swaps: routers, zaps, harvests and rebalances, often spread across several contracts. QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep.

A separate reviewer agent tries to disprove every finding before you see it, and each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, a proof of concept. For this class, a proof of concept moves the pool before the swap and shows what the protocol accepts.

It then checks every pull request on GitHub or GitLab.com against that graph. New strategies and swap routes keep arriving after the first audit, and each one is a fresh chance to pass 0 as a minimum. [Run a full audit](https://shield.quillaudits.com/register), or [talk to an auditor](https://calendly.com/akshadh-a-quillaudits/30min) before a strategy launch. New accounts get $50 in credit, good for up to half of an order.

## FAQ

### What is a reasonable slippage tolerance?

There is no single number. A deep stablecoin pool needs a far tighter tolerance than a thin pool of a volatile token, so compute the expected output off-chain for each trade and size the tolerance to that pool.

### Is a deadline part of slippage protection?

Yes. Without one, a signed swap can wait unexecuted until the market has moved, and the minimum the user chose no longer reflects a fair price.

### Can a contract compute amountOutMin on chain?

Only from a source the same transaction can't move, such as an oracle price with staleness checks. Reading the pool you are about to trade in gives you the price after any manipulation.

### Does a private mempool remove the need for slippage checks?

No. It hides a transaction from most searchers, but the contract still accepts any price if the minimum is 0, and anyone who can call the function can sandwich it themselves.

## Sources

- [Rhea Finance Rekt, rekt.news](https://alpha.rekt.news/rhea-finance-rekt) · checked 3 December 2026
- [Rhea Finance post-mortem puts exploit losses at $18.4 million, more than double initial estimates, The Block](https://www.theblock.co/post/397961/rhea-finance-exploit-losses-18-4-million-double-initial-estimates) · checked 3 December 2026
- [Smart Contract Weakness Classification Registry, SWC Registry](https://swcregistry.io/) · checked 3 December 2026
- [Maximal extractable value (MEV), ethereum.org](https://ethereum.org/developers/docs/mev/) · checked 3 December 2026
- [Swapping, Uniswap docs](https://developers.uniswap.org/docs/protocols/v2/guides/swapping) · checked 3 December 2026
