The calculateDustAmount
function in the Rtoken contract incorrectly uses rayDiv
and rayMul
to calculate the dust amount, leading to meaningless results.the function scales the contract balance down by 27 decimals and scales the total supply up by 27 decimals, resulting in a huge disparity between the two values. As a result, the function always returns 0 or a very small value, which does not accurately represent the dust generated by the protocol.
The issue exists in the calculateDustAmount
function, which is intended to calculate the excess balance of the underlying asset that is not tied to the rToken supply. The function performs the following steps:
Scales Down Contract Balance:
The contract balance is divided by the normalized income using rayDiv
, which scales it down by 27 decimals.
Example: If the contract balance is 100e18 and the normalized income is 1.1e27, the result is 90.90e-9.
Scales Up Total Supply:
The total supply of rTokens is multiplied by the normalized income using rayMul
, which scales it up by 27 decimals.
Example: If the total supply is 90.90e18 and the normalized income is 1.1e27, the result is 99.99e45.
Compares and Subtracts:
The scaled-down contract balance is compared to the scaled-up total real balance.
Due to the scaling, the contract balance will always be much smaller than the total real balance, causing the function to always return 0.
The function always returns 0 which does not accurately represent the dust generated by the protocol. So If the dust amount is used for donations or protocol fees, the incorrect calculation indeed could lead to
Loss of funds (if dust is underestimated).
Manuel review
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.