Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Invalid

Precision Loss in Liquidity Index Calculation

Issue:

In ReserveLibrary::calculateLiquidityIndex, the final value is downcast to uint128 after rayMul(lastIndex):

function calculateLiquidityIndex(
uint256 rate,
uint256 timeDelta,
uint256 lastIndex
) internal pure returns (uint128) {
uint256 cumulatedInterest = calculateLinearInterest(
rate,
timeDelta,
lastIndex
);
@> return cumulatedInterest.rayMul(lastIndex).toUint128();
}

Remember that calculateLinearInterest returns uint256:

/**
* @notice Calculates the new liquidity index using linear interest.
* @param rate The current liquidity rate (in RAY).
* @param timeDelta The time since the last update (in seconds).
* @param lastIndex The previous liquidity index.
* @return The new liquidity index.
*/
function calculateLinearInterest(
uint256 rate,
uint256 timeDelta,
uint256 lastIndex //* unused param
) internal pure returns (uint256) {
uint256 cumulatedInterest = rate * timeDelta;
cumulatedInterest = cumulatedInterest / SECONDS_PER_YEAR;
return WadRayMath.RAY + cumulatedInterest;
}

Back to calculateLiquidityIndex, since rayMul maintains RAY (1e27) precision, this can cause truncation or overflow if the result exceeds uint128 max (2^128 - 1).

Impact: Potential loss of accrued interest, incorrect liquidity index updates

Recommendation:

Ensure safe downcasting

Updates

Lead Judging Commences

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.