In the RToken contract, the calculateDustAmount function incorrectly scales the total supply twice when calculating the total real balance, leading to an artificially inflated denominator and thus underreporting of dust amounts. This affects the protocol's ability to accurately track and manage excess tokens.
The issue lies in the fundamental understanding of how RToken balances are scaled and how the total supply is calculated. Let's break this down:
The protocol uses a ray-based scaling system (similar to Aave) where:
Raw balances are scaled by the liquidity index to account for earned interest
The totalSupply() function is already overridden to return the scaled amount:
The problem occurs because:
totalSupply() returns a value already scaled by the liquidity index
The function then takes this scaled value and scales it again with rayMul(getNormalizedIncome())
This results in the totalRealBalance being artificially large by a factor of the liquidity index
For example:
If raw total supply is 1000
Liquidity index is 1.1
The correct scaled total supply should be: 1000 * 1.1 = 1100
But the function calculates: (1000 * 1.1) * 1.1 = 1210
This means the dust amount from calculateDustAmount is wrong, which means when the reserve pool tries to transferAccruedDust the capped transferAmount is wrong;
Inability to recover legitimate dust tokens
Incorrect reporting of the dust amounts in the RToken
Manual code review
Remove the second scaling operation in calculateDustAmount:
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.