What is a sandwich attack in crypto ?

Crypto blog

What is a sandwich attack in crypto ?

sandwich attack crypto

If you are getting into crypto trading and more precisely bot trading, maybe you have already heard about sandwich attack in crypto trading.

But what exactly is a sandwich attack and why should you know about it? In this article, we will explain what a sandwich attack is and how it is used in the crypto world.

I will try to use as simple words as i can to explain this concept that can be hard to understand if you are not familier with this concept.

A sandwich attack bot is a type of automated computer program that is used to manipulate the price of a cryptocurrency.

Moreover, you must know that there is some scams going around in crypto sphere, making you believe that you can earn money yourself by using this method. Please refer to this article after understanding what is a sandwich attack :

How does work a sandwich bot attack ?

First of all, you need to understand how a transaction works on blockchains.

Concept of mempool in crypto transactions

Transactions made on the Bitcoin network or any other crypto are not directly added to the blockchain.

They are first collected and stored in what’s called the”memory pool”.

this is a temporary storage area for transactions that is created by the software running the blockchain. This is called the “memory pool” but often named “mempool” for short.

This mempool is really important in order to understand a sandwich attack in crypto. Now, you need to understand what is MEV.

What is a MEV in crypto

MEV is an acronym for Maximum Extractable Value.

It represents the maximum amount of value that can be extracted from a trade without compromising the security of the underlying asset. It is a concept that was first introduced by Ethereum developers who wanted to ensure that traders would not be able to take advantage of any weaknesses in the blockchain to extract more value than was intended.

The MEV of a mempool represents all the gas fees of these transactions. On a proof of work blockchain, this is what goes to miners.

MEV as a maximum tax fee in the mempool

In order to understand how MEV works, it’s important to first understand the concept of liquidity. Liquidity is the ability to quickly and easily convert assets into cash. In a traditional market, the liquidity of an asset is represented by the bid-ask spread, which is the difference between the highest price someone is willing to pay for an asset and the lowest price someone is willing to sell it for.

In cryptocurrency, the liquidity of an asset is determined by the amount of buyers and sellers in the market, as well as the amount of assets available.

MEV takes this concept one step further by limiting the amount of value that can be extracted from any given trade or group of trades. This is done by setting a maximum amount of value that can be taken out of any given trade before the order is filled.

For example, if a trader is buying a cryptocurrency for $10 and the market is offering a price of $11, the trader can only take out a maximum of $10 worth of value from the trade. Any additional value that is extracted from the trade will be returned to the market, ensuring that no one person is taking advantage of the system.

The concept of MEV also helps to create a more secure trading environment. By limiting the amount of value that can be taken from a trade, it makes it more difficult for malicious actors to manipulate the market and extract more value than intended. Additionally, it helps to ensure that the price of cryptocurrencies remains stable and that the market is fair for everyone involved.

In a mempool, the most expensive transactions have priority because of this gas fee. Because of this hierarchy, it is easy to determine which trade is going first. Some people understood that, and created bots that could take advantage of this information.

This is where sandwich attack is born.

What is a bot sandwich attack ?

Now you understand what is a mempool (all the pending transactions of a future block), and a MEV (all the fees of these transactions).

Now, let’s dive into this sandwich attack.

In order to explain this, let’s use an example to make it easier to understand.

Example of a sandwich attack in crypto trading

Let’s say someone who has a lot of money wants to buy a lot of some Ethereum. He will put a buy order on a specific price. He will also choose a slippage in % (this represents the maximal price variation you are willing to pay on your purchase. let’s say you put 1%, if ethereum goes up to 2 % by the time your transaction is about to get executed, it is then cancelled. If it only goes 1% up, the transaction will occur, but 1% more expensive).

With this slippage, you also choose a gas fee for your transaction. The more you pay, more chances you have to have priority in the mempool.

Now let’s get back to the bot.

Bot placing order before and after the “big transaction” : the sandwich

Because bots access the “mempool” (where transactions are temporarly stored before being executed on the blockchain), they know what transactions are pending, and more importantly, how much gas fees are paid. They know what priority order is in this mempool.

With this information in mind, they place two orders at the same time. The first order is placed at the lowest price, with a higher gas fee than the big transaction. Consequently, the bot transaction have priority on the guy buying Ethereum. While the second order is placed at a higher price, with a lower gas fee, right behind the big transaction.

The sandwich effect on trades

This creates a “sandwich” effect, where the price of the cryptocurrency is manipulated between the two orders. Why is it manipulated ? Because of the big transaction in the middle, the price is most likely to go up. Simple rule of market, buying pressure, price goes up. The clever bot now sells the token he bought right before this big transaction, at a higher price, thus making a profit.

The purpose of a sandwich attack is to benefit from the difference in price between the two orders. This is done by first buying the cryptocurrency at the lower price and then quickly selling it at the higher price. The gas fees make it easy for the bot to adjust priority order in the mempool, making sure transactions are made at the exact right time.

This allows the attacker to make a profit without having to actually own the cryptocurrency, but more importantly taking minimum risks, as they can accurately predict how the price is fluctuating.

The sandwich attack is an effective way to manipulate the price of a cryptocurrency, as it is able to buy and sell quickly before the market can react. This makes it difficult for the market to detect the manipulation and counter it.

Consequences of a sandwich attack on users

Because of this price manipulation, you could be paying more for your trades. The bot is artificially making prices vary in a shot period of time, making you pay more because of the slippage, explained earlier.

How to avoid sandwich attack while trading crypto

However, this would never excess your slippage percentage, so you just make sure to limit it to 1% or less. You don’t have to worry much about this kind of attack on your daily trades.

The most important thing to remember about this is that there is people around here making you believe you could earn a lot of money using this kind of bot. Be extremely careful !!


To read more about cryptos :

How to create a trading bot without coding : Coinrule

What is DCA in crypto investment ?

Why is Bitcoin a revolution ?

 

Leave a Reply

Your email address will not be published. Required fields are marked *