*Paid Advertisement. Not financial advice. RugDoc is not responsible for the projects showcased here. DYOR and ape safu.

Sandwich Attack

A Sandwich Attack is a front running attack on a decentralized exchange (DEX), in which influence is exerted on the initial price of a swap. The attacker takes precedence over this transaction and buys this coin at the current bargain price and then sells it to the victim at a more expensive price. The victim is in between the two transactions, like a sandwich. A sandwich attack is a common attack that takes place in the world of DeFi.

Front running attack & mempool #

The Sandwich Attack is part of a front running attack. A transaction is not immediately added to the blockchain, but they are first collected as part of blocks. A block is therefore a collection of all transactions that are ready to be executed.

The nodes in the network are then notified of these transactions. When nodes receive a copy of this transaction, they add it to the pool of unused transactions, called the mempool.

When a new block is created on the blockchain, the creator of this block processes all these unused transactions. The order is determined by the amount of the transaction costs. The higher the gas fee, the faster your transaction will be completed.

In these few minutes a front running attack happens. They benefit from the process of adding transactions based on transaction costs. An attacker has the ability to ensure that its transaction is processed before any other transaction by including higher transaction costs. By definition, a front running attack is the privilege of influencing information before others can.

By having this extra information, a front runner knows which transactions are in the mempool and which have not yet been added to a block. This allows a front-runner to place a trade in a block for someone else. How? By looking at the transaction cost of the current transaction, and surpassing it by means of a higher transaction cost. Miners treat transactions with a higher fee first.

At first you would think that this makes sense, that the person with the highest transaction cost is given priority. But front runners can exploit this to harm other users. Front runners can also apply this strategy to Ethereum Name Service. Imagine that you want to register a domain name with Ethereum to ensure that your network is found well by means of a nice name.

A front runner can therefore see this information earlier and use this information. This front runner can then sell you this domain name at a higher price. Ethereum Name Service has protected itself from this problem, this is just as an example.

Slippage #

We know slippage in DeFi when the trader receives a different price than was initially expected. The price at which your order was executed does not correspond to the price that was requested. In addition to the lack of liquidity, a volatile market can also be the cause of this slippage. For example, when you have a trade ready, and the value of these assets suddenly dips.

So how can a front runner influence this? By finding out information from the trade that is not yet included in the block, and then changing this price so that you can only execute your trade at a higher price. A front runner can earn thousands of dollars from this by performing the same attack over and over.

The higher you set your slippage on a DEX, the more likely it is that a frontrunner will use it to influence the price. The bigger your silppage, the more willing you are to actually receive less tokens. These front runners, mostly bots, notice this and will do everything they can to ensure that you get your tokens against the worst-case scenario you enter. For example, do you opt for 20% slippage? Then you will also get 20%, not 15%. Why? If that option were there, the front runner would run away with the better deal.

How to avoid Sandwich Attacks #

Front running and sandwich attacks affect the entire network. It makes trading in DeFi no longer attractive to some, even though the possibilities in DeFi are endless. After all, who wants to pay more than the current price? Therefore, there are a number of ways to minimize these attacks:

Gas price limit #

These attacks can only happen because higher gas fee transactions take precedence over others. By setting a certain limit on this gas price, preferential treatment will take place to a lesser extent. The impact will be less significant. You can never completely eliminate this problem, because there are always differences in gas fees. But by making this difference less significant, it will then also happen less quickly.

Avoid low liquidity pools #

Lack of good liquidity is detrimental to this problem. The smaller this pool, the smaller the chance that an investor will get a good price, because this is more prone to slippage. The higher the slippage, the more profit you can get from a sandwich attack.

Smaller trades #

A sandwich attack is only interesting with larger trades. The bigger the trade, the bigger the profit margin. One way to avoid sandwich attacks is to split your trade into several smaller trades. These small transactions are not interesting enough for front runners. It is true that you always pay a transaction cost on these smaller transactions instead of one fee on the entire trade. This is a choice you make yourself.

Updated on July 26, 2022
How do you feel about this article?

Leave a Reply

*Paid Advertisement. Not financial advice. RugDoc is not responsible for the projects showcased here. DYOR and ape safu.

Our mission here at RugDoc is to screen for hard rug code that results in 100% theft of ALL underlying funds for ALL participants.

This is the ONE part of the due diligence process that most people cannot simply do on their own as it costs thousands of dollars to hire a senior solidity developer to look over a farm for safety.

A project coin with terrible code can go up in price, and a project with good code and a good team can also go down in price.

Do NOT use our ratings to refer to your likelihood in making money if you invest in the project. They are ONLY in reference to code safety.

Everything else beyond code safety is YOUR responsibility to go do research on. We just make sure the casino you’re betting in won’t rob you before you even get to place a bet.

Our reviews for projects are organized into a few colors.

🟢 Least Risk
These projects are the least likely to hard or soft rug. Usually reserved for cornerstone projects of an ecosystem where it makes no financial sense for them to rug in any manner as they make more money just being legit.

🔵 Low Risk
These projects are usually established projects in an ecosystem that have a track record of success or have KYC’d to us or other authoritative sources in the real world. As a result, it is extremely unlikely for them to soft rug or hard rug their projects. The projects can still fail and the token price can go down, but usually more as a result of natural market forces.

⚪️ Some Risk
This is the default rating for projects with unknown teams but have code that is unlikely to have hard rug risk. Since the team is unknown and doesn’t have a track record of success, it’s entirely possible that they may try to soft rug by dumping tokens, abandoning the project, etc. Even a last minute contract swap to a malicious contract is possible. The only thing that is unlikely is a complete hard rug as long as you are 100% sure you deposit into the contract we review.

🟠 Medium Risk
Similar to Some Risk, but the underlying code itself is custom enough or complex enough that it warrants an elevated risk rating that needs deeper research. Make sure you read every point presented to make sure you’re comfortable with that before entering. Still unlikely to hard rug, but more chances of custom code behaving incorrectly and causing other issues.

🔴 High Risk
Project contains code or practices that are HIGHLY LIKELY to lead to catastrophic losses as they are right now. Make sure you read the description carefully as we will always warn what these issues are. If you see the words Hard Rug anywhere in the review, STAY FAR AWAY!

⚫️ Not Eligible
We reserve the right to not review exceedingly complex projects that would require tens of thousands of dollars of senior security analyst man hours. Typically these are projects that deal with leverage, lending, options, derivatives, and anything that is overly complex and which requires tons of peer reviews and audits from top audit companies.

Search

🟢 For owners who have made impactful changes and would like an update to their farm review:

1️⃣ Use #update at @RugDocChat with your description and proof of changes and it will be forwarded to our scanners.

2️⃣ This does not guarantee a change in your review.

3️⃣ Owners who have difficulty solving the issues can consider our Consultation Package - please contact @BaymaxCrypto on Telegram to discuss.