Home What are Sandwich Attacks in DeFi and How to Avoid them?

What are Sandwich Attacks in DeFi and How to Avoid them?

Share
Share

Sandwich Attacks & How To Avoid Them

By Laxmikant Khanvilkar

In these times of decentralized finance, popularly known as DeFi, an investor is vulnerable to several exploits. Some of the most common ways are: flash loan attacks, rug pulls, and more recently, the bitter ones- Sandwich Attacks. It finds more effective use to swindle money from uninitiated investors. The Ethereum creator Vitalik Buterin talked about the Sandwich attack in the context of Uniswap in 2018.

Let us understand ‘sandwich attack’ in simple terms.

The sandwiching occurs by placing one order right before the trade and one right after it. In essence, the attacker will front-run and back-run simultaneously, with the original pending transaction sandwiched in between.

For practical understanding, let us assume a victim trades a virtual digital currency (VDA) e.g. Ether to another asset let say Bitcoin (BTC) and makes a large purchase.

A trading bot sniffs out the transaction and Front-Runs the victim by purchasing BTC before the large trade is approved. This purchase raises the BTC price for the victim trader and increases the slippage (the likely change in price is based on the volume to be traded and the available liquidity).

In the above example, since the purchase of BTC is done at high price, the rate continues to rise, and, hence, the victim ends up buying at a higher value, at which point the attacker concludes selling. It is crucial to understand the basic concept of an attack and the potential ramifications.

Simplifying Sandwich Attack

A sandwich attack, mainly targeted at DeFi protocols and platforms, can have significant consequences and result in market manipulation. Sandwich Attacks may create problematic situations in DeFi. Such attacks often take place in the wild due to the public nature of blockchains, all transactions can be easily traced by anyone in the mempool (unless one has a special direct link to a mining pool). Alternatively, smart contracts may contain functions without access restrictions performing such a trade. These functions often exist for claiming reward tokens and immediately swapping them for some other token using a decentralized exchange (DEX).

Listed below is the course of Sandwich Attack:

  • Detect the victim’s transaction.
  • Front-Run the victim’s transaction.
  • Victim transacts and suffers higher slippage.
  • The attacker then back-runs the victim.

Factors to Consider in Sandwich Attacks

The sandwich attack method makes this type of attack sound straightforward. In reality, it is perhaps too easy to perform. Even if the profit is small, one can use this method repeatedly without any repercussions.

However, a malicious trader needs to be well-prepared to pull off a sandwich attack. There are many intricacies in DeFi to consider which may impact the chance of success.

The majority of sandwich attacks are carried out through automated market maker solutions (AMMs) – a predefined pricing algorithm. It automatically performs price discovery and market-making based on the assets in the liquidity pools. The AMM allows liquidity providers to watch and follow the market, then set the bid and ask prices. Liquidity takers, in their turn, trade against the AMM. Some key examples include Uniswap, PancakeSwap, Sushi and more.

Through their pricing algorithms, liquidity is always in high demand, and trades execute continuously. But you cannot forget about the price slippage aspect, which occurs when the volume and liquidity of an asset change.

Traders also face an expected execution price, an actual execution price and an unexpected slippage rate. Blockchain transactions can take some time to execute and the inter-exchange rates of assets can fluctuate wildly, resulting in more unexpected price slippage – the change in the price of an asset during a trade.

When a liquidity taker issues trade on ETH/BTC, the taker wishes to execute the trade with the expected execution price (based on the AMM algorithm and ETH/BTC state), given the expected slippage.

Despite the clear cut financial incentive, doing so much in the sandwich attack, may not always be worth a shot. The cost of performing these transactions to front and back run other traders will often outweigh the financial gain for attackers.

As DeFi attracts more and more people of late, there will be more opportunities for culprits to strike and reap higher profits through the sandwich attacks.

Protecting against Sandwich attacks

For AMMs, it is essential to develop countermeasures capable of protecting users from sandwich attacks.

For example, the 1inch platform introduced a new order type known as ‘flashbot transactions’ which are not visible in the mempool as they are never broadcasted to it. Instead, the 1inch platform has a direct connection to trustworthy miners to make transactions visible after they are mined.

Till today, it appears to be the only way for users to protect themselves against a sandwich attack. However, it remains unclear if other AMMs will forge partnerships with miners to include transactions without broadcasting them to the mempool. Other solutions may be found in the future, although that will likely take some time.

Conclusion:

From the above, it is clear that the attacker analyses transaction in the Mempool to decide to launch an attack or not. So it would be better to encrypt transaction details.

There are proposals in the community to use zk-SNARKs, a zero-knowledge-proof technique, to achieve this goal. In other words, zk-SNARKs would be used to encrypt and hide each transaction’s information, so the bot could not do anything about it.

There is no full proof approach to control this kind of attack because of high Gas cost and the possibility that it can be used to perform blocking attacks that result in the reduction of overall liveness.

The present scenario is still in R&D work to defend this kind of attack in blockchain mempool.

Share

Latest News

Singapore's Temasek Rules Out Crypto Investments, Plans To Triple AI Portfolio By 2031
News

Singapore’s Temasek Rules Out Crypto Investments, Plans To Triple AI Portfolio By 2031

Singapore’s Temasek has ruled out direct cryptocurrency investments and is prioritizing artificial intelligence (AI) as its long-term growth strategy. The $400 billion...

Tokenized Stock Transfers Double To $8.4B As On-chain Equities Gain Momentum
News

Tokenized Stock Transfers Double To $8.4B As On-chain Equities Gain Momentum

Transfers of tokenized stocks jumped 105% in the past month to $8.41 billion, showing growing demand for blockchain-based equity markets. Data from...

Trump-linked AI Financial Explores $15M Sale Of Core Business After WLFI Token Losses
News

Trump-linked AI Financial Explores $15M Sale Of Core Business After WLFI Token Losses

AI Financial Corporation, the Nasdaq-listed company formerly known as Alt5 Sigma, is reportedly exploring the sale of its core payments business for...

Russia Moves Closer To New Crypto Rules With Simpler Reporting Requirements
News

Russia Moves Closer To New Crypto Rules With Simpler Reporting Requirements

Russia is moving closer to a regulated cryptocurrency market after the State Duma’s Financial Markets Committee approved a revised crypto oversight bill...

Latest Blogs

Crypto Savings 101: How To Earn Passive Income From Stablecoins

Introduction Let’s imagine a hypothetical situation of wanting to sell Bitcoin after a big rally! Suppose you now have $10,000 in your...

How To Know What Drives The Price Of AI Tokens?

Have you ever wondered why some Artificial Intelligence (AI) tokens witness huge price rallies while others struggle to survive? Well, the AI...

5 Ways You Can Make Money From AI Tokens

AI Tokens are perhaps the hottest trend in the cryptocurrency market today and are most likely to become a major investment narrative...

Rise Of AI Memecoins: How AI Is Redefining Memecoin Trading

The world of cryptocurrency has always been full of surprises, but the rise of AI agents in memecoin trading is something new...

Related Articles

Crypto Savings 101: How To Earn Passive Income From Stablecoins

Introduction Let’s imagine a hypothetical situation of wanting to sell Bitcoin after...

How To Know What Drives The Price Of AI Tokens?

Have you ever wondered why some Artificial Intelligence (AI) tokens witness huge...

5 Ways You Can Make Money From AI Tokens

AI Tokens are perhaps the hottest trend in the cryptocurrency market today...

Rise Of AI Memecoins: How AI Is Redefining Memecoin Trading

The world of cryptocurrency has always been full of surprises, but the...