The rToken contract has a flaw where token amounts are scaled twice during transfers and balance updates. Both the transfer and transferFrom functions adjust the amount using rayDiv with the normalized income (getNormalizedIncome). However, when the _update function processes the transaction, the same amount is scaled again. This results in an unintended reduction in token values, leading to incorrect balance updates and transfer amounts.
Issue:
The contract applies scaling twice—first in transfer and transferFrom, and then again in _update. This double application of rayDiv leads to an unintended decrease in transferred token amounts.
Affected Code:
Transfer Function:
TransferFrom Function:
_update Function:
If an initial amount of 1000e18 is processed with a scaling factor of 2e18, the first adjustment reduces it to 500e18. When _update applies another scaling, it drops further to 250e18, which is incorrect.
Reduced Transfer Amounts:
Due to the unintended double scaling, recipients receive fewer tokens than they should.
Inaccurate Balances:
Users’ token balances are updated incorrectly, leading to discrepancies in their holdings.
Potential Token Loss:
The miscalculation can result in token amounts shrinking with each transaction, causing financial discrepancies.
Manual Code Review
Prevent Double Scaling:
Ensure that token amounts are adjusted only once by modifying the _update function to use the already scaled value.
Fix the _update Function:
Modify _update to prevent additional scaling:
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.