Core Contracts

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

Incorrect Implementation of Normalized Income

Summary

The ReserveLibrary contains error in its implementation of getNormalizedDebt function This function incorrectly calculate interest rates and return wrong values, which affects the entire protocol's interest rate model and economic calculations.

Vulnerability Details

The issue exists in ReserveLibrary.sol:

  1. getNormalizedIncome incorrectly applies double scaling by multiplying the already scaled interest rate with the liquidity index again

/**
* @notice Gets the normalized income of the reserve.
* @param reserve The reserve data.
* @return The normalized income (in RAY).
*/
function getNormalizedIncome(ReserveData storage reserve, ReserveRateData storage rateData) internal view returns (uint256) {
uint256 timeDelta = block.timestamp - uint256(reserve.lastUpdateTimestamp);
if (timeDelta < 1) {
return reserve.liquidityIndex;
}
return calculateLinearInterest(rateData.currentLiquidityRate, timeDelta, reserve.liquidityIndex).rayMul(reserve.liquidityIndex);
}

Proof of Concept

contract ReserveLibraryPoc is Test {
using WadRayMath for uint256;
using ReserveLibrary for ReserveLibrary.ReserveData;
using ReserveLibrary for ReserveLibrary.ReserveRateData;
ReserveLibrary.ReserveData reserve;
ReserveLibrary.ReserveRateData rateData;
function setUp() public {
reserve.liquidityIndex = 1.1e27;
reserve.usageIndex = 1.1e27;
reserve.lastUpdateTimestamp = uint40(block.timestamp);
rateData.currentLiquidityRate = 0.05e27; // 5% APY
}
function test_double_scaling_in_normalized_income() public {
vm.warp(block.timestamp + 365 days);
uint256 normalizedIncome = ReserveLibrary.getNormalizedIncome(reserve, rateData);
uint256 expectedIncome = ReserveLibrary.calculateLinearInterest(
rateData.currentLiquidityRate,
365 days,
reserve.liquidityIndex
);
// This fails because normalizedIncome is double scaled
assertEq(normalizedIncome, expectedIncome);
}
}

Running the test shows:

[FAIL] test_double_scaling_in_normalized_income()
Expected: 1050000000000000000000000000
Actual: 1155000000000000000000000000

Impact

  1. Interest rates are incorrectly calculated (15.5% instead of 5% in the PoC)

  2. Debt calculations are wrong, affecting liquidations

  3. All users are affected by incorrect interest calculations

Tools Used

  • Manual code review

Recommendations

  1. Remove double scaling from getNormalizedIncome

  2. Fix getNormalizedDebt to return usageIndex

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!