How Do “Sandwich Attacks” Exploit the Price Changes Caused by Large Trades in an AMM?
A sandwich attack involves a malicious actor detecting a large pending trade in the mempool. The attacker executes a small buy order just before the large trade (the "front-run"), driving up the price.
The large trade then executes at the higher, front-run price, incurring more slippage. Immediately after, the attacker executes a sell order (the "back-run") at the newly inflated price.
The attacker profits from the price movement caused by the victim's trade, and the victim pays a higher execution price.