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

CLARITY Act Faces Uncertain Future As David Sacks Exits Crypto Czar Role
News

CLARITY Act Faces Uncertain Future As David Sacks Exits Crypto Czar Role

After David Sacks left his position as the Trump administration’s crypto and AI czar, the future of the CLARITY Act is now...

Nvidia-backed AI Startup Reflection Targets $25B Valuation
News

Nvidia-backed AI Startup Reflection Targets $25B Valuation

According to reports, Reflection, which is supported by Nvidia, wants to raise $2.5 billion at a $25 billion valuation. To compete with...

Tazapay Raises $36M To Expand Stablecoin Payment Infrastructure
News

Tazapay Raises $36M To Expand Stablecoin Payment Infrastructure

Tazapay has raised $36 million in its Series B funding round, with support from Circle, Coinbase, and other investors. The company plans...

Morgan Stanley Moves Closer To Launching Bitcoin ETF
News

Morgan Stanley Moves Closer To Launching Bitcoin ETF

After receiving a listing notice from NYSE Arca, Morgan Stanley is getting closer to launching its spot Bitcoin exchange-traded fund (ETF). The...

Latest Blogs

AI-integrated Crypto Wallet: Safe & Efficient Management?

  Are you a crypto wallet user? If yes, is it an AI-integrated crypto wallet? In case you are wondering what exactly...

AI-enabled Fraud: Real Cases, Scammer Tactics & Smart Prevention Tips

Hey, congratulations! You won the Rs 2 Crore lottery. To withdraw funds, share your bank details along with a one-time password (OTP)...

Healthcare Will Never Be The Same, Thanks To Blockchain

We have all heard this famous saying, “Health is Wealth’. Success, wealth, and accomplishments are meaningless without good health. Nothing is more...

AI-enabled Fraud Detection In Digital Finance

Do you remember the last time you used an Automated Teller Machine(ATM) to withdraw money? Well, with the advent of Unified Payments...

Related Articles

AI-integrated Crypto Wallet: Safe & Efficient Management?

  Are you a crypto wallet user? If yes, is it an...

AI-enabled Fraud: Real Cases, Scammer Tactics & Smart Prevention Tips

Hey, congratulations! You won the Rs 2 Crore lottery. To withdraw funds,...

Healthcare Will Never Be The Same, Thanks To Blockchain

We have all heard this famous saying, “Health is Wealth’. Success, wealth,...

AI-enabled Fraud Detection In Digital Finance

Do you remember the last time you used an Automated Teller Machine(ATM)...