Don't Get Rekt

Smart contract bugs / 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.

7 real exploits · $11.7M lost

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 and fixed code

Vulnerable
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
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)

  • May 28, 2023Arbitrum$7.5MFlash loan

    Jimbo's Protocol: 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.

    Root cause and fix

    Vulnerable code: JimboController · shift()

    The shift() function in JimboController rebalances by moving the contract's WETH into the liquidity pool, but it has no slippage control. It does not check that the pool price is sane first. The attacker flash-borrowed 10k ETH and bought JIMBO, which pushed the price up. They then deposited some of the overvalued JIMBO into the controller, which triggered shift() and sent the contract's WETH into the pool at the inflated price. Finally they sold the rest of their JIMBO into the pool, drained the WETH, and crashed the price.

    What would have stopped it: Add slippage and price-deviation checks to shift(). For example, compare the pool price against a TWAP or an external oracle, and revert if it has moved beyond a set bound. Also stop rebalances from running in the same block as large price swings. Fuzz and flash-loan simulation tests would catch this.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Jan 12, 2026Ethereum$3.7M

    YO Protocol: 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.

    Root cause and fix

    Vulnerable code: Odos Router V2 · executePath

    The Automated Harvesting System sent a swap through Odos Router without the guardrails used by other trading systems. Its slippage check only compared execution against the starting quote and did not check whether that quote was sane. The bad output quote (a slippage parameter of 17,872,058) let the swap route through thin pools with 85-88% fee tiers. About 97% of the $3.71M position went to liquidity providers, and the vault got 112,036 USDC.

    What would have stopped it: Compute the minimum acceptable output independently on-chain, for example from an oracle price plus a tight tolerance. Do not use a quote supplied by the keeper. Also cap price impact, restrict allowed pools and fee tiers, and cap the size of a single swap.

    rekt.news article ↗

  • Nov 6, 2023Arbitrum$290KFlash loan

    TheStandard.io: 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.

    Root cause and fix

    Vulnerable code: SmartVaultV2 · swap()

    The SmartVaultV2 swap() function swapped collateral on Uniswap V3 without a proper minimum-output (slippage) limit. The attacker created a WBTC/PAXG pool at a skewed price with one tiny full-range position. They flash-loaned WBTC, deposited it in a new vault and minted about 290K EURO. They then called swap() to trade WBTC for PAXG in the manipulated pool, which gave the vault's collateral away at a bad rate. After that they removed their liquidity and collected the proceeds. They swapped the EURO to USDC and then to WBTC, and repaid the flash loan.

    What would have stopped it: Compute the minimum output in swap() from a trusted oracle price (for example Chainlink) and pass it as amountOutMinimum. Also restrict swaps to pools that are known to be liquid and not manipulable.

    Run the exploit (Foundry PoC) ↗

  • Nov 10, 2025Ethereum$100KFlash loan

    DRLVaultV3: 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.

    Root cause and fix

    Vulnerable code: 0x6A06707ab339BEE00C6663db17DdB422301ff5e8 · swapToWETH()

    The vault's publicly callable swapToWETH(_amount) swaps vault USDC into WETH on a USDC/WETH Uniswap V3 pool without a meaningful minimum output or price check. The attacker borrowed about 13.98M USDC from Morpho and swapped it through a DEX router to push the WETH price far up. They then called swapToWETH(100,000 USDC), so the vault bought WETH at the inflated price. Finally they swapped back to restore the price, repaid the flash loan and kept the difference. This reading comes from the PoC and the post-mortem title, which names slippage.

    What would have stopped it: Compute a minimum output from a trusted oracle, such as a TWAP or Chainlink feed, and revert if the swap returns less. Restrict swapToWETH() to a trusted keeper role, or pass a slippage limit that is not set by the caller.

    Run the exploit (Foundry PoC) ↗

  • Aug 2, 2023Ethereum$36KFlash loan

    Curve Finance (CurveBurner): An attacker sandwiched Curve's CurveBurner execute() call, which swapped fees through the 3pool with no slippage protection, and took about $36K.

    Root cause and fix

    Vulnerable code: CurveBurner (0x786b374b5eef874279f4b7b4de16940e57301a58) · execute()

    CurveBurner.execute() is publicly callable and adds USDT-only liquidity to the Curve 3pool, which swaps the fees with no minimum-output or slippage check. The attacker took huge flash loans from Balancer and borrowed more from Aave and Compound. They used the funds to skew the 3pool by adding USDT and removing most of the DAI and USDC. They then called execute(), so the burner traded at a bad price. Afterwards they restored the pool balance, withdrew USDT at a profit, repaid every loan and kept the difference.

    What would have stopped it: Require a minimum-output or slippage bound on the burner's swap and liquidity operations, based on a trusted price. Restrict who can call execute() and when, or use a private relay, so a bot cannot sandwich it.

    Run the exploit (Foundry PoC) ↗

  • Jul 17, 2023BNB Chain$31KFlash loan

    NewFi: 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.

    Root cause and fix

    Vulnerable code: StakedV3 (0xB8dC09Eec82CaB2E86C7EdC8DD5882dd92d22411) · Invest()

    The Invest() function removes liquidity and swaps BUSD and USDT on a PancakeSwap V3 pool without a real minimum-output limit. The quoteAmount the caller passes is trivially small (2), and the contract does not check the price against a trusted source. The attacker flash-borrowed BUSD from three Pancake V3 pools and swapped 12M BUSD to USDT to skew the pool price. They then called Invest(), which swapped at the bad price. Finally they swapped back and repaid the flash loans, keeping the profit.

    What would have stopped it: Enforce a minimum output computed on-chain from a trusted price source such as a TWAP or Chainlink. Do not accept a caller-supplied quote. Reject swaps when the pool price deviates from the reference price.

    Run the exploit (Foundry PoC) ↗

  • May 22, 2024EthereumFlash loan

    Burner: Burner lost about 1.7 ETH to a sandwich attack on its public convertAndBurn() function, which swaps into PNT with no slippage protection.

    Root cause and fix

    Vulnerable code: Burner · convertAndBurn()

    The public convertAndBurn(address[] tokens) function swaps the contract's token balances into PNT on an AMM with no minimum output or price check, and anyone can call it. The attacker bought PNT with a large amount of WETH (simulated as a flash loan), which pushed the price up. They then called convertAndBurn so the Burner bought PNT at the inflated price. Finally they sold the PNT back for WETH and kept the difference.

    What would have stopped it: Set a minimum output (slippage limit) on the swaps in convertAndBurn, derived from a trusted oracle or TWAP price. Also restrict who can trigger the conversion, or run it through private order flow so it can't be sandwiched.

    Run the exploit (Foundry PoC) ↗

References

Send a new scam

Describe what happened, or paste a link to the post. Do not include seed phrases, keys or passwords.

Open the post ↗