Site iconSite icon ForkLog

Cows in the Dark Forest: A Review of the CowSwap Decentralized Exchange

Cows in the Dark Forest: A Review of the CowSwap Decentralized Exchange

In May, trading volume on Ethereum-based decentralized exchanges (DEX) surpassed the $115 billion mark. Almost 60% of this volume was on Uniswap.

The growth of the DeFi sector has been accompanied by hacker attacks and fraudulent schemes. But a relatively new risk for users of decentralized exchanges has become Miner Extractable Value (MEV).

In late April, the project Gnosis unveiled a protocol for decentralized exchanges with MEV protection and a Coincidence of Wants (CoWs) order-matching mechanism. We discuss Gnosis Protocol v2 (GPv2) and test the DEX CowSwap.

What MEV Is

In 2019, cryptocurrency and smart-contracts researcher Phil Daian published the paper “Flash Boys 2.0: Front-running, Transaction Reordering, and Instability of Consensus on Decentralized Exchanges.” In it, Daian introduced Miner Extractable Value (MEV).

MEV is the profit that miners can earn by selectively including or reordering transactions within blocks.

Imagine: on Uniswap there is an arbitrage opportunity with potential profit of $10,000. A trading bot spots it and submits an Ethereum mempool transaction. There are two scenarios that may follow:

More about MEV can be read in Charles Noyes’s “MEV and I”, as well as Dan Robinson and Georgios Konstantopoulos’s “Ethereum Is a Dark Forest” and “Escape from the Dark Forest”.

What CowSwap Is and the Gnosis Protocol

CowSwap — a decentralized exchange with DEX-aggregator features based on Gnosis Protocol v2 (GPv2).

The Gnosis team released the first version of the protocol in early 2020. Over the next six months, developers studied the protocol’s weaknesses. They found that gas costs prevented market makers from offering tight spreads. Fragmented liquidity also affected asset prices. In April 2021 the project introduced the second version of the protocol, which addresses this problem.

By mid-year, Gnosis and the developers of the AMM protocol Balancer planned to deploy Balancer-Gnosis-Protocol (BGP) on Ethereum. It would combine Balancer V2’s gas-cost-reduction algorithm with the price-determination mechanism of Gnosis Protocol V2 with MEV protection. This integration would offer CowSwap users better prices.

As of publication, CowSwap was in alpha testing.

How GPv2 Works and How It Protects Against MEV

Gnosis Protocol v2 employs technologies such as:

CowSwap submits users’ orders to GPv2. The protocol bundles orders into batches (BA) and passes them to the solving participants (solvers). The solvers search for the most advantageous market price and are rewarded in Gnosis tokens (GNO).

Any user can become a solver. To do so, one must:

When the best prices are found, the protocol executes the orders in the batch. First it looks for CoWs trades: when there is a match of wants, the smaller order is executed against the larger one. It then searches for liquidity on other DEXs to complete the remaining orders.

After the Balancer-Gnosis Protocol integration, Balancer will become one of CowSwap’s main liquidity sources.

Testing the Exchange: Exploring the Interface and Executing a Swap

We tested CowSwap by swapping Wrapped Ether (WETH) for the Gnosis token (GNO). To do so, we visited CowSwap.exchange and connected an Ethereum wallet.

As of publication, CowSwap supports MetaMask and WalletConnect.

We selected tokens for swapping. By default CowSwap shows Gemini’s tokens. You can connect tokens from other exchanges — click the Manage button. You can also input a token address manually.

Enter the token ticker in the quick search field.

We specified the amount of tokens and configured the transaction. Selected:

CowSwap offers an Expert mode. In this mode the exchange does not require confirmation before submitting transactions and allows trades with high slippage.

The exchange does not recommend beginners enable Expert mode.

When attempting to sell 0.1 ETH, the exchange offered to wrap the cryptocurrency into an ERC20 token called WETH. We bought the token and paid a transaction fee of 0.0011591 ETH.

CowSwap will wrap Ether when needed during a swap.

We then checked the transaction settings and authorised CowSwap to spend tokens from the wallet. We clicked Approve WETH and confirmed the operation in MetaMask.

CowSwap will automatically calculate the swap price.

We moved on to the swap itself: clicked Swap and confirmed the transaction in MetaMask.

CowSwap will highlight the Swap button after confirming the transaction.

CowSwap charges a swap fee equal to the value of the trade. In our case it amounted to 0.0540555 GNO.

Transaction status can be checked in the Gnosis Protocol Explorer.

Each transaction is accompanied by the sound of cows’ mooing. Do not panic.

Conclusions

According to the Flashbots team, since January 2020 Ethereum arbitrage bots have earned almost $750 million from MEV.

Behind CowSwap’s playful interface lie the sophisticated technical solutions of Gnosis Protocol v2: the exchange protects users from MEV, optimises gas costs, and enables trades at prices better than the market through a combination of CoWs and Gas-Free Transactions with DEX-aggregator features.

Follow ForkLog news on Twitter!

Exit mobile version