# What is a Sandwich Attack? How MEV bots steal from you in DeFi

> A Sandwich Attack is a maneuver through which you can lose everything at the hands of bots that manipulate your trades and the entire DeFi market.
> By José Maldonado · DeFi · 2026-03-16

Imagine you find the perfect entry point to buy a token on a decentralized exchange (DEX) and make a good profit. You confirm the transaction, pay the gas and yet, when you check your wallet, you notice you have received fewer cryptocurrencies than the screen showed. No, it is not a smart contract error or bad luck with volatility; you have just been the victim of a Sandwich Attack.

## Anatomy of an ambush: How does a Sandwich Attack work?

A sandwich attack, **is a price manipulation maneuver executed with millimetric precision on the blockchain, taking advantage of the very mathematical architecture of decentralized exchanges (DEX).**

To understand its effectiveness, it is worth remembering that platforms based on Automated Market Makers (AMM) determine the price of an asset according to the proportion of tokens within a liquidity pool.

When a large order is about to be executed, the balance of that pool will inevitably change. It is precisely this algorithmic certainty that attackers exploit. The whole process consists of three precise moves, often executed within the same block of transactions, which wrap around and squeeze an ordinary user's trade.

**[JP Morgan accused of facilitating a $328 million crypto Ponzi scheme](https://observatorioblockchain.com/en/crypto/jp-morgan-acusado-de-facilitar-un-ponzi-cripto-de-328-millones/)**

## Front-running, illegal in TradFi, "legal" in DeFi

The first move, known as front-running or the "top slice," takes place in the shadows of the network before your transaction is official. When the attacker, through their bot, detects a considerable buy order pending validation in the mempool, they immediately issue their own buy order for the same asset. This is a practice that in TradFi is illegal in many parts of the world, but in DeFi, anyone can do it.

Therefore, to ensure that validators process their operation first, the bot pays a much higher network fee (gas) or uses private channels to send a direct incentive to the block builder. This initial bot purchase alters the balance of the liquidity pool and raises the token price artificially, taking it in a calculated way right up to the slippage tolerance limit that the unwary user had configured.

## Filling the Sandwich

Next comes the time to "fill" the sandwich. The user's original transaction is finally executed on the market. However, due to the bot's prior manipulation, the user ends up buying the asset at this new inflated price.

When this purchase is completed, the proportion of tokens in the liquidity pool suffers a second impact, pushing the asset's value even higher. The user receives far fewer tokens than the graphical interface had initially estimated, absorbing the entire loss generated by the forced price variation.

Finally, the attacker closes the trap with back-running or the "bottom slice." In the same fraction of a second, and algorithmically packaged in the same block to avoid any risk of external volatility, the bot launches a sell order.

It offloads all the tokens it acquired in the first step, but now sells them at the maximum price generated by the victim's purchase. The attacker pockets the price difference as a net, risk-free profit, while the user bears the full cost of this extractive financial engineering, leaving the trade with a silent deficit in their wallet.

**[Binance sues The Wall Street Journal over a report on alleged ties to Iran](https://observatorioblockchain.com/en/crypto/binance-demanda-al-wall-street-journal-por-un-reportaje-sobre-iran/)**

## The role of MEV bots: The predators of the Mempool

Of course, all this financial choreography is not executed manually by humans; it would be extremely difficult to do and succeed at. That is the reason MEV bots exist, commonly known as Maximal Extractable Value bots.

These algorithms are designed with a single purpose: **to incessantly scan the mempool, which is the public waiting room where transactions await inclusion in the next block.**

The bots analyze every pending transaction in real time, looking for arbitrage opportunities or profitable manipulations. When they detect an ordinary user sending an order to a decentralized exchange, the algorithm instantly calculates whether the volume is sufficient to justify an attack.

If the numbers add up, the bot injects its own transactions with priority fees calculated to the millimeter, manipulating the block order in its favor and acting as an invisible predator in the ecosystem.

## Why you? The danger of a poorly configured Slippage

MEV bots do not attack at random; they look for specific vulnerabilities, and the most common is a poorly configured price slippage level.

Slippage is the maximum percentage of price variation that a user is willing to tolerate from the moment they confirm the transaction until it is executed on the blockchain.

Many users, out of ignorance or in an attempt to speed up their purchases during periods of high volatility, leave this value at automatic or excessively high levels. By doing so, they are basically telling the market that they are willing to pay a significant premium.

The bots interpret this tolerance as an open door and manipulate the price exactly up to that maximum permitted limit, making sure to extract as much value as possible without the victim's transaction being rejected by the smart contract.

This is precisely what happened with the attack on the trader who lost 50 million dollars, due to a poor configuration and swap rules applied by AAVE and CoW Protocol.

**[A trader used AAVE to buy their token and lost 50 million dollars](https://observatorioblockchain.com/en/defi/un-trader-uso-aave-para-comprar-su-token-y-perdio-50-millones/)**

## Anti-MEV Shield: Tools and settings to trade safely

Fortunately, the ecosystem has developed robust technical mechanisms to neutralize this threat. The first line of defense is operational discipline: manually adjusting slippage tolerance to low, realistic levels drastically restricts attackers' profit margin, making the sandwich no longer mathematically profitable for the bot. For more advanced protection, adopting private RPC endpoints is essential.

Tools such as [**Flashbots Protect**](https://protectrpc.flashbots.net/) allow transactions to be sent directly to validators through dark channels, completely bypassing the public mempool and making the order invisible to predatory algorithms.

In addition, the evolution of decentralized exchanges has given rise to platforms that integrate native protection against MEV, using order-matching mechanisms and batch auctions that eliminate the possibility of manipulating transaction order, guaranteeing a truly fair trading environment.

In any case, if you are an actor in DeFi, remember that MEV bots are out there lurking, and that you should seek measures to protect yourself. Learning about how these attacks work and which allies you can count on is the first step to avoid falling victim to these attacks, and their consequences.
