---
title: "Front-running, sandwiches and missing slippage"
url: https://dontgetrekt.today/dev/frontrunning-mev
section: "In what order does it run?"
---

# Front-running, sandwiches and missing slippage

A transaction waits in the public mempool before it is mined. A bot sees it, copies it or trades around it, and takes the profit.

## How the attack works

1. A swap has no minimum output (`amountOutMin = 0`) or no deadline.
2. A bot sees the transaction in the mempool. It buys first, lets the victim buy at a higher price, then sells.
3. Variants: a public `claim()` or rescue transaction that a bot copies and sends with a higher fee; a contract that swaps its own fees at any price; a first-come initializer.

## Vulnerable code

```solidity
function harvest() external {
    uint256 r = rewardToken.balanceOf(address(this));
    router.swapExactTokensForTokens(r, 0, path, address(this), block.timestamp);
    // amountOutMin = 0 and deadline = now: a sandwich takes most of r
}
```

## Fixed code

```solidity
function harvest(uint256 minOut, uint256 deadline) external onlyKeeper {
    uint256 r = rewardToken.balanceOf(address(this));
    uint256 fair = r * oraclePrice() / 1e18;
    require(minOut >= fair * 99 / 100, "slippage too high");   // max 1%
    router.swapExactTokensForTokens(r, minOut, path, address(this), deadline);
}
```

## Review checklist

- Every swap needs a minimum output from the user or from an oracle, and a real deadline.
- Do not let anyone trigger a swap of protocol funds at any price.
- Use commit-reveal for actions where the first caller wins.
- For sensitive transactions (whitehat rescues, admin actions), use a private mempool such as Flashbots Protect.

## How to test for it

- In a fork test, move the pool price before the call. The call must revert when the price is worse than the limit.

## Real exploits (7)

- 2023-05-28 Jimbo's Protocol ($7.5M): Jimbo's Protocol lost about $7.5M on Arbitrum when an attacker used a flash loan to exploit the missing slippage control in JimboController's shift() rebalance. [rekt.news](https://rekt.news/jimbo-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-05/Jimbo_exp.sol)
- 2026-01-12 YO Protocol ($3.7M): YO Protocol lost about $3.71M when its automated harvest keeper swapped stkGHO to USDC via Odos with a bad quote that effectively disabled slippage protection, returning only $112k. [rekt.news](https://rekt.news/yo-protocols-slippage-bomb)
- 2023-11-06 TheStandard.io ($290K): TheStandard.io lost about $290K on Arbitrum because the SmartVault swap() had no slippage protection, so an attacker could swap through a pool they had manipulated. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-11/TheStandard_io_exp.sol)
- 2025-11-10 DRLVaultV3 ($100K): DRLVaultV3 lost about $100K when its public swapToWETH() swapped USDC to WETH with no slippage protection, letting an attacker sandwich it with a flash-loaned price push. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2025-11/DRLVaultV3_exp.sol)
- 2023-08-02 Curve Finance (CurveBurner) ($36K): An attacker sandwiched Curve's CurveBurner execute() call, which swapped fees through the 3pool with no slippage protection, and took about $36K. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-08/CurveBurner_exp.sol)
- 2023-07-17 NewFi ($31K): NewFi on BNB Chain lost about $31K because StakedV3.Invest() swapped on a pool with no slippage protection, so an attacker sandwiched it with flash-loaned BUSD. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-07/NewFi_exp.sol)
- 2024-05-22 Burner: Burner lost about 1.7 ETH to a sandwich attack on its public convertAndBurn() function, which swaps into PNT with no slippage protection. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2024-05/Burner_exp.sol)

## References

- [SWC-114: Transaction order dependence](https://swcregistry.io/docs/SWC-114/)
- [Flashbots Protect](https://docs.flashbots.net/flashbots-protect/overview)
