The RToken contract's mint function incorrectly handles the scaling of the minting amount, leading to a loss of funds for users who deposit assets. The amount provided to the mint function is not scaled up by the liquidity index before being used in the internal _mint function. While the _update function does scale down the amount to represent the balance in scaled down amount, the initial mint amount is already incorrect, resulting in fewer RTokens minted than expected.
The RToken contract is designed to be a rebasing token, where balances are scaled based on a liquidity index. The mint function is responsible for minting new RTokens when a user deposits the underlying asset. However, the current implementation contains a flaw in how it handles scaling:
Incorrect Scaling: The amountToMint (the user's deposit amount) is divided by the index (liquidity index) using rayDiv. This is incorrect. It should be multiplied by the index using rayMul to account for the accruing interest.
Unscaled Amount Used for Minting: The _mint function is called with the original, unscaled amountToMint instead of correct scaled up balance. This means the user receives fewer RTokens than they should, based on the current liquidity index.
Late Scaling in _update: The _update function does correctly scale the amount down by the normalized income. However, this happens after the incorrect _mint call, so the user has already lost value. The damage is done when the tokens are minted with the unscaled amount.
Loss of Funds for Users: Users receive fewer RTokens than they are entitled to, resulting in a direct financial loss. The magnitude of the loss is proportional to the difference between the liquidity index at the time of deposit and the initial liquidity index.
Assume the liquidity index (index) is 1.1 * 10**27 (representing a 10% increase since the initial value).
Alice deposits 100 units of the underlying asset.
The mint function calculates amountScaled as 100 / 1.1 = 90.91 (approximately). This is incorrect; it should be 100 * 1.1 = 110.
The _mint function is called with 100 instead of correct amountScaled.
Alice receives 100 / 1.1 = 90.91 RTokens, but she should have received 100 RTokens.
Alice has lost approximately 9.09 RTokens due to the incorrect scaling.
Use this guide to intergrate foundry into your project: foundry
Create a new file FortisAudits.t.sol in the test directory.
Add the following gist code to the file: Gist Code
Run the test using forge test --mt test_FortisAudits_IncorrectMintScalingInRToken -vvvv.
Logs before the fix:
Logs after the fix:
To mitigate this vulnerability, the mint function should correctly scale the minting amount by multiplying it by the liquidity index before calling the _mint function. This will ensure that users receive the correct amount of RTokens based on the current liquidity index.
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.