# What is slippage in smart contracts?

URL: https://shield.quillaudits.com/learn/glossary/slippage/

Slippage is the difference between the price a trade expected and the price it actually executes at. In a contract, the defense is a minimum amount out, or a maximum amount in, plus a deadline, so a swap that would fill at a worse price or much later reverts instead.

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

## Why does slippage happen?

The trade itself moves the price in an AMM, more so in a shallow pool, and other transactions can land between the quote and the execution. That second part is where [MEV](https://shield.quillaudits.com/learn/glossary/mev/) comes in, and the Uniswap guide warns that without a minimum, someone can insert transactions before and after a swap so it trades at a worse price ([Uniswap](https://developers.uniswap.org/docs/protocols/v2/guides/swapping)).

## How does a contract protect a swap?

Take the minimum from the user and pass it through. The Uniswap guide recommends the price the trader sees off chain as its source, and says a minimum set on chain has to come from an oracle ([Uniswap](https://developers.uniswap.org/docs/protocols/v2/guides/swapping)).

**Unsafe and safer swaps through a router, with token approvals left out (illustrative, not audited code)** `Zap.sol`

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

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

contract Zap {
    IRouter public immutable router;

    constructor(IRouter router_) {
        router = router_;
    }

    // Unsafe: any output, at any time. A sandwich takes the difference.
    function swapUnsafe(uint256 amountIn, address[] calldata path) external {
        router.swapExactTokensForTokens(amountIn, 0, path, msg.sender, block.timestamp);
    }

    // Safer: the caller sets the worst output and the latest time they accept.
    function swap(uint256 amountIn, uint256 minOut, address[] calldata path, uint256 deadline) external {
        router.swapExactTokensForTokens(amountIn, minOut, path, msg.sender, deadline);
    }
}
```

## What should a reviewer check?

- Every swap, liquidity add and liquidity removal takes a minimum from the caller, and a hardcoded 0 is a finding.
- The minimum isn't computed from a spot price read in the same transaction, which a sandwich moves first.
- The deadline is a parameter, because `block.timestamp` always means the block that includes the transaction and so never expires.
- Multi-hop and vault paths check the final amount the user receives.
- Fee-on-transfer tokens are measured by the balance change, not the amount requested.

In vault code the same bug can hide in a `harvest()` function that swaps rewards with `amountOutMin` set to 0, which hands part of every harvest to whoever sandwiches it. The fix takes the minimum from the keeper that calls it, or prices it from an oracle the swap can't move.

## Sources

- [Swapping (Uniswap V2 guide), Uniswap docs](https://developers.uniswap.org/docs/protocols/v2/guides/swapping) · checked 3 December 2026
