The calculateDustAmount function in the RToken contract contains two related calculation errors:
Redundant calculation of the interest rate index (index).
Comparison between different units (standardized RToken vs non-standardized underlying token ).
These two errors combined cause the function to always return 0, making the dust transfer functionality completely ineffective and preventing the system from clearing dust assets.
The calculateDustAmount function contains two major issues:
Redundant Calculation of the Interest Rate Index: The index (interest rate) is already accounted for in totalSupply(). The function incorrectly multiplies currentTotalSupply by the index again, which results in an overestimation of the totalRealBalance.
Comparison Between Different Units: The function compares contractBalance (in the RToken unit without interest) with totalRealBalance (in the underlying asset unit with interest), leading to mismatched units and an incorrect result. The function should be comparing values of the same unit.
Vulnerability Code
contracts/core/tokens/RToken.sol:calculateDustAmount#L317-L328
contracts/core/tokens/RToken.sol:totalSupply#L204
contracts/core/tokens/RToken.sol:transferAccruedDust#L354
contracts/core/pools/LendingPool/LendingPool.sol:transferAccruedDust#L747
Dust Transfer Failure: The dust transfer functionality (transferAccruedDust) fails because calculateDustAmount always returns 0.
Locked Funds: Dust funds, which are small leftover amounts in the contract, cannot be cleared or transferred, potentially leaving funds locked in the contract permanently.
System Inefficiency: The inability to clear dust funds increases contract inefficiency and can negatively impact the platform’s liquidity and asset management.
Manual Code Review
To fix this issue, the redundant calculation of the interest rate index should be removed, and the comparison should be done using consistent units. The updated implementation should look like this:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.