Understanding the popular DeFi project Curve: Why is it important? Why is it being "attacked"?

share
Understanding the popular DeFi project Curve: Why is it important? Why is it being "attacked"?

Deep Dive into Uniswap's "Special Version" Curve.

By: Pan Zhixiong, Director of ChainNews Research

A new DeFi project, Curve.fi, is currently the hottest star in the decentralized finance arena. This seemingly "simple" and even somewhat "rudimentary" new project addresses just one need: the exchange of stablecoins.

Advertisement - Please scroll down for more content

You read that right.

The frequent exchange of stablecoins is a pressing need for many industry professionals because USDT is more convenient for deposits and withdrawals, while DAI and USDC are more compliant. However, considering the high fees and poor liquidity, the conversion costs are not low. Curve.fi aims to address this pain point. This startup has developed an Ethereum-based automated trading protocol that focuses on solving this problem while leveraging the composability of open finance to incentivize contributors to the platform.

In simple terms, Curve is a decentralized exchange protocol that utilizes a special algorithm, combining elements of "a specific version of Uniswap" and "Compound" to focus solely on the exchange of stablecoins.

Curve went live on the Ethereum mainnet in January this year but is still in the early stages of development. At the time of drafting this article, the audit results of its contracts have not been made public. Its interface is also very simple (or one might say "unique"), which may lead one to speculate that the developers intentionally designed it to mimic the interface of 80s computers to reflect the current development stage. Of course, this may also serve to keep users who do not understand the product's risks at bay.

Understanding the Popular DeFi Project Curve: Why is it important? Why is it being 'attacked'?Curve.fi's retro interface

However, Curve's development has surpassed the expectations of many. In just over a month since its launch, Curve has been integrated by several decentralized aggregation exchanges on Ethereum. Taking the example of 1inch, an exchange that helps users choose the most optimal route (lowest slippage), in the week of February 17th to 23rd, Curve ranked first in 1inch's weekly trading volume, accounting for 60%, which is three times that of Uniswap and six times that of Kyber. Although there has been a slight decline in recent data, the percentage remains high. This somewhat indicates the urgent need for stablecoin exchanges among users.

Users prefer to exchange stablecoins using Curve because the transaction costs and slippage are extremely low, which are the most critical factors for stablecoin traders. Curve's automated market-making algorithm is tailored for stablecoin trading scenarios and is more focused than Uniswap's generic algorithm, resulting in lower transaction slippage through this market-making algorithm. Additionally, Curve's transaction fee is only 0.04%, whereas the transaction fee for the DAI/USDC pair on Coinbase is 12.5 times that of Curve.

On the other hand, users injecting funds into Curve can earn a very high annualized yield. To increase the protocol's liquidity to meet larger-scale trading demands, Curve allocates all fee earnings to users providing liquidity and generates additional returns through third-party protocol aggregation, giving users the opportunity to achieve an annualized return of about 20%—in comparison, the annualized return on DAI on Compound is currently around 8%.

However, last weekend, an incident of "user loss" occurred on Curve, further propelling this new product into the controversial spotlight of the DeFi community. Initially, everyone thought that this user's $140,000 loss was due to liquidity issues on Curve. However, based on the analysis of the user's transaction behavior, it is speculated that the user may have intended to "attack" the protocol and steal funds. This process is quite complex, and we will analyze it in detail later.

Regardless, Curve's product is indeed still in its early stages, and the slippage protection feature in its product logic is not yet perfect. In the following sections, we will delve into this further.

Table of Contents

Customized Stablecoin "Uniswap"

Let's start by explaining the operation principle of Curve.

Overall, Curve is more like a "Uniswap" customized for stablecoin trading.

Uniswap is the infrastructure for Ethereum's decentralized trading protocol, known for its simple product logic and high decentralization as it lacks administrator special privileges (admin key), making it considered a protocol with a high level of decentralization by the community. Uniswap can be accurately defined as an "Automated Market Maker" or "Liquidity Pool," also known as "AMM" (Automated Market Maker) or "LP" (Liquidity Pool). Other decentralized trading protocols, such as Kyber and 0x API, also allocate some transactions to Uniswap.

In essence, Uniswap has two functions: liquidity injection and liquidity withdrawal, corresponding to two roles: liquidity providers and traders. Liquidity providers injecting funds into the pool can earn a share of the transaction fees in the pool, while traders withdrawing liquidity need to exchange tokens between each other (trade) and pay a portion of the transaction fees.

For example, a user with ETH and DAI in their wallet can deposit ETH and DAI into the Uniswap pool as a liquidity provider according to the latest exchange ratio. Suppose the user deposits 1 ETH and 200 DAI according to the new exchange ratio. When a trader wants to exchange DAI for ETH, they can enter this pool for the exchange. Uniswap's "market-making algorithm" will calculate how much ETH the trader can buy. Similar to centralized exchanges, Uniswap also generates "slippage" during transactions. The larger the user's trading funds, the greater the slippage, meaning higher transaction costs. After the transaction is completed, the transaction fees paid by the trader will be distributed according to the proportion of funds contributed by all liquidity providers in the pool.

Uniswap adopts a market-making algorithm called the "Constant Product Market Maker Model," which is very simple in logic and can meet the requirements in most general scenarios.

However, exchanging stablecoins and other types of tokens is different and requires special treatment. The price of USD stablecoins is pegged to 1 USD, although there may be slight fluctuations due to market volatility. In the long term, all USD stablecoins are considered equivalent, whether it is DAI generated through collateral, USDC, PAX, TUSD issued with legal and physical asset endorsements, or USDT claiming to be backed by physical assets. It is necessary to consider that "USD stablecoins are often equivalent" and allow for "price differences between stablecoins." When these two factors are combined, a mechanism completely different from Uniswap is needed.

The "StableSwap" mechanism invented by the Curve team is a market-making algorithm designed specifically for the exchange of stablecoins. If their algorithm is plotted as a curve, it falls between the Uniswap curve and the constant price. As shown in the figure below:

Uniswap Curve, Constant Price, and StableSwap Curve

Readers need not rush to understand the curve or formulas in the figure above, as all details of StableSwap are not fully disclosed at the moment. However, we can provide some known information to help readers understand the principles of this algorithm.

Let's make two assumptions:

  • Assumption 1: If the price of all stablecoins remains constant at 1 USD, stablecoin X and stablecoin Y are equivalent and can be exchanged without loss. In the figure above, if in the initial state, stablecoin X and stablecoin Y each have 5 units, the exchange ratio established by this assumption is X+Y=10, which is the dashed line in the figure, also known as the "constant price" market maker. For traders who need to exchange, 3 units of X can be exchanged for 3 units of Y, but this pool has a capacity limit, and X<=10 and Y<=10 are required;
  • Assumption 2: If stablecoins adopt the constant product market maker model of Uniswap, which is the outermost dashed curve in the figure, and if stablecoin X and stablecoin Y each have 5 units in the initial state, the curve is XY=25, allowing trading more than 5 units of tokens, but with price fluctuations, the distance from the "constant price" market maker is very far, meaning price fluctuations are significant;

The StableSwap mechanism designed by Curve falls between the two assumptions, considering that "stablecoins are often equivalent" (assumption 1) and allowing "price differences between stablecoins" (assumption 2). In other words, this is a market-making algorithm closer to the "constant price" exchange than the Uniswap algorithm.

The biggest advantage of StableSwap is lower slippage, meaning lower transaction costs. The whitepaper of StableSwap draws the function curve of the algorithm and the constant product algorithm of Uniswap, showing that StableSwap can maintain at 1 USD, while Uniswap's algorithm quickly lowers the price as the amount sold increases.

StableSwap Curve and Uniswap Curve

In our tests, Curve's slippage is not inferior to centralized exchanges. Taking the DAI/USDC trading pair on Coinbase as an example, pushing orders at the $100,000 level into the trading system and looking at the snapshot at the time, Curve is slightly better than Coinbase, and Coinbase's fees are $460 more than Curve.

Curve vs. Coinbase Order Fees Comparison

Upgrade Incentives: Utilizing DeFi Composability to Increase Returns

After optimizing the market-making algorithm, another issue is how to increase the size of the entire pool to provide larger-scale trading and lower transaction costs.

Uniswap also faces the same issue of how to incentivize users to contribute their funds and become "liquidity providers" to share profits. Among these, the transaction fee rate is a fundamental parameter. If it is too high, traders may choose platforms with lower transaction fees, and if it is too low, liquidity providers may receive little profit.

Uniswap's fee rate is 0.3%, while Curve's is 0.04%. Currently, Curve's transaction fee rate is more user-friendly for traders but not as friendly for liquidity providers. However, the fee income still depends on the total trading volume. Therefore, if there is a high demand for stablecoins and more users are attracted to trade at discounted rates, the overall income scale will not be inferior to Uniswap.

In addition to the fee rate, Curve also utilizes DeFi's composability to further increase profits for liquidity providers.

Consider the following two scenarios:

  • For example, in Uniswap, if a user wants to inject liquidity for ETH/DAI, they deposit 1 ETH and 200 DAI, and the user can receive a share of all related transaction fee income.
  • For example, in Compound, if a user wants to deposit DAI into a lending platform (such as Compound) to earn additional income, they can receive cDAI, a wrapped token backed by collateral assets that automatically generates income. This token can earn a share of the annual income paid by the lending platform's collateral providers.

Curve combines these two scenarios to maximize user profits. The specific process is as follows:

  1. The user converts DAI to Compound's cDAI, earning Compound's income, currently around 8% annually;
  2. The user deposits cDAI into Curve, earning Curve's transaction fee income, which is adjusted based on trading volume.

More Room for Improvement! Further Enhancing Returns

When Curve combines with another new DeFi protocol, iearn, returns can be further increased, reaching up to an annualized 30%. iearn is a decentralized yield aggregator that finds the highest-yielding protocols in current lending platforms and automatically balances to higher-yielding lending platforms as market conditions change.

In essence, the effect of Curve combined with iearn is similar to the combination of Compound:

  1. The user converts DAI to iearn's yDAI, earning the highest-yielding platform selected by the iearn protocol, with annualized returns not lower than Compound;
  2. The user deposits yDAI into Curve, earning Curve's transaction fee income, which is adjusted based on trading volume.

iearn also provides a feature called Zap, which combines the two operations into one process, making it easier for users. Without this feature, conducting two separate operations would be too cumbersome for ordinary users.

iearn Founder Andre Cronje

It is worth noting that the founder of the iearn project is Andre Cronje. In the world of cryptocurrencies, Andre Cronje is a familiar figure. He was the Chief Code Reviewer of the blockchain media Crypto Briefing and conducted code quality reviews for many popular projects during the ICO boom, known for his sharp eye and critical writing. Many well-known projects' technical capabilities and code quality were harshly criticized by him.

Project Progress: 4 Independent Liquidity Pools Launched in Over a Month

According to the whitepaper and information on GitHub, the current maintainer of Curve is Michael Egorov, the Chief Technical Officer of the privacy project NuCypher.

Michael Egorov

However, based on information from Twitter, the founder of the iearn project, Andre Cronje, may also be one of the core figures of Curve, as he frequently participates in product planning and external communication at Curve.

In the past month, Curve has successively launched four independent liquidity pools, also known as V1, V2, V3, and V4, which are:

Basic Information of Curve's Four Independent Liquidity Pools V1, V2, V3, and V4
  • Curve V1 (Compound): Launched on January 20, supporting USDC and DAI (settled by cUSDC and cDAI), in addition to transaction fees, it can also accumulate Compound income;
  • Curve V2 (USDT): Launched on February 10, supporting DAI, USDT, USDC. The advantage is the addition of USDT trading, but there is no additional income, only relying on transaction fee income;
  • Curve V3 (Y): Launched on February 13, supporting DAI, USDC, USDT, TUSD (settled by iearn's y tokens), in addition to transaction fees, it can also accumulate iearn income;
  • Curve V4 (BUSD): Launched on February 27, replacing TUSD in V3 with Binance's BUSD, supporting DAI, USDC, USDT, BUSD (settled by iearn's y tokens), in addition to transaction fees, it can also accumulate iearn income.

Based on the current funds and trading volume of the four pools, V3 and V4 versions are more popular. However, from the trend, V4 may catch up with or even surpass V3. This indicates that liquidity providers prefer iearn version Curve pools with additional income, even if they need to take on more risks.

The Project Is Still in Its Early Stages, Technical Risks Are Evident

Five days after Curve V1 went live, independent security researcher Sam Sun reported a vulnerability to Curve. Sun pointed out that if exploited, the vulnerability would lead to asset losses in the smart contract.

Fortunately, the vulnerability has not been exploited. Michael Egorov discovered that the vulnerability was hidden in Curve's algorithm, and the whitepaper had not yet disclosed these details. He subsequently deployed a brand new smart contract and made frontend UI adjustments, transferring all funds to the new smart contract.

The warning on Curve's website clearly informs users of the risks. Not only are the details of the code audit not fully disclosed, but Curve is currently only in the beta stage, and the official recommendation is for users not to invest assets they cannot afford to lose, especially for liquidity providers. The website states that for traders using the platform, the risks are relatively low.

A week ago, Curve announced that the details of the security audit conducted by Trail of Bits would soon be made public. Overall, there are no issues with the USDT and Y pools, but the Compound pool needs to be redeployed to fix the problems already addressed in the other two pools because it was the earliest contract.

However, risks still exist, not only at the technical level.

We must revisit and understand the various risks lurking in the DeFi world. For example, in the recent flash loan arbitrage attack on bZx, the attacker clearly understood the weak points in the entire DeFi ecosystem and exploited them skillfully, utilizing liquidity flaws, not solely due to technical vulnerabilities. Therefore, the issues Curve faces are not just about code audits but also other systemic risks.

For example, if the iearn protocol is attacked by arbitrageurs, the V3 and V4 pools will also incur losses. If a market crash causes losses in the Compound liquidation system, it will affect the V1 pool. Risks also include problems with the price source or oracle in the entire system, among others. Since Curve is built on many projects, risks accumulate from the bottom up.

Truly "Attacked"

Shortly after Curve V4 went live but before it was publicly announced, the Curve platform encountered a special "incident," causing quite a stir in the overseas DeFi community. Although this may not be considered a hacking incident, it exposed issues in product design and communication.

On February 28, a user conducted a huge exchange in the context of insufficient liquidity in Curve V4. Although the team discovered the incident and took remedial action immediately, the user still lost $140,000. Later, after detailed analysis of the transaction records, it was found that the story was not as simple as initially thought.

Afterward, Andre Cronje wrote two articles detailing the incident, and the following analysis is based on his second article.

The incident involved three addresses, referred to as:

  • The loser's address A
    0x44e59f7c598644a68975ef41fed052362c4c8ed3
  • The gainer's address B
    0x8183866223445441b6fb9206b9f0b583410977e6
  • The good friend's address C
    0x431e81e5dfb5a24541b5ff8762bdef3f32f96354

The sequence of events was as follows:

  1. When Curve V4 (BUSD) was not yet publicly released, A attempted to move funds from V3 to V4, conducting multiple stablecoin exchanges. At that time, the V4 pool only had 42,800 USDC (a lower proportion compared to other stablecoins), but A exchanged far more funds than this amount into USDC, resulting in significant losses. The largest loss and the final transaction were when A exchanged $446,000 for 25,000 USDC. In total, A incurred a loss of $560,000.
  2. A's actions caused an imbalance in all four stablecoins in