You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rounding errors compounded over time can lead to inaccurate interest accumulation, impacting both borrowers and lenders.
Root Cause
In https://github.com/sherlock-audit/2024-12-numa-audit/blob/ae1d7781efb4cb2c3a40c642887ddadeecabb97d/Numa/contracts/lending/CToken.sol#L459
The accrueInterest function calculates interest using Exp structs but can result in rounding errors due to the truncation of mantissas. This is because the Exp struct represents fixed-point numbers with a mantissa (the significant digits of the number) and an implicit exponent. When performing arithmetic operations with these fixed-point numbers, the results are often truncated to fit within the fixed-point representation.
Internal pre-conditions
Here's why this can lead to rounding errors:
1.Fixed-Point Arithmetic: The Exp struct uses fixed-point arithmetic, which involves scaling numbers by a factor (e.g., 1e18) to represent fractional values. When performing operations like multiplication or division, the results are scaled back down, which can lead to truncation of the least significant digits.
2.Truncation: During arithmetic operations, especially division, the result may not be an exact multiple of the scaling factor. This means that the result will be truncated to fit within the fixed-point representation, losing some precision in the process.
3.Accumulation of Errors: Over time, as interest is accrued repeatedly, these small truncation errors can accumulate, leading to noticeable discrepancies in the calculated interest.
External pre-conditions
No response
Attack Path
No response
Impact
Small rounding errors compounded over time can lead to inaccurate interest accumulation, impacting both borrowers and lenders causing financial discrepancies leading to unfair interest calculations and protocol instability.
PoC
No response
Mitigation
1.Increase Precision: Use a higher precision for the fixed-point representation. For example, instead of using 18 decimal places, you could use 27 or more. This reduces the impact of truncation errors but may increase gas costs.
2.Accumulate Interest in a Separate Variable: Instead of updating the principal directly, accumulate the interest in a separate variable and update the principal periodically. This reduces the frequency of truncation errors.
The text was updated successfully, but these errors were encountered:
Bouncy Cloud Mockingbird
High
Rounding Errors in Interest Rate Calculations
Summary
Rounding errors compounded over time can lead to inaccurate interest accumulation, impacting both borrowers and lenders.
Root Cause
In https://github.com/sherlock-audit/2024-12-numa-audit/blob/ae1d7781efb4cb2c3a40c642887ddadeecabb97d/Numa/contracts/lending/CToken.sol#L459
The accrueInterest function calculates interest using Exp structs but can result in rounding errors due to the truncation of mantissas. This is because the Exp struct represents fixed-point numbers with a mantissa (the significant digits of the number) and an implicit exponent. When performing arithmetic operations with these fixed-point numbers, the results are often truncated to fit within the fixed-point representation.
Internal pre-conditions
Here's why this can lead to rounding errors:
1.Fixed-Point Arithmetic: The Exp struct uses fixed-point arithmetic, which involves scaling numbers by a factor (e.g., 1e18) to represent fractional values. When performing operations like multiplication or division, the results are scaled back down, which can lead to truncation of the least significant digits.
2.Truncation: During arithmetic operations, especially division, the result may not be an exact multiple of the scaling factor. This means that the result will be truncated to fit within the fixed-point representation, losing some precision in the process.
3.Accumulation of Errors: Over time, as interest is accrued repeatedly, these small truncation errors can accumulate, leading to noticeable discrepancies in the calculated interest.
External pre-conditions
No response
Attack Path
No response
Impact
Small rounding errors compounded over time can lead to inaccurate interest accumulation, impacting both borrowers and lenders causing financial discrepancies leading to unfair interest calculations and protocol instability.
PoC
No response
Mitigation
1.Increase Precision: Use a higher precision for the fixed-point representation. For example, instead of using 18 decimal places, you could use 27 or more. This reduces the impact of truncation errors but may increase gas costs.
2.Accumulate Interest in a Separate Variable: Instead of updating the principal directly, accumulate the interest in a separate variable and update the principal periodically. This reduces the frequency of truncation errors.
The text was updated successfully, but these errors were encountered: