What is a sandwich attack?

A sandwich attack is when a blockchain attacker sandwiches a swap between two transactions to make a profit.


How does a sandwich attack work?

  1. A user submits a swap, and it is pending confirmation.
  2. A blockchain attacker sees the pending transaction  and knows the price for the token swapped will increase. So, they submit a swap. This is called front-running.
  3. The blockchain attacker's swap is completed at a low price.
  4. The user’s transaction is completed at a high price, which means they receive fewer tokens than expected.
  5. The blockchain attacker swaps the tokens again at a higher price. This is called back-running.


The blockchain attacker profits from the increase in price from the previous transactions. This results in a gain for the attacker, and a loss for the user.

 

These attacks are possible because of price slippage and the blockchain's transaction transparency.

 

Here are some ways to reduce the risk of sandwich attacks:

  1. Use large liquidity pools. Attackers target small liquidity pools because their transactions have a larger effect on a token's price.
  2. Use swap protection. If your wallet offers swap protection using a MEV Blocker, it can protect your swap from sandwich attacks and front-running.