The calculateDustAmount function in the RToken contract incorrectly scales the contract's balance of the underlying asset by dividing it by the normalized income from the lending pool. This scaling is unnecessary and incorrect because the contract balance represents the actual amount of the underlying asset held by the contract, not a scaled value. This issue could lead to incorrect calculations of dust amounts, potentially affecting the protocol's accounting and the ability to rescue dust tokens.
In the calculateDustAmount function, where the contract balance of the underlying asset is scaled by dividing it by the normalized income from the lending pool:
The contractBalance represents the actual amount of the underlying asset held by the contract, not a scaled value. The normalized income is used to scale token balances to account for interest accrual, but it should not be applied to the contract's actual balance of the underlying asset. This incorrect scaling can lead to an underestimation of the dust amount, which is the difference between the contract's actual balance and the total obligations to token holders.
The lending pool has a normalized income of 1.1e27 (10% interest accrued).
The contract holds 100e18 units of the underlying asset.
The total supply of RTokens is 90e18, which corresponds to 99e18 units of the underlying asset when scaled by the normalized income (90e18 * 1.1e27 / 1e27 = 99e18).
In this case, the dust amount should be 1e18 (100e18 - 99e18). However, due to the incorrect scaling, the contractBalance is calculated as:
The dust amount is then calculated as:
This results in an incorrect dust amount of 0, when it should be 1e18.
NOTE: There is an underflow revert happens, but this is only an example to explain the issue better.
The dust amount may be underestimated, leading to incorrect accounting of the contract's balance.
Manual review
The calculateDustAmount function should not scale the contract balance by the normalized income.
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.