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

Don't Miss

What are Tokenomics and Token Features? | A Beginners Guide

You need to login in order to Like Tokenomics and Token Features Explained By Kapil Rajyaguru One of the biggest issues with tokenomics...

What are Soulbound Tokens? | Soulbound Tokens on The Rise

You need to login in order to Like Soulbound Tokens on The Rise By Ruchi Sharma Digital assets based on blockchain technology known...

Related Articles

What Are Utility NFTs & How Do They Work? | 3.0TV

You need to login in order to Like Demystifying Utility NFT By...

When Will Bitcoin Cross $1 Lakh? | Expert Predictions & Trends 2025

You need to login in order to LikeWhen Will Bitcoin Cross the...

NFT Domains: Revolutionizing Ownership in the Digital Landscape

You need to login in order to LikeNFT Domains: Revolutionizing Ownership in...

Are NFTs a Good Investment: Should You Buy in 2025?

You need to login in order to LikeAre NFTs a Good Investment:...