How mistX uses Flashbots bundles to provide frontrunning protection

6.1.2021 | Hasu

After covering CowSwap on Uncommon Core a few days ago, today I looked at another “gasless exchange”mistX.

When making a gasless trade, the trader does not pay a transaction fee to the miner. In CowSwap, a relayer pays the Ethereum gas fee on behalf of the trader and recoups it from the trade execution. MistX uses a different approach by relying on Flashbots bundles.

In this post, we will unpack a typical mistX transaction to learn more about how their exchange works.

Before we start, what is this transaction supposed to do? 

The intent of the trader can be seen in the decoded input data (1): They wanted to swap 82.9 MIST for at least 9,234 USDC. In practice, they received 9,327 USDC (2).

mistX’s main innovation is to publish transactions exclusively as a bundle in Flashbot’s private mempool instead of in Ethereum’s public mempool, where it would be exposed to hungry sandwich attackers. Etherscan tags transactions that their node did not see on the public p2p layer before they were included in a block as “private” (3).

A Flashbots bundle must be 

  • executed atomically – meaning either entirely or not at all
  • mined at the top of a block (possibly with other non-competing bundles) 

We can see that this was indeed the case, as the transaction has position 1 in the block (4). This property ensures that Flashbots miners can’t frontrun the trade, even if a sandwich attack would be profitable. The goal is that users can safely set a non-zero slippage tolerance to ensure timely inclusion even in a volatile market.

In practice, traders are still trusting Flashbots miners not to sandwich a bundle. However, such an abuse would be easily detectable, and Flashbots can cut them off from future flow. Eventually, Flashbots hopes to remove any need for trust by making miners blind to the transactions they include until they are already on-chain.

The second innovation afforded by Flashbots bundles is gasless transactions

A mistX transaction does not pay a native transaction fee to miners (5). Instead the trader pays the miner via a smart contract call made in one of the transactions from the Flashbots bundle. This payment is conditional on the trade executing as well, and so if the trade was to revert – typically because the user’s slippage tolerance was broken – then the miner has no incentive to include it.

This approach differs from CowSwap’s in that CowSwap takes the execution risk from the trader, whereas in mistX the transaction is actually risk-free.

As a result, traders no longer have to worry about failed transactions, and there is less wasted blockspace as well.

However, while the transaction is gasless, it is all but free for the trader. They pay in one of two ways:

  • With worse execution, as mistX removes some ETH from their input or output to pay the miner; or
  • by taking ETH from the user’s wallet. This step should be unnecessary in the future, as the exchange can shave off ETH after the first hop, or accept USD stablecoins as an alternative.

In the screenshot, we can see that the transaction paid 0.0099 ETH to Sparkpool, the including miner, and 0.0005 to the mistX fee wallet (6). This comes down to another 0.27%, or $25.

The way to calculate the cost of a mistX transaction is actually the exact same as when using the public mempool. It’s gas used * gas price = final fee in ETH.

First, since Flashbots bundles are bound to the first slots in each block, they compete with other important transactions like arbitrage, liquidations, and sandwich attacks. As a result, they incur a large opportunity cost.

This opportunity cost will hopefully go down over time, as Flashbots miners start including more bundles per block, and exchanges like mistX start batching multiple trades in the same bundle.

Second, mistX trades – and gasless transactions in general – use more gas than regular DEX trades. Instead of the 205k gas used here (7), executing the same trade on Uniswap would have cost around 160-180k gas. The difference is the two extra transactions made by mistX: one to the miner, and one to their own fee wallet.

Bottom line, mistX combines two nice innovations: frontrunning protection via Flashbots bundles, and gasless transactions. Right now, they route all trades to Uniswap v2, so for many trades it is still better to use a regular DEX aggregator (or meta-aggregator like CowSwap) to minimize price impact.

Nonetheless, using Flashbots bundles in this way represents an interesting proof-of-concept for the entire Defi economy.

Acknowledgements: Thanks to Dire of mistX and Robert Miller of Flashbots for patiently answering all my questions, and Georgios Konstantopoulos for review.

Written by:

Disclaimer: This post is for general information purposes only. It does not constitute investment advice or a recommendation or solicitation to buy or sell any investment and should not be used in the evaluation of the merits of making any investment decision. It should not be relied upon for accounting, legal or tax advice or investment recommendations. This post reflects the current opinions of the authors and is not made on behalf of Paradigm or its affiliates and does not necessarily reflect the opinions of Paradigm, its affiliates or individuals associated with Paradigm. The opinions reflected herein are subject 
to change without being updated.