A sandwich attack is a type of MEV (Maximal Extractable Value) strategy used in decentralized exchanges (DEXs). It involves the attacker placing two transactions on either side of a legitimate trade transaction to capture profits from the trade.
Here's how a sandwich attack works:
1. The attacker monitors the DEX for a large trade transaction that will move the price of the traded asset.
2. The attacker quickly places two transactions, one before and one after the legitimate trade transaction, with the goal of profiting from the price movement caused by the legitimate trade.
3. The first transaction placed by the attacker is to buy the asset that will be traded in the legitimate trade, but at a slightly lower price. This will make the legitimate trader's buy order more expensive.
4. The second transaction is to sell the asset immediately after the legitimate trade is executed, but at a slightly lower price. This will make the legitimate trader's sell order less profitable.
5. The attacker then profits from the price movement caused by the legitimate trade, as the legitimate trader's order was executed at a less favorable price due to the first transaction placed by the attacker, and the attacker's sell order was executed at a more favorable price due to the second transaction.
The sandwich attack is a form of MEV, where the attacker seeks to extract maximum value from the DEX by exploiting the order flow and price movement caused by legitimate trades. However, sandwich attacks can harm the integrity and fairness of DEXs, as they prioritize the profits of the attacker over the interests of other traders.