when using 18 decimals token as (TWAP) reference token, token price above 19 of chainlink reference token will overflow and revert in getValue ,and cause many vault function can't use.
Impact
It will cause function getValue of oracle revert,and cause many function using _requireLoanIsHealthy or _checkLoanIsHealthy to getValue can't use.
It include function transform,borrow ,decreaseLiquidityAndCollectand liquidate.User can't transform loan,borrow asset decrease liiquidity and liquadate portion.
Proof of Concept
For convenience, we use DAI as (TWAP) reference token(18 decimals) and 0 address (USD) as chainlink reference token,
In _getReferenceTokenPriceX96,it calculate price in Q96:
It will cause transform,borrow ,decreaseLiquidityAndCollectand liquidate can't use.Because bad debt cannot be liquidated, so I think it is high severity.
One possible liquidation scenario is that the postion NFT‘s token0 price rises above 19USD, and token1 falls (still less than 18USD), which then causes the entire position NFT's collateral value to drop to the liquidation standard. Since the price of token1 will cause revert during liquidation, the user's postion NFT cannot be liquidated in time.
By the way,i don't think this is an issue caused by an administrator configuration error,because I didn't find any configuration about reference token in the white paper and c4 page.At the same time, 18 decimals are more commonly used in standard ERC20 tokens than other decimals tokens,It should be taken into account.
Recommended mitigation steps
Use the FullMath.sol in the uniswap v3 library to perform 512-bit calculations(for example,mulDiv) to prevent overflow.
Lines of code
https://github.com/code-423n4/2024-03-revert-lend/blob/435b054f9ad2404173f36f0f74a5096c894b12b7/src/V3Oracle.sol#L304-L305
Vulnerability details
when using 18 decimals token as (TWAP) reference token, token price above 19 of chainlink reference token will overflow and revert in
getValue
,and cause many vault function can't use.Impact
It will cause function
getValue
of oracle revert,and cause many function using_requireLoanIsHealthy
or_checkLoanIsHealthy
togetValue
can't use.It include function
transform
,borrow
,decreaseLiquidityAndCollect
andliquidate
.User can't transform loan,borrow asset decrease liiquidity and liquadate portion.Proof of Concept
For convenience, we use DAI as (TWAP) reference token(18 decimals) and 0 address (USD) as chainlink reference token,
In _getReferenceTokenPriceX96,it calculate price in Q96:
there is the revert code:
in this formulation,any token price upper 19 USD will overflow,because:
$$ 10^{referenceTokenDecimals} chainlinkPriceX96 Q{96} \ge 10^{18} 19 Q{96} Q_{96} = 19 10^{18} * Q_{192} $$ and :
$$ Q{64} = 2^{64} = 18446744073709551616 \lt 19 10^{18} $$ So : $$ 10^{referenceTokenDecimals} chainlinkPriceX96 * Q{96} \gt Q{192} * Q{64} = Q_{256} = 2^{256} $$ Therefore the previous multiplication operation will cause overflow, and the price query function
getValue
will revert:https://github.com/code-423n4/2024-03-revert-lend/blob/435b054f9ad2404173f36f0f74a5096c894b12b7/src/V3Oracle.sol#L106-L117
It will cause
transform
,borrow
,decreaseLiquidityAndCollect
andliquidate
can't use.Because bad debt cannot be liquidated, so I think it is high severity.One possible liquidation scenario is that the postion NFT‘s token0 price rises above 19USD, and token1 falls (still less than 18USD), which then causes the entire position NFT's collateral value to drop to the liquidation standard. Since the price of token1 will cause revert during liquidation, the user's postion NFT cannot be liquidated in time.
By the way,i don't think this is an issue caused by an administrator configuration error,because I didn't find any configuration about reference token in the white paper and c4 page.At the same time, 18 decimals are more commonly used in standard ERC20 tokens than other decimals tokens,It should be taken into account.
Recommended mitigation steps
Use the FullMath.sol in the uniswap v3 library to perform 512-bit calculations(for example,mulDiv) to prevent overflow.
Assessed type
Under/Overflow