Risk Warning: Beware of illegal fundraising in the name of 'virtual currency' and 'blockchain'. — Five departments including the Banking and Insurance Regulatory Commission
Information
Discover
Search
Login
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt
BTC
ETH
HTX
SOL
BNB
View Market
Detailed explanation of Uniswap v4 Truncated Oracle: concept, operating mechanism and function
Foresight News
特邀专栏作者
2023-09-21 03:20
This article is about 1679 words, reading the full article takes about 3 minutes
The truncated price oracle can reduce the impact of large transactions on prices, making the oracle more resistant to manipulation, making it safer to use in DeFi scenarios.

Original title: Uniswap v4 Truncated Oracle Hook

Original compilation: Frank, Foresight News

The Uniswap protocol is an important cryptographic infrastructure for millions of traders and supports over $1.6 trillion in trading volume by providing deep liquidity, and Uniswap v4 is the latest evolution of the protocol, allowing developers to use Hooks Build custom AMM functions on top of Uniswap.

Previously we wrote about the Time Weighted Average Market Maker Hookarticle, today we will focus on the truncated oracle.

Price oracles, such as those in the Uniswap v3 pool, are known to deliver price information about liquidity pools to other DeFi protocols, and truncated price oracles, deployed as optional v4 hooks, can reduce large transactions It will have an impact on prices and make it more oracle-resistant, making it safer to use in DeFi scenarios.

The role of price oracles

A price oracle is a tool used to view price information for a specific asset. These on-chain oracles are trustless price sources that reflect 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.

The Uniswap v3 price oracle was built with Ethereum’s Proof-of-Work (PoW) mechanism in mind, but after Ethereum’s consensus algorithm switched to Proof-of-Stake (PoS), some of the oracle’s key assumptions changed, making Its safety is reduced.

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

So we need to modify the oracle to make it more resilient, and the truncated price oracle uses a different formula to calculate the price and can provide a more reliable price feed that is less susceptible to manipulation.

What is a truncated oracle hook?

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

This truncation helps eliminate the long-term impact of large transactions on price—whether these large transactions are legitimate or malicious, because if a malicious actor attempts to manipulate the price, the manipulation must continue across multiple blocks. , which makes the operation cost of truncated oracles very high.

How does the truncated oracle hook work?

The smart contract of this Hook stores a copy of the price of the corresponding liquidity pool, where in Uniswap v3 and v4, these prices are expressed in ticks.

Before making a trade or LP adjustment, Hook compares the current price movement of the liquidity pool with the price movement stored in its contract, and if the difference between the two numbers is less than a certain numerical unit (based on our research, we use 9, 116), then Hook will be updated to this new price point.

However, if the current price movement of the liquidity pool exceeds 9116 digital units, the oracle will cap its price to +- 9116, thus limiting the amount of price point movement of the liquidity pool in a block.

After the Hook is updated, the transaction or LP adjustment will not be executed until the end of the corresponding block, and then the cycle repeats with the next block that triggers the Hook smart contract.

By truncating the extent of recordable price (point) swings, the oracle can ignore outliers and eliminate the impact of large trades on price. If prices continue to fluctuate significantly, the oracle will quickly adapt to the price point of the liquidity pool.

Truncating oracles are safer

Let’s use the lending market as an example to better understand truncated prophecies. The DeFi lending market allows users to deposit assets as collateral in order to lend out other assets, up to a portion of the collateral value.

For example, if the mortgage rate in the lending market is 1.5, then Alice needs to provide at least US$1,500 in collateral to lend out 1,000 USDC. That is, if the ETH is US$1,000, then Alice needs to deposit at least 1.5 ETH.

And during the borrowing process, Alice needs to maintain a ratio of at least 1.5, which means that if the price of her 1.5 ETH drops, then anyone can repay her bad debt and obtain the collateral of these 1.5 ETH.

The lending market uses price oracles to compare the prices of ETH and USDC. While it is currently economically impractical to manipulate the ETH/USDC liquidity pool on Uniswap v3, malicious actor Bob could influence smaller-scale DEXs by executing large transactions and driving down the price of ETH.

This allows Bob to manipulate the lending market so that Alices position needs to be liquidated, and Bob can then pay off Alices loan for less than $1,500 and take her 1.5 ETH.

This type of manipulation is one of the most common ways that DeFi protocols that rely on price oracles can be manipulated to cause losses. Lending and lending protocols are just one example. Other DeFi primitives (such as perpetual contracts) also rely on on-chain price oracles.

If the DeFi lending market that Alice is in uses a truncated price oracle, then Bob will have to continue to conduct market manipulation for a period of time. For example, in this example, Bob must wait 15 blocks for the price of the oracle to achieve the fluctuation he wants before he can try to liquidate Alices position.

But within these five minutes, the arbitrage robot may eat Bobs corresponding transaction, leaving him with nothing. For Bob, this cost is too high.

at presentUniswap v4and truncated oracle hooks are still under development and final specifications may change.


Uniswap
Oracle
Welcome to Join Odaily Official Community