来源:SharkTeam
2024年6月10日,UwU Lend遭受攻击,项目方损失约1930万美元。
一、攻击交易分析
攻击者:0x841dDf093f5188989fA1524e7B893de64B421f47
攻击者共发起了3笔攻击交易:
攻击交易1:
0x242a0fb4fde9de0dc2fd42e8db743cbc197ffa2bf6a036ba0bba303df296408b
攻击交易2:
0xb3f067618ce54bc26a960b660cfc28f9ea0315e2e9a1a855ede1508eb4017376
攻击交易3:
0xca1bbf3b320662c89232006f1ec6624b56242850f07e0f1dadbe4f69ba0d6ac3
以攻击交易1为例,进行分析:
攻击合约:0x21c58d8f816578b1193aef4683e8c64405a4312e
目标合约:UwU Lend金库合约,包括:
uSUSDE:0xf1293141fc6ab23b2a0143acc196e3429e0b67a6
uDAI:0xb95bd0793bcc5524af358ffaae3e38c3903c7626
uUSDT:0x24959f75d7bda1884f1ec9861f644821ce233c7d
攻击过程如下:
1. 从不同平台闪电贷多种代币,包括WETH, WBTC, sUSDe, USDe, DAI, FRAX, USDC, GHO
代币接收地址为0x4fea76b66db8b548842349dc01c85278da3925da

闪电贷的代币和数量如下:
从AaveV3中闪电贷159,053.16 WETH和14,800 WBTC
从AaveV2中闪电贷40,000 WETH
从Spark中闪电贷91,075.70 WETH和4,979.79 WBTC
从Morpho中闪电贷301,738,880.01 sUSDe,236,934,023.17 USDe和100,786,052.15 DAI
从Uniswap V3: FRAX-USDC 中闪电贷60,000,000 FRAX和15,000,000 USDC
从Balancer中闪电贷4,627,557.47 GHO和38,413.34 WETH
从Maker中闪电贷500,000,000 DAI
共计约328,542.2 WETH,19779.79 WBTC,600786052.15 DAI,301,738,880.01 sUSDe,236,934,023.17 USDe,4,627,557.47 GHO,60,000,000 FRAX,15,000,000 USDC
2. 将闪电贷的Token转移到合约0xf19d66e82ffe8e203b30df9e81359f8a201517ad(简记为0xf19d)中,为发起攻击做准备。

3. 通过兑换(exchange)代币,控制sUSDe的价格(降低价格)

(1)USDecrvUSD.exchange

将8,676,504.84 USDe兑换成8,730,453.49 crvUSD,USDecrvUSD中USDe数量增加,价格降低,crvUSD数量减少,价格提高
(2)USDeDAI.exchange

将46,452,158.05 USDe兑换成14,389,460.59 DAI,USDeDAI中USDe数量增加,价格降低,DAI数量减少,价格提高
(3)FRAXUSDe.exchange
将14,477,791.69 USDe兑换成46,309,490.86 FRAX,USDeDAI中USDe数量增加,价格降低,FRAX数量减少,价格提高
(4)GHOUSDe.exchange

将4,925,427.20 USDe兑换成4,825,479.07 GHO,USDeDAI中USDe数量增加,价格降低,GHO数量减少,价格提高
(5)USDeUSDC.exchange

将14,886,912.83 USDe兑换成14,711,447.94 USDC,USDeDAI中USDe数量增加,价格降低,USDC数量减少,价格提高
以上exchange后,5个资金池中的USDe价格降低。最终导致sUSDe价格大跌。
4. 不断创建借贷头寸,即向LendingPool合约中存入其他资产(WETH,WBTC和DAI),然后借贷sUSDe。因为sUSDe价格大跌,因此,借出的sUSDe数量比价格大跌前要多很多。

5. 与第3步类似,反向操作将sUSDe的价格拉高。

由于sUSDe被拉高,第4步借贷的头寸价值超过抵押价值,达到了清算的标准。
6. 批量地对借贷头寸进行清算,获得清算奖励uWETH

7. 偿还贷款,提取标的资产WETH, WBTC,DAI和sUSDe。

8. 将sUSDe再次存入到LendingPool中,此时sUSDe价格被拉高,因此可以借贷出较多其他资产,包括DAI和USDT。

9. 兑换代币,偿还闪电贷。最终获利1,946.89 ETH


二、漏洞分析
通过以上分析,发现整个攻击过程存在大量的闪电贷以及多次操纵sUSDe的价格,当抵押sUSDe时,会影响借出资产的数量;当借出sUSDe时,会影响借贷率,进而影响清算系数(健康因子)。
攻击者利用这一点,通过闪电贷砸低sUSDe的价格,抵押其他资产,借出大量的sUSDe,然后再抬高sUSDe的价格,清算抵押资产而获利,并将剩余的sUSDe抵押借出其他资产,最后偿还闪电贷,攻击完成。
从上面第3步发现,攻击者通过控制Curve Finance的USDe/rvUSD, USDe/AI, FRAX/SDe, GHO/SDe和USDe/SDC这5个交易池中的USDe的价格来操纵sUSDe的价格的。价格读取函数如下:


其中,sUSDe价格由11个价格计算得到的,其中前10个由CurveFinance中读取,最后一个又UniswapV3提供。
从CurveFinance中读取的价格则是由USDe/rvUSD, USDe/AI, FRAX/SDe, GHO/SDe和USD/SDC这5个交易池提供,也是攻击者在攻击交易中操纵的5个交易池。


返回的价格由uwuOracle读取的price,CurveFinance交易池合约中的price_oracle(0)和get_p(0)计算得到的。
(1)price是有Chainlink提供的价格,是不可以操纵的;

(2)交易池参数


攻击者通过操纵交易池的代币数量来操纵get_p(0)的返回值,进而实现操纵价格。
三、安全建议
针对本次攻击事件,开发过程中应遵循以下注意事项:
(1)针对操纵价格的漏洞,可以采用链下的价格预言机,这样可以避免价格被操纵。
(2)项目上线前,需要由第三方专业的审计公司进行智能合约审计。