paint-brush
MEV Bots: How Do They Influence The Crypto Market?by@nftbro
122 reads

MEV Bots: How Do They Influence The Crypto Market?

by NFT BroAugust 5th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In the case of DEX and lending protocols, MEV is a good thing. But for normal users (I only buy, I only sell), phenomena like sandwiching lead to a total mess.
featured image - MEV Bots: How Do They Influence The Crypto Market?
NFT Bro HackerNoon profile picture


In theory, validators should determine the inclusion of transactions in a block. Still, in practice, this is done by searchers, independent participants who search for potentially profitable transactions and launch their bots into them. Validators still win a little bit because searchers set the gas fee above the average, and the delta goes to validators in exchange for the increased probability of the transaction's inclusion in the nearest block.


But the trick is that many searchers can fight for a single transaction at once (e.g., in the case of DEXs), and the gas fees can really be up to 90% of the MEV.


Since “transaction cost = gas price * amount of gas” (gas price is a highly competitive variable), there are programmable transactions that minimize the required amount of gas. How can the required amount of gas be minimized:


  1. Use an address that starts with zeros because it takes up less space.
  2. Leave some ERC-20 tokens on the contract balance since it costs more gas to initialize a storage slot (the case if the balance is 0) than to update a storage slot (I don't fully understand this thesis).


But gas minimization is something on the smart side. However, frontrunning still exists when bots wander through the mempool, find transactions with a profit, copy the transaction, replace the recipient address, do a local double-check to make sure that the transaction really will be with a profit, and if everything is ok, put the gas fee higher and thus frontrun the initial transaction.


Against this background, flash bots appeared. They allow searchers to confirm mev transactions directly with validators without publishing them in the public mempool. Thus, these bots that just walk around the mempool and look for transactions are deprived of their benefit.

MEV Examples


Here are four common examples of MEVs.

DEX

DEX is the most understandable example (and, of course, the most competitive). It is when you buy at Uniswap cheaper and sell at SushiSwap more expensive within one transaction.

Lending Protocol Liquidations

Lending protocol liquidations (Maker, Aave) is another example. Let's say if I am 100% DAI, I can take 30% MKR and go to vote in MakerDAO (this is just an example). If my MKR/DAI ratio exceeds 30% because of a change in the asset price, someone can liquidate my loan and return the MKR to whoever I borrowed it from (it's like margin calls in trading).


The person who took the loan pays liquidation fees, some of which go to the liquidator. Searchers keep track of which loans are likely to be liquidated soon and guard them.

Sandwich Trading

The next type of MEV is sandwich trading: a searcher looks for large transactions on DEX, e.g., someone wants to exchange 10,000 DAI for UNI, which will increase the price of UNI and decrease the price of DAI. The searcher can roughly calculate the price effect, place a buy order before the swap transaction described above, and place a sell order immediately after the swap transaction described above. But you must understand that this is a more risky story because it is atomic. I mean, it consists of a chain of actions; if one of them is not executed, the others are also not executed (and sandwich attacks are also prone to salmonella attacks).

NFT MEV

There are also MEVs with NFT. They're more subtle. However, one of the precedents was when a searcher bought up CryptoPunks at floor price and kept it a secret (this trick is explained in this tweet). In short, as I understand it, a private (when even the miner does not know what he is mining) block was built, which included transactions to buy all CryptoPunks at once.


But this has been known for a long time, and the market, so to speak, is divided between the searchers (those who know and understand from 2018 were having fun there when there were no words to explain). In this regard, the searchers move to other networks (BNB, for example) where the MEV is the same and the competition is lower.

How Does MEV Influence The Crypto Market?


In general, in the example with DEX and lending protocols, MEV is a good thing.


But for normal users (I only buy, I only sell), phenomena like sandwich attacks lead to total mess (deterioration of user experience)—this is in the case of dApps.


In the case of the network, when frontrunners raise the gas price, the gas price is raised for everyone, and the network is overloaded.


And (perhaps) most importantly, if the MEV greatly exceeds the normal benefit of the validators, the validators themselves may start “messing” with the blocks (rearranging them), leading to blockchain reorganization and consensus instability in general.


The flash bots have moved gas auctions to the off-chain, meaning that when searchers bid for gas, it doesn't directly affect the price of gas.

Risks Of MEV In PoS

Here are the exact risks of MEVs in PoS:


  • Centralization of validators (32 Ethereum to become a validator). Purely from an economic common sense perspective, validators earn less than miners, meaning their incentive to "abuse" MEV is higher. Large staking pools have the resources to invest in MEV extraction - and the more MEV they extract, the more they can invest in extracting even more; that's economies of scale. An independent validator can't afford this, so he is motivated to join the pool and say goodbye to decentralization.
  • Private mempools. Because of sandwich attacks and frontrunners, traders are starting to conduct off-chain transactions directly with validators (i.e., they don't send the transaction to the mempool at all). Darkpools—private mem pools with paid entry—are emerging. The main offer of darkpools is transaction privacy. And again, goodbye decentralization.


If users perceive that the network is susceptible to manipulation by validators extracting MEV, their trust in the system diminishes. This loss of trust decreases user adoption and negatively impacts the overall ecosystem.

Proposer-Builder Separation (PBS)


PBS is a concept in blockchain architecture designed to mitigate the risks and challenges associated with MEV. It aims to separate the roles of proposing and building blocks to enhance the blockchain network's fairness, security, and decentralization.


Block proposer and block attester are joined by block builders, who build a transaction bundle for a block and place a request to include that block in the Beacon Chain. The proposer selects the bandle with the highest fee. The result is still an auction in which block builders bid to have their bandle included in the block.


The bidder publishes the block header + bid. If the bandle wins the auction, the block proposer creates a signed block proposal, validator attestation occurs, and the block is finalized.


Thus, direct MEV extraction goes from the validator's competence to the block builders' competence. The risk that validators will drop everything and start just maximizing MEV extraction is reduced (although formally, when block builders bid for their bundle to be included in the block, validators still get a higher fee than the default one). Also, there is no need for trust in such a setting: neither for the validators to trust that they won't steal their MEV nor for the validators to trust that they will withhold blocks or include invalid transactions since the validators will get paid anyway.


I also recommend you read how the Builders API works (the second method of coping with potential centralization).

RPC Nodes

RPC nodes act as the intermediaries between decentralized applications (dApps) and the blockchain. They facilitate the communication necessary for transactions, fetching data from the blockchain and sending transaction requests to it.

Why Are RPC Nodes So Important For Blockchain Applications?


Blockchain applications, such as cryptocurrency wallets, are not directly connected to the blockchain. They simply convert user actions in the interface into transactions and then send them to the selected RPC node. It processes the transactions and sends them throughout the network, where other nodes verify the transaction and include it in the blockchain. If the selected RPC node does not respond, the application loses connection with the network and stops working.


The developer can launch his or her own RPC node to make the application independent of the state of someone else's node. However, it's expensive. For example, hosting a Solana node alone costs from $1000 per month, and you also need to allocate resources for monitoring and maintenance.


Most dApp developers use public RPC nodes to avoid spending money. These nodes are launched by other companies or projects and can be accessed for free or a subscription. However, they have a drawback: they are usually hosted on centralized services such as Google Cloud, Amazon Web Services, or Hetzner.


Hetzner banned Solana nodes from its platform in early November. The decision resulted in the shutdown of 22% of Solana nodes and the failure of dApps that used RPC nodes on this platform.


The Hetzner situation demonstrated that relying on only one RPC node and on a centralized hosting service is dangerous. To be on the safe side, a decentralized application should have redundant RPCs and a system for monitoring the connection and automatically routing requests.

Do RPC Nodes With MEV Protection Contribute To A Healthier Crypto Market?


Yes, RPC nodes with MEV protection can significantly contribute to solving MEV issues. Here are 3 direct benefits of RPCs.

Fair Transaction Ordering

RPC nodes with MEV protection ensure that transactions are processed in the order they are received. This mitigates the risk of front-running and other forms of MEV exploitation. RPC nodes promote a fairer trading environment by preserving the integrity of transaction sequences.


Example: Decentralized Exchanges (DEXs)


In a DEX, a large trade can drastically affect the market price of a token. I have already discussed this situation above. This not only disadvantages the original trader but also creates artificial price volatility. MEV-protected RPC nodes prevent such manipulations, ensuring the trade occurs as intended and maintaining market stability.

Fewer Transaction Costs

MEV exploits can lead to increased transaction fees as users attempt to outbid each other to avoid being front-run. This bidding war drives up costs, making the network less accessible to average users. MEV-protected RPC nodes help maintain lower transaction fees by preventing these unfair practices.


Example: Gas Fees in Ethereum


When users suspect their transactions might be front-run, they often increase the gas fees to prioritize them. This not only raises costs for individual users but can also lead to network congestion. By using RPC nodes with MEV protection, the incentive to inflate gas fees diminishes, resulting in a more efficient and cost-effective network.

User Trust and Participation

Trust is a cornerstone of any financial market. MEV exploits erode this trust, making users wary of participating in blockchain-based transactions. RPC nodes with MEV protection help rebuild this trust by ensuring fair play, which encourages more users to engage with the crypto ecosystem.


Example: DeFi Platforms


Decentralized Finance (DeFi) platforms rely heavily on user trust. If users believe that their transactions could be unfairly manipulated, they might avoid these platforms altogether. MEV-protected RPC nodes foster a trustworthy environment, encouraging more users to participate in DeFi activities, thus driving growth and innovation in the sector.

dRPC - A Solution For The Crypto Market


dRPC is a provider of Remote Procedure Call (RPC) services specifically designed to protect against MEV exploits. By focusing on securing the transaction process, dRPC ensures that users can interact with blockchain networks without falling victim to manipulative practices such as front-running and back-running.


While many RPC providers offer general services, dRPC’s specialized focus on MEV mitigation sets it apart. This targeted approach ensures that dRPC is at the forefront of addressing one of the most significant challenges in the crypto market.