What are DeFi Sandwich Attacks?

by | Oct 21, 2021

Disclaimer: Posts on the HyperTrader blog and associated HyperLinq websites are for educational and informational purposes only. These posts should not be taken as financial advice, nor are they meant to be viewed as trading advice. HyperLinq Inc. or the authors take no responsibility for any damages or losses.

First of all, we’re not talking about hitting anyone with a bunch of sandwiches. The DeFi landscape offers various innovative features and solutions, but at the same time, requires a big learning curve and is full of scams, attacks, and rug pulls.

So, today, we’ll try to explain and understand a particular kind of DeFi attack known as Sandwich attacks. So, let’s begin.

What is a Sandwich Attack?

To understand the concept of sandwich attacks and how do they work, we’ll first need to understand a few terms. The first term is price slippage. The price slippage can be defined as the change in the price of an asset during the trade. In the context of decentralized finance, whenever you’re trading on a DEX such as Uniswap, you’ll notice the price slippage mentioned under the swap button.

To understand the sandwich attacks, we’ll also need to take a step back and remind ourselves of the concept of automated market makers aKa AMM. To get a better grasp of the concept, head to our explainer: What are Automated Market Makers?

In our AMM explainer blog post, we understood how AMMs use a constant product formula and the algorithm automatically dictates the prices of assets depending on the demand and supply after every trade.

In essence, the price of an asset can substantially increase or decrease with a single big trade. That’s what sandwich attackers take benefit of, by sandwiching a big transaction by simultaneously front-running and back-running it.

So, Here’s How A Sandwich Attack Works

Let’s understand the working of a sandwich attack in a step-by-step scenario:

  • The attacker detects the victim’s transaction in the memepool.
  • They front-run the victim’s transaction by attaching a higher transaction fee, thus ensuring the attacker’s transaction gets executed before the victim’s.
  • Victims’ transactions get executed and suffer higher slippage by paying higher for an asset than they expected because of the attacker’s transaction resulting in an increase in the price of the asset.
  • The attacker then back-runs the victim and makes a profit.
  • Thus executing a sandwich attack – sandwiching the victim’s transaction with two transactions.

For example, if a victim wanted to swap her USDC for ETH. The attacker will front-run the victim’s transaction with the same swap (swapping USDC for ETH) and thus increasing the price of ETH. Now, the victim will end up paying more USDC for the ETH with higher price slippage. Once the victim’s transaction is executed, the attacker will swap her ETH back to USDC and make a profit.

It’s worth noting that the attacker can only make a profit when the transaction amount is big enough since the transaction costs on the Ethereum network can be really high.

Now, the questions arise, how can you be safe from such attacks? Unfortunately, you can’t really do anything about it as a user, unless the decentralized exchange (DEX) or the given DeFi platform develops a countermeasure to such attacks. Since the DeFi landscape is innovating at a massive scale, hopefully, we’ll have a countermeasure for such attacks real soon.

Head of Content Marketing @ HyperLinq. His love for Chai and mountains precedes everything. Often wonders about things like, "why $1 earned through leverage feels 100x better than $1 earned selling your time?"

All You Need To Know About Bitcoin ETFs

Introduction to Bitcoin ETFs and their advantages & disadvantages.

Announcement: Now Trade on FTX Derivatives with HyperTrader

We, at HyperLinq, are delighted to announce the onboarding of FTX Derivatives as our newest crypto exchange to support trading on our native desktop app, HyperTrader. Thus enabling FTX Derivatives traders to supercharge their crypto trading and experience reduced...

Introduction to Blockchain Stack

What is blockchain stack and what are various layers of a blockchain stack?

How Blockchain Governance Works?

Understanding the working of blockchain governance and how incentives are aligned across various participants.

Understanding Blockchain Governance

Understanding what is blockchain governance, its benefits, and how it works?

What is Bitcoin Taproot Update?

What is Bitcoin Taproot Update?

Metaverse 101: The Future is Here

All you need to know about Metaverse.

What are Blockchain Domains?

What are blockchain domains and what are their benefits over traditional domains?

Real-World Use-Case of Smart Contracts

What are the real world use cases of smart contracts?

What is IPFS?

What is InterPlanetary File System and how it works?

All You Need To Know About Bitcoin ETFs

Introduction to Bitcoin ETFs and their advantages & disadvantages.

Announcement: Now Trade on FTX Derivatives with HyperTrader

We, at HyperLinq, are delighted to announce the onboarding of FTX Derivatives as our newest crypto exchange to support trading on our native desktop app, HyperTrader. Thus enabling FTX Derivatives traders to supercharge their crypto trading and experience reduced...

Introduction to Blockchain Stack

What is blockchain stack and what are various layers of a blockchain stack?

How Blockchain Governance Works?

Understanding the working of blockchain governance and how incentives are aligned across various participants.

Understanding Blockchain Governance

Understanding what is blockchain governance, its benefits, and how it works?

What is Bitcoin Taproot Update?

What is Bitcoin Taproot Update?

Metaverse 101: The Future is Here

All you need to know about Metaverse.

What are Blockchain Domains?

What are blockchain domains and what are their benefits over traditional domains?

Real-World Use-Case of Smart Contracts

What are the real world use cases of smart contracts?

What is IPFS?

What is InterPlanetary File System and how it works?

%d bloggers like this: