https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/tokens/RToken.sol#L212-L215
https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/tokens/RToken.sol#L223-L226
https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/tokens/RToken.sol#L307-L311
The RToken contract contains two issues related to the calculation of scaled amounts and the usage of the liquidity index:
Double Calculation of Scaled Amounts: The _update function recalculates scaled amounts even though they are already calculated in functions like transfer and transferFrom. This leads to incorrect token balances and potential financial discrepancies.
Incorrect Liquidity Index Usage in transferFrom: The transferFrom function uses the _liquidityIndex instead of the normalized income from the LendingPool. This results in incorrect scaling of amounts, as the _liquidityIndex is never updated since RToken::updateLiquidityIndex was not implemented in the LendingPool, it will always return its initialized value.
The _update function, which is called during token transfers, mints, and burns, recalculates the scaled amount using the normalized income from the LendingPool. However, functions like transfer and transferFrom already calculate the scaled amount before calling _update. This results in the scaled amount being calculated twice, leading to incorrect token balances.
transferFromThe transferFrom function uses the _liquidityIndex to calculate the scaled amount instead of the normalized income from the LendingPool. This is problematic because:
The _liquidityIndex is not updated, leading to outdated values.
The normalized income from the LendingPool is the correct value to use for scaling, as it reflects the current state of the reserve pool.
Double Calculation of Scaled Amounts:
The _update function recalculates the scaled amount:
However, functions like transfer and transferFrom already calculate the scaled amount before calling _update:
Incorrect Liquidity Index Usage in transferFrom:
The transferFrom function uses the _liquidityIndex instead of the normalized income:
Double Calculation of Scaled Amounts:
A user transfers 100 tokens. The transfer function calculates the scaled amount as 90 tokens (assuming a normalized income of 1.1).
The _update function recalculates the scaled amount again, reducing it further to 81 tokens.
The recipient receives 81 tokens instead of the expected 90 tokens.
Incorrect Liquidity Index Usage in transferFrom:
A user transfers 100 tokens using transferFrom. The function uses the outdated _liquidityIndex (which is, 1.0 since it was initialized as WadRayMath.RAY) instead of the normalized income (e.g., 1.1).
The scaled amount is calculated as 100 tokens instead of 90 tokens, leading to incorrect token balances.
Incorrect Token Balances: Double calculation of scaled amounts leads to incorrect token balances, causing financial discrepancies.
Outdated Scaling: Using the _liquidityIndex instead of the normalized income results in outdated scaling, leading to incorrect token transfers.
Manual Code Review: The vulnerabilities were identified through a manual review of the RToken contract.
Solidity: The smart contract language used to write the contract.
Choose either of these 2 mitigations, depends on what the protocol prefers
Remove Double Calculation of Scaled Amounts:
Use Normalized Income in transferFrom:
Update the transferFrom function to use the normalized income from the LendingPool instead of the _liquidityIndex.
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.