Halborn Logo

// Blog

Blockchain Explained

How Does MEV Searching and Block Building Work?


profile

Rob Behnke

December 5th, 2023


Blockchain systems are designed to maintain a decentralized, immutable digital ledger. Transactions recorded on this ledger can be used to achieve various purposes such as transferring value or interacting with smart contracts.

Transactions are added to the digital ledger as part of a block. MEV searching and block building are crucial parts of this process. Maximal Extractable Value (MEV) refers to the potential profits that MEV searchers and block builders can derive from this process, and there are several potential sources of profit (some more ethical than others).

How Transactions Are Ordered on the Blockchain

The blockchain is operated by a network of independent nodes, which need to agree on the order in which transactions are included in the ledger. Disagreements could cause issues if different orderings of transactions would create different final results. Adding transactions to the blockchain as part of blocks makes it easier to maintain a global ordering than if each transaction were added individually.

Transactions can be timestamped, but they aren’t added to the blockchain on a first-come-first-served basis. When a transaction is submitted to the blockchain, each node stores a copy on a public mempool until it is included in a block. Block builders draw from these mempools to select the transactions to be included in the next block in the chain.

This selection process has little to do with the order in which these transactions enter these mempools. Instead, each transaction will have an associated fee paid by the transaction creator. These fees are used to determine the order in which transactions are added to blocks and the distributed ledger.

MEV Searching and Block Building

Transaction fees are paid to the miners and forgers that create blocks and operate the blockchain network. While minimum transaction fees exist, users can pay extra for their transactions to be processed more quickly. As a result, the fees paid to the block builder depend on the set of transactions that they include in a block.

This potential for additional profits is called Maximal Extractable Value (MEV). The role of a MEV searcher is to search through the transactions waiting in mempools to be added to a block and build a set of transactions to be included in the next block.

Once a block candidate has been developed, it is sent on to the block builder to construct. For example, in a Proof of Stake system, this would be the party tasked with creating the next block, who would digitally sign it with their private key. Once the block has been built and validated, it can be submitted to the rest of the blockchain network.

MEV Opportunities

In theory, a MEV searcher and block builder would derive their profits from selecting the most high-value pending transactions in mempools. In practice, there are multiple opportunities for MEV searchers to derive value in more underhanded ways, including:

  • Chain Reorganization: Many blockchains lack instant transaction finality, meaning that previously confirmed blocks and transactions may be replaced with other versions during a reorganization. A block builder seeing a high-value transaction included in a previous block may ignore that block and create a version of their block that contains the valuable transaction.


  • Frontrunning: In a frontrunning attack, someone who observes a transaction in a public mempool creates their own transaction to be executed before it. For example, an attacker may be exploiting a vulnerable smart contract, and the frontrunner attempts to exploit it first. While frontrunning is usually performed by paying a higher transaction fee than the original transaction, a MEV searcher or block builder can frontrun more cheaply since they decide the ordering of transactions within a block.


  • Sandwich Attack: If a large trade is performed on a decentralized exchange (DEX), someone who performs a buy before and a sell after it can make a profit. MEV searchers and block builders who identify a pending large trade in the mempool could create their own transactions to sandwich it and guarantee that they’re performed in that order (since they control the organization of transactions within a block).


  • Arbitrage: Arbitrage opportunities exist when a digital asset has different prices on different exchanges, typically due to the relative quantities of the assets on those exchanges. A transaction buying the asset from the lower-price exchange and selling it to the higher-priced one can make a significant profit. A MEV searcher who identifies such a transaction in the mempool could ignore it and build their own transaction to take advantage of the arbitrage opportunity.


  • Liquidation Sniping: In Decentralized Finance (DeFi), undercollateralized loans can be liquidated by third parties. Similar to arbitrage, a MEV searcher who notices a pending liquidation transaction can create their own transaction to take advantage of the liquidation opportunity instead.


  • Hidden Transactions: In theory, transactions submitted to a blockchain node should be distributed to the rest of the network to be included in public mempools. However, a node receiving a high-value transaction may keep it secret in order to ensure that they can include the transaction in a block that they create and receive the associated fees.

Conclusion

Block building is an essential process within the blockchain that manages how transactions are added to the blockchain’s digital ledger. Transactions are submitted to public mempools, and MEV searchers look through these mempools to select transactions to be included in the next block.

MEV searchers and block builders are incentivized by the potential opportunities for profit in the block building process. In addition to the potential profits gleaned from selecting high-fee transactions to include in blocks, MEV searchers and block builders can make additional profits via various methods.

This design offers the potential for significant profits and can also create centralization in the business of building blocks to maximize MEV. As a result, the Transaction Supply Network (TSN) — which breaks down these roles into smaller pieces — has been proposed to decentralize power and more evenly distribute potential profits.