DEV Community

amoweolubusayo
amoweolubusayo

Posted on • Updated on

Front running in DeFi and protective measures

So, I started looking at the DeFi space. I have found it interesting so far understanding the technicalities involved in trading especially on Dexs.

This article however will be a less technical which is a little drift from my recent articles as I will be concentrating on one of the common problems traders face using exchanges.

I hope you find this insightful!

Preamble

Have you ever experienced a scenario where you received less than you expected after a trade? Yes? You might just have been front runned.

In this article, I would talk about front running, how to be protected from front running as well as what protocols can do.

Front running in DeFi

Front running is the act of taking advantage of advanced information or prior knowledge of transactions to buy or sell assets. A front runner capitalizes on the way transactions are ordered within a block to take out profit from another trader thereby leading to losses for this trader involved.

On the Ethereum blockchain, there is the problem of front-running where anyone who runs a full-node Ethereum client can see unconfirmed transactions and send transactions with a higher gas price. Actually, front-runners do not even need to run a full node to see transactions. They can have a bot that monitors pending transactions in the mempool or use any infrastructure such as the ones I wrote in this article here Top 5 Web3 infrastructure. Bots are also able to quote a higher gas price. Bots operate in milliseconds so imagine the speed in reading a transaction from the memory pool, calculating the optimal transaction size, configuring transactions and then executing them.

Sadly, front running is such a common practice on Ethereum-based DEXs.

How can we be protected from Front running?

Players involved: DEXs, users, protocols.

What can DEXs do?

Fast Matching orders: Orders can be matched in every block with very fast block times so that there is very little room for front-running to happen

Provide off-chain privacy: Privacy should be taken seriously in markets such as DeFi.

What can users do?

Overpay on Gas: As a user, try to go for the ‘fast’ gas option on your wallet of choice, this way there would be no time for front runners to formulate an order. If you wish to place a large value order, this approach is recommended.

Place value smaller orders: You can also place smaller value orders. Front runners take into consideration gas fees on both entering and exiting the market, so you are most likely safe by trading low cash volume.

What I think protocols can do on the long run

Protocols should consider building untraceable blockchain node infrastructure such that node requests are somewhat hidden from people who wish to manipulate the market.

They can do this by building tools that guarantees no monitoring of blockchain requests. In traditional blockchain, the requests to node providers can be tracked and monitored thus compromising privacy and giving front runners an unfair advantage from your metadata. Protocols can look into building tools with 0 monitoring of blockchain requests.

Any other thoughts are welcome too! Kindly comment below.

I would be posting more DeFi- related articles in the coming weeks/months. Stay tuned…

Top comments (0)