Core Contracts

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

Incorrect calculation of compound interest due to incorrect taylor series expansion formula

Summary

The taylor series expansion calculation function rayExp in WadRayMath library used to calculated the compound interest has incorrect denominators.

function rayExp(uint256 x) internal pure returns (uint256 z) {
if(x == 0) {
return WadRayMath.RAY;
}
// Compute e^x, where x is in ray units (scaled by 1e27)
// assembly implementation for maximum gas efficiency
// Using a fixed number of terms for the Taylor series expansion
//@Audit the dominators are wrong here which would cause a error in the tylor series calculation as x gets bigger
assembly {
// Initialize result with 1 in ray units (1e27)
let result := 1000000000000000000000000000
// First term: 1 + x
result := add(result, x)
// Second term: x^2 / 2!
let term := div(mul(x, x), 2000000000000000000000000000) // should be bx^2 / 2e27
result := add(result, term)
// Third term: x^3 / 3!
term := div(mul(x, term), 3000000000000000000000000000) // should be x^3 / 6e27
result := add(result, term)
// Fourth term: x^4 / 4!
term := div(mul(x, term), 4000000000000000000000000000) // should be x^4 / 24e27
result := add(result, term)
// Fifth term: x^5 / 5!
term := div(mul(x, term), 5000000000000000000000000000) // should be x^5 / 120e27
result := add(result, term)
// Sixth term: x^6 / 6!
term := div(mul(x, term), 6000000000000000000000000000) // should be x^6 / 720e27
result := add(result, term)
// Seventh term: x^7 / 7!
term := div(mul(x, term), 7000000000000000000000000000) // should be x^7 / 5040e27
result := add(result, term)
// Assign to return value
z := result
}
}

Vulnerability Details

Due to incorrect implementation of the of the taylor series expansion formula we can get higher a compound interest value compared to the expected one, this is due to incorrect division in the denominators by smaller values. You can see a comparison in the rate of growth between the incorrectly implemented functon in the code and the correct one:

  • Formula being used:

  • Correct formula:

Graphical comparison of the growth of the two functions:

Impact

As the usage rate of the LendingPool is getting bigger so would be inaccuracy in the compound interest calculation, which in turn means that we would get larger values for the compound rate than we should and user debt calculations would yield bigger values as they are dependent on the compound interest value.

Tools Used

  • Manual review

Recommendations

Implement the correct denominator devision in the taylor series expansion calculation.

Updates

Lead Judging Commences

inallhonesty Lead Judge
7 months ago
inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

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

Give us feedback!