Difference between revisions of "Sandwich Attack"

From CryptoWiki

m (1 revision imported)
 
Line 6: Line 6:


* [https://weekinethereum.substack.com/p/week-in-eth-news-for-nov-8-2020-this?token=eyJ1c2VyX2lkIjoxMzk3OTAwLCJwb3N0X2lkIjoxNzUzMDQzNSwiXyI6ImM5eFJuIiwiaWF0IjoxNjA0OTA5NzkzLCJleHAiOjE2MDQ5MTMzOTMsImlzcyI6InB1Yi0xMDcxIiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.tDm2-Sl4t4NQ3JgkyLwjcMUZ8pOgMKkKFXiCfEtOUNI From] [[Week in Ethereum]] (9-11-2020):
* [https://weekinethereum.substack.com/p/week-in-eth-news-for-nov-8-2020-this?token=eyJ1c2VyX2lkIjoxMzk3OTAwLCJwb3N0X2lkIjoxNzUzMDQzNSwiXyI6ImM5eFJuIiwiaWF0IjoxNjA0OTA5NzkzLCJleHAiOjE2MDQ5MTMzOTMsImlzcyI6InB1Yi0xMDcxIiwic3ViIjoicG9zdC1yZWFjdGlvbiJ9.tDm2-Sl4t4NQ3JgkyLwjcMUZ8pOgMKkKFXiCfEtOUNI From] [[Week in Ethereum]] (9-11-2020):
"''[[Frontrunners|Frontrunning]] and backrunning your [[uniswap]] [[transaction]] to avoid the slippage tolerance."''
"''[[Frontrunners|Frontrunning]] and backrunning your [[uniswap]] transaction to avoid the slippage tolerance."''
 
* From this [https://quillaudits.medium.com/front-running-and-sandwich-attack-explained-quillaudits-de1e8ff3356d blog] (3-11-2022):
 
''"A sandwich attack is a form of front-running, which primarily targets [[Decentralized Finance (DeFi)|decentralized finance]] protocols and services.''
 
''A sandwich attack involves “sandwiching” a user’s transactions in between two transactions. These two transactions are before and after the user's transaction (hence the name sandwich), generating a loss for the user and a gain for the attacker.''
 
''In a sandwich attack, an attacker will first monitor for pending transactions in the [[mempool]]. Then He will find the user's transaction and place two trades, one before the victim’s pending transaction (front-running) and another trading order just after it (back-running). The victim’s pending transaction will be sandwiched between the two new trade orders created by the attacker. The purpose of placing these two orders and surrounding pending transactions is to manipulate asset prices.''
 
''Let us assume that Bob is swapping [[Ethereum (ETH)|ETH]] for [[Polygon (MATIC)|MATIC]] from a Uniswap pool. Now, an attacker monitors his transaction by scanning the mempool, and when he finds his transaction and he immediately places two orders.''
 
''Attacker’s 1st Txn: Swapping ETH for MATIC paying higher [[gas]] fees''
 
''Attacker’s 2nd Txn: Swapping back MATIC for ETH paying lower gas fees''
 
# ''First, the attacker will front-run Alice’s transaction with the same swap (swapping ETH for MATIC) and thus increasing the price of MATIC.''
# ''Now, after the price is increased Alice’s transaction is executed and she ends up paying more ETH for MATIC with higher price slippage.''
# ''Once the victim’s transaction is executed, the attacker will swap his MATIC back to ETH and make a profit."''


== Usage ==
== Usage ==

Latest revision as of 06:28, 14 November 2022

Basics

"An arb bot puts transactions before and after yours to extract all of the slippage you set."

"Frontrunning and backrunning your uniswap transaction to avoid the slippage tolerance."

  • From this blog (3-11-2022):

"A sandwich attack is a form of front-running, which primarily targets decentralized finance protocols and services.

A sandwich attack involves “sandwiching” a user’s transactions in between two transactions. These two transactions are before and after the user's transaction (hence the name sandwich), generating a loss for the user and a gain for the attacker.

In a sandwich attack, an attacker will first monitor for pending transactions in the mempool. Then He will find the user's transaction and place two trades, one before the victim’s pending transaction (front-running) and another trading order just after it (back-running). The victim’s pending transaction will be sandwiched between the two new trade orders created by the attacker. The purpose of placing these two orders and surrounding pending transactions is to manipulate asset prices.

Let us assume that Bob is swapping ETH for MATIC from a Uniswap pool. Now, an attacker monitors his transaction by scanning the mempool, and when he finds his transaction and he immediately places two orders.

Attacker’s 1st Txn: Swapping ETH for MATIC paying higher gas fees

Attacker’s 2nd Txn: Swapping back MATIC for ETH paying lower gas fees

  1. First, the attacker will front-run Alice’s transaction with the same swap (swapping ETH for MATIC) and thus increasing the price of MATIC.
  2. Now, after the price is increased Alice’s transaction is executed and she ends up paying more ETH for MATIC with higher price slippage.
  3. Once the victim’s transaction is executed, the attacker will swap his MATIC back to ETH and make a profit."

Usage