Summary
The dust amount is wrongly calculated.
Vulnerability Details
The calculateDustAmount returns the dust amount in the contract
* @notice Calculate the dust amount in the contract
* @return The amount of dust in the contract
*/
function calculateDustAmount() public view returns (uint256) {
@> uint256 contractBalance = IERC20(_assetAddress).balanceOf(address(this)).rayDiv(ILendingPool(_reservePool).getNormalizedIncome());
uint256 currentTotalSupply = totalSupply();
uint256 totalRealBalance = currentTotalSupply.rayMul(ILendingPool(_reservePool).getNormalizedIncome());
return contractBalance <= totalRealBalance ? 0 : contractBalance - totalRealBalance;
}
Here totalSupply() is already converted to current index so no need to again multiply it with getNormalizedIncome to calculate totalRealBalance. (Double conversion happend)
Impact
Incorrect dust calculation lead to incorrect transfer of the accured dust amount.
Tools Used
Recommendations
Calculate dust as shown below.
function calculateDustAmount() public view returns (uint256) {
uint256 contractBalance = IERC20(_assetAddress).balanceOf(address(this));
uint256 currentTotalSupply = totalSupply();
return contractBalance <= currentTotalSupply ? 0 : contractBalance - currentTotalSupply;
}