The Redeem() and redeemTo() functions in the RToken contract allow users to redeem their RTokens for the underlying basket of collateral tokens. During the redemption process, the basketsNeeded variable is updated to reflect the reduced number of baskets required for collateralization.
However, the calculation of amtBaskets in the _scaleDown() function, is called by both redeem() and redeemTo(). This leads to incorrect accounting of the basketsNeeded value, affecting the overall stability and collateralization of the RToken system.
The calculation of amtBaskets uses basketsNeeded.muluDivu(amtRToken, totalSupply()), which may not accurately reflect the number of baskets to be deducted based on the redeemed RToken amount.
Impact
The basketsNeeded variable, which represents the number of baskets required for full collateralization, may not be updated correctly during redemptions. This can result in the RToken system believing it has more or fewer baskets than it actually does.
If the basketsNeeded value is not reduced accurately during redemptions, the RToken system may not maintain the expected level of collateralization.
The basketsNeeded value is used in various calculations, such as determining the exchange rate between RTokens and the underlying basket. Inaccuracies in basketsNeeded can lead to incorrect exchange rates, affecting the value of RTokens and the fairness of redemptions.
Proof of Concept
Let's say:
Alice holds a significant amount of RTokens and decides to redeem them using the redeem() function.
The redeem() function calls the _scaleDown() function to update the basketsNeeded value based on the redeemed amount.
However, due to the incorrect calculation of amtBaskets in _scaleDown(), the basketsNeeded value is not reduced accurately.
As a result, the RToken system now has an inaccurate basketsNeeded value, which may not reflect the true number of baskets required for collateralization.
This inaccuracy can lead to improper collateralization, incorrect exchange rate calculations, and potential instability in the RToken system.
Tools Used
Manual review
Recommended Mitigation Steps
Update the calculation to reflect the number of baskets to be deducted based on the redeemed RToken amount. By calculating amtBaskets as amtRToken.muluDivu(basketsNeeded, totalSupply()), the function will accurately determine the number of baskets to be deducted based on the redeemed RToken amount.
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L508-L516 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L160-L190
Vulnerability details
The
Redeem()
andredeemTo()
functions in the RToken contract allow users to redeem their RTokens for the underlying basket of collateral tokens. During the redemption process, thebasketsNeeded
variable is updated to reflect the reduced number of baskets required for collateralization.However, the calculation of
amtBaskets
in the_scaleDown()
function, is called by bothredeem()
andredeemTo()
. This leads to incorrect accounting of thebasketsNeeded
value, affecting the overall stability and collateralization of the RToken system.Arises in the
_scaleDown()
function in RToken.sol:508-516The calculation of
amtBaskets
usesbasketsNeeded.muluDivu(amtRToken, totalSupply())
, which may not accurately reflect the number of baskets to be deducted based on the redeemed RToken amount.Impact
The
basketsNeeded
variable, which represents the number of baskets required for full collateralization, may not be updated correctly during redemptions. This can result in the RToken system believing it has more or fewer baskets than it actually does.If the
basketsNeeded
value is not reduced accurately during redemptions, the RToken system may not maintain the expected level of collateralization.The
basketsNeeded
value is used in various calculations, such as determining the exchange rate between RTokens and the underlying basket. Inaccuracies inbasketsNeeded
can lead to incorrect exchange rates, affecting the value of RTokens and the fairness of redemptions.Proof of Concept
Let's say:
redeem()
function.redeem()
function calls the_scaleDown()
function to update thebasketsNeeded
value based on the redeemed amount.amtBasket
s in_scaleDown()
, thebasketsNeeded
value is not reduced accurately.basketsNeeded
value, which may not reflect the true number of baskets required for collateralization.Tools Used
Manual review
Recommended Mitigation Steps
Update the calculation to reflect the number of baskets to be deducted based on the redeemed RToken amount. By calculating
amtBaskets
asamtRToken.muluDivu(basketsNeeded
,totalSupply())
, the function will accurately determine the number of baskets to be deducted based on the redeemed RToken amount.Assessed type
Math