Uniswap v4's new practice of "hook" - How does the "truncated oracle" change DeFi?

CN
1 year ago

Truncated Oracle Hook can reduce the impact of large trades on prices and make it more resistant to manipulation, thus making it safer for use in DeFi scenarios.

Original Title: "Uniswap v4 Truncated Oracle Hook"

Translation: Frank, Foresight News

The Uniswap protocol is an important cryptographic infrastructure for millions of traders, supporting over $1.6 trillion in trading volume by providing deep liquidity, and Uniswap v4 is the latest evolution of the protocol, allowing developers to build custom AMM features on top of Uniswap using hooks.

We have previously written an article about the time-weighted average market maker hook, and today we will focus on the "truncated oracle."

As is well known, price oracles (such as those in Uniswap v3 pools) can transmit price information about liquidity pools to other DeFi protocols, while the optional v4 hook-deployed truncated price oracle can reduce the impact of large trades on prices and make it more resistant to manipulation, thus making it safer for use in DeFi scenarios.

Role of Price Oracles

Price oracles are tools used to view price information for specific assets. These on-chain oracles are trusted price sources reflecting on-chain data. Uniswap v3 price oracles allow smart contracts to integrate and use on-chain pricing data to create more composable applications across DeFi.

While the Uniswap v3 price oracles were built considering Ethereum's proof-of-work (PoW) mechanism, some key assumptions of this oracle have changed with Ethereum's transition to proof-of-stake (PoS) consensus algorithm, leading to a decrease in its security.

Although manipulating high-liquidity pools on Uniswap v3 is too costly, the importance of price oracles also makes them a target for malicious actors, who have sufficient economic motivation to manipulate price oracles.

Therefore, we need to modify the oracles to make them more resilient, and the truncated price oracle uses a different formula to calculate prices and can provide more reliable and less manipulable price feeds.

What is the Hook of Truncated Oracle?

The truncated oracle is an on-chain price oracle that uses a geometric mean formula to record the prices of assets in Uniswap liquidity pools, and then truncates the price feed of the oracle—meaning that the recorded price within a single block can only move up or down to a maximum value.

This truncation helps eliminate the long-term impact of large trades on prices—whether these large trades are legitimate or malicious—because if a malicious actor attempts to manipulate the price, they must continue to manipulate it over multiple blocks, making the cost of manipulating the truncated oracle very high.

How Does the Truncated Oracle Hook Work?

The smart contract of the hook stores a copy of the price of the corresponding liquidity pool, where in Uniswap v3 and v4, these prices are represented as individual points (Ticks).

Before executing a trade or LP adjustment, the hook compares the current price change of the liquidity pool with the price change stored in its contract. If the difference between these two numbers is less than a certain numerical unit (based on our research, we use 9,116), the hook will update to this new price point.

However, if the current price change of the liquidity pool exceeds 9116 numerical units, the oracle will limit its price feed to +- 9116, thereby limiting the movement of the liquidity pool's price points within a block.

After the hook update, the trade or LP adjustment will be executed, and this process will continue until the end of the corresponding block, then repeat for the next block that triggers the smart contract of the hook.

By truncating the degree of extreme price (point) fluctuations that can be recorded, this oracle can ignore outliers and eliminate the impact of large trades on prices. If the price continues to fluctuate significantly, the oracle will quickly adapt to the price points of the liquidity pool.

Truncated Oracle is Safer

Let's take the example of the lending market to better understand the truncated oracle. DeFi lending markets allow users to deposit assets as collateral in order to borrow other assets, with the ability to borrow a portion of the collateral's value.

For example, if the collateral ratio in the lending market is 1.5, then Alice needs to provide at least $1,500 worth of collateral to borrow 1,000 USDC, meaning if ETH is $1,000, Alice needs to deposit at least 1.5 ETH.

During the lending process, Alice needs to maintain a ratio of at least 1.5, which means if the price of her 1.5 ETH drops, anyone can repay her bad debt and obtain the collateral of 1.5 ETH.

The lending market uses a price oracle to compare the prices of ETH and USDC. Although currently manipulating the ETH/USDC liquidity pool on Uniswap v3 is economically impractical, malicious actor Bob can influence smaller-scale DEX by executing large trades and suppressing the price of ETH.

This allows Bob to manipulate the lending market, forcing Alice's position to be liquidated, and then Bob can repay Alice's loan for less than $1,500 and take her 1.5 ETH.

This type of manipulation is one of the most common ways in which DeFi protocols are manipulated by price oracles, and the lending protocol is just one example, with other DeFi primitives (such as perpetual contracts) also relying on on-chain price oracles.

If the DeFi lending market where Alice is located uses a truncated price oracle, then Bob will have to manipulate the market for a sustained period of time. For example, in this scenario, Bob must wait for 15 blocks to achieve the price fluctuation he wants from the oracle, and then he can attempt to liquidate Alice's position.

However, during these fifteen minutes, arbitrage bots may eat up Bob's corresponding trades, leaving him with nothing. For Bob, this cost is too high.

Currently, Uniswap v4 and the truncated oracle hook are still in development, and the final specifications may change.

免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。

HTX:注册并领取8400元新人礼
Ad
Share To
APP

X

Telegram

Facebook

Reddit

CopyLink