function supplyAssets(address asset, bytes32 positionId) external view returns (uint256)
function debtAssets(address asset, bytes32 positionId) external view returns (uint256)
When external functions call these functions to query data, if they require real-time values, it may lead to severe and dangerous situations.
Vulnerability Detail
The main reason for the above issues is that they ignore the fact that both the balance and debt values can change over time. In practice, a pool may not update its liquidityIndex or borrowIndex for a period of time, as these values are only updated when functions like supply, borrow, withdraw, repay, liquidation, or forceUpdateReserves are triggered.
Let’s assume the pool’s liquidityRate and borrowRate are both non-zero, and the liquidityIndex and borrowIndex have not been updated for an hour. In this case, the functions querying the balance and debt should take time into account in the calculation formulas. Otherwise, the values retrieved will not be real-time. This poses significant risks for upstream functions that rely on these values if they do not account for this issue.
Impact
The balance and debt calculations in PoolGetter for users or pools are not real-time, which can lead to critical errors in upstream logic. For example, one observed issue is:
The balance and debt calculations in PoolGetter for users or pools are not real-time, which can lead to critical errors in upstream logic. For example, one observed issue is:
neon2835
High
PoolGetter's Calculation of User or Pool Balance and Debt is Not Real-Time, it may lead to severe and dangerous situations
Summary
In
PoolGetter
, thebalance
anddebt
calculations for users or pools in the following functions are not real-time values:When external functions call these functions to query data, if they require real-time values, it may lead to severe and dangerous situations.
Vulnerability Detail
The main reason for the above issues is that they ignore the fact that both the
balance
anddebt
values can change over time. In practice, a pool may not update itsliquidityIndex
orborrowIndex
for a period of time, as these values are only updated when functions likesupply
,borrow
,withdraw
,repay
,liquidation
, orforceUpdateReserves
are triggered.Let’s assume the pool’s
liquidityRate
andborrowRate
are both non-zero, and theliquidityIndex
andborrowIndex
have not been updated for an hour. In this case, the functions querying thebalance
anddebt
should take time into account in the calculation formulas. Otherwise, the values retrieved will not be real-time. This poses significant risks for upstream functions that rely on these values if they do not account for this issue.Impact
The balance and debt calculations in PoolGetter for users or pools are not real-time, which can lead to critical errors in upstream logic. For example, one observed issue is: The balance and debt calculations in PoolGetter for users or pools are not real-time, which can lead to critical errors in upstream logic. For example, one observed issue is:
Code Snippet
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/PoolGetters.sol#L34
Tool used
Manual Review
Recommendation
Taking the
getBalance
function as an example, the original code is:Optimized version:
Duplicate of #473