The RToken contract implements an interest-bearing token where balances increase over time due to interest accrual. The contract maintains two types of balances:
Scaled balances (shares) - stored internally
Normalized balances (assets) - exposed to users, calculated by multiplying shares by the liquidity index
The calculateDustAmount() function is designed to determine the amount of underlying assets in the contract that are not accounted for by user balances, which can then be recovered through transferAccruedDust().
The calculateDustAmount() function contains a critical error in its calculation logic that results in incorrect dust amount determination. The current implementation:
Scales down the contract's actual asset balance by the liquidity index:
Gets the total supply in normalized terms (already in assets):
Incorrectly scales up the already-normalized total supply:
The fundamental issue is that the function mixes scaled and normalized values incorrectly, leading to a comparison between incompatible units and double-scaling of the total supply.
High. The incorrect calculation leads to:
False positives - reporting dust when there isn't any
False negatives - failing to detect actual dust
Incorrect dust amounts when dust exists
This directly affects the contract's ability to recover excess assets through transferAccruedDust(), potentially leading to trapped assets or excessive withdrawals.
High. The function will consistently produce incorrect results whenever it is called, affecting all dust recovery operations.
Consider a scenario with:
Liquidity index = 2 RAY
Actual asset balance = 1000 tokens
Total user balances (normalized) = 900 tokens
Expected dust = 1000 - 900 = 100 tokens
Current implementation:
contractBalance = 1000 / 2 = 500 (incorrectly scaled down)
currentTotalSupply = 900 (correct)
totalRealBalance = 900 * 2 = 1800 (incorrectly scaled up)
Result = 0 (since 500 < 1800)
The function reports no dust when there should be 100 tokens available for recovery.
The function should be rewritten to compare values in the same unit (assets):
This implementation:
Uses the raw asset balance from the contract
Uses the normalized total supply (already in asset terms)
Compares compatible units to determine the true dust amount
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.