Front running is the practice of exploiting advance knowledge of a pending transaction to execute your own transaction first, profiting at the expense of the original party. The term originates in traditional finance where brokers with advance knowledge of large client orders would execute their own orders first, then fill the client’s order at the now-moved price.
In crypto, front running takes on a distinctly technical dimension because of how blockchain transactions work. Before a transaction is confirmed in a block, it sits in the mempool: a public queue of pending transactions visible to miners, validators, and sophisticated bots. This visibility creates an opportunity for front running at a structural level that does not exist in traditional financial markets.
Front running is most relevant for DeFi users who interact with decentralised exchanges (DEXs) like Uniswap. Understanding how it works helps you configure your transactions to minimise its impact and choose appropriate slippage tolerance settings.
Traditional financial front running requires a human intermediary (a broker) who has access to client order flow before it is executed. It is explicitly illegal under securities regulations globally. The blockchain version does not require a corrupt human intermediary: it exploits a structural property of how public blockchains process transactions.
When you submit a transaction to a blockchain, it is first broadcast to the network and sits in the mempool. During this waiting period, other network participants can see your transaction, understand what it will do (buy a specific token on a DEX, for example), and submit their own transactions with a higher gas fee to have them processed first. The blockchain orders transactions by gas price: higher gas = earlier confirmation. This structural property is the foundation of blockchain front running.
The sandwich attack is the most common form of front running in DeFi. It is called a “sandwich” because the victim’s transaction is sandwiched between two attacker transactions.
Here is how a sandwich attack unfolds: you submit a transaction to buy Token X on a DEX. A bot detects your pending transaction in the mempool, sees you are about to buy a significant amount, and immediately submits two transactions: one front-run buy order for the same token at a higher gas price (executed before yours), and one back-run sell order at a lower gas price (executed after yours). The sequence becomes: attacker buys Token X (price rises slightly), you buy Token X (at a now higher price, and your purchase moves the price further up), attacker sells Token X (at the elevated price, profiting from the artificial price increase). You pay more for your tokens than you would have without the attack, and the attacker profits the difference.
The profit per attack is proportional to the size of the victim’s transaction. Small transactions produce too little profit to cover gas costs for the attacker. Very large transactions are the most targeted.
The Capital Nexus newsletter covers DeFi security, trading strategies, and market mechanics for crypto investors each week: Capital Nexus Newsletter.
Front running is one component of MEV (Maximal Extractable Value), which is the broader category of value that can be extracted by controlling the ordering of transactions within a block. MEV includes not just front running but also back running (executing after a large transaction), sandwich attacks, arbitrage between DEX pools, and liquidation of undercollateralised positions in lending protocols.
MEV has become a significant and growing source of value extraction in Ethereum and other programmable blockchains. Specialised MEV searchers run bots that continuously scan the mempool and simulate pending transactions to identify profitable sequencing opportunities. The sophistication and competitiveness of MEV extraction has increased dramatically as the practice has professionalised.
Not all DeFi users are equally exposed to front running risk.
Large DEX traders are the primary targets. Sandwich attacks are not economically viable against very small trades because the gas cost of the two attacker transactions exceeds the potential profit from a tiny victim transaction. A $100 trade is unlikely to attract sandwich attacks on a high-gas network like Ethereum. A $50,000 trade on the same network is a more attractive target.
Users on high-liquidity pairs are less affected. On extremely liquid trading pairs with very deep liquidity pools, the price impact of any individual transaction is small, which limits both the profit opportunity for attackers and the damage to victims. Front running is most profitable and most impactful on low-liquidity tokens where even moderate-sized trades move price significantly.
Users with high slippage tolerance are more vulnerable. If you set your slippage tolerance to 5% or higher on a DEX trade, you are explicitly accepting execution up to 5% worse than quoted. This creates a larger profit window for sandwich attacks. Lower slippage tolerance limits the attacker’s profit window but also increases the risk of your own transaction reverting (failing) if price moves before execution.
Several practical steps reduce, though cannot eliminate, front running exposure in DeFi.
Some services allow you to submit transactions privately, bypassing the public mempool, so bots cannot detect your transaction before it is confirmed. Flashbots Protect and similar services provide this for Ethereum transactions. Some DEXs implement mechanisms specifically designed to reduce sandwich attack profitability.
Keep your slippage tolerance as low as is practical for the token you are trading. A 0.5% slippage tolerance on a highly liquid pair significantly limits the attack window. Accept slightly higher revert risk in exchange for reduced front-running exposure.
Splitting a very large swap into multiple smaller transactions over time reduces the profitability of any single sandwich attack, as each smaller transaction presents a smaller profit opportunity. This is more effective for long-term accumulation than for immediate execution needs.
MEV bot activity varies with network conditions and gas prices. During periods of low network activity and gas prices, the economics of sandwich attacks are less favourable for attackers. Using gas tracking tools to identify low-congestion windows reduces both gas costs and front-running exposure.
Shepley Capital’s Black Emerald membership provides DeFi research and trading frameworks for investors navigating on-chain markets: View Membership Options.