Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

新闻报道新闻报道
0

引言:
去中心化金融(DeFi)的蓬勃发展,使得去中心化交易所(DEX)成为了市场关注的焦点。Uniswap作为行业领先的DEX,其v3版本在功能设计上进行了重大创新。本文将深入分析Uniswap v3的核心机制,并详细解读其功能设计,同时为审计人员提供相关的审计要点。

一、Uniswap v3核心机制
Uniswap v3协议主要由四个模块组成:
1. PositionManager:用户进行流动性操作的主要接口,通过该模块创建代币池、提供/移除流动性,并使用ERC721作为流动性提供者(LP)的凭证。
2. SwapRouter:用户进行代币交换的入口,通过该模块完成代币的交换操作。
3. Pool:负责实现代币交易、流动性管理、收取交易手续费,以及Oracle数据的管理功能。其中,Tick机制将价格范围划分为多个精细的刻度。
4. Factory:用于创建和管理Pool合约。

二、Uniswap v3功能设计
1. 创建代币对
用户通过createAndInitializePoolIfNecessary函数完成代币对的创建。系统会检查代币对是否存在,若不存在,则调用createPool函数进行部署,并通过initialize函数完成参数初始化。
2. 提供流动性
用户通过mint函数创建新的流动性头寸并生成对应的NFT,或通过increaseLiquidity函数为现有的NFT流动性头寸增加流动性。
3. 移除流动性
用户通过decreaseLiquidity函数移除流动性。系统会检查LP凭证权限和交易时间有效性,确保池子拥有足够流动性后,调用burn函数移除流动性,并更新用户Position信息。
4. swap
用户通过exactInput函数指定支付token数量及期望获得的最小token数量,或通过exactOutput函数指定支付的最大token数量及期望获得的token数量。系统会解析路径,依次调用exactInputInternal或exactOutputInternal函数完成swap操作,并更新手续费、流动性、tick和价格等值。
5. flash
用户通过flash函数进行闪电贷操作。系统计算借贷手续费,发送token到指定地址,并回调用户实现的uniswapV3FlashCallback函数完成还款操作。

三、审计要点
1. 检查swap操作后是否有调用refundETH
在exactInput函数中,用户需指定支付的token数量和预期获得的最小token数量。系统会重新计算amount0和amount1,以确保用户可以精确地发送token。然而,当使用ETH进行交换时,用户需要随交易一起发送ETH。即便在交易过程中未使用完所有的ETH,函数不会自动退回多余部分。因此,建议检查swap操作后是否调用refundETH,以防止用户未使用的ETH遗留在协议中。
2. 检查是否实现TWAP来获取预言机价格
当将Uniswap作为价格来源时,外部协议直接访问Slot0获取sqrtPriceX96可能存在价格操纵的风险。为降低这种风险,建议开发者实现时间加权平均价格(TWAP)来获取价格,以增加操纵价格的难度。

结论:
Uniswap v3在功能设计上进行了重大创新,为去中心化金融领域提供了更多可能性。本文对Uniswap v3的核心机制和功能设计进行了深入剖析,并为审计人员提供了相关的审计要点。随着DeFi的不断发展,Uniswap v3有望在去中心化金融领域发挥更大的作用。


>>> Read more <<<

Views: 0

0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注