the calculateDustAmount is supposed to calculate the amount of _assetAddress
tokens that is simply lying in the contract (not intended for any user). But this calculation is wrong.
Going through the burn function in the RToken.sol ,it can be seen that the balanceof(user) is the amount of _assetAddress
that the user deserves. => amount can be a maximum of balanceOf(from), and this amount is transferred to the receiverofUnderlying. Thus the above point should be clear.
But the calculateDustAmount(), makes many mistakes:
contractBalance: should have been just IERC20(_assetAddress).balanceOf(address(this)),
totalRealBalance: should have been just the totalSupply (which is just the addition of balanceOf(users) of all the users)
Thus the entire calculation makes no sense and actually reduces the amount of dust calculated than the actual. This makes the contract alway have some extra balance.
Incorrect dust removal functionality
manual review
update the dust calculations as follows:
dust = IERC20(_assetAddress).balanceOf(address(this)) - totalSupply()
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.