During rebalancing when trade settlement, the exchange rate between total supply of rToken and backing needed will be volatile and user can incur slippage loss and there's no validation to check the minimum rToken minted.
While issuance maybe paused during these times, but there will still be user's issue transaction losing to the slippage, because the first rebalancing can even happen before owner pausing issuance.
Rebalancing can happen if the rToken is not frozen during trade settlement or when tradeEnd < block.timestamp.
So, there are flows where exchange rate between total supply of rToken and backing needed, it can be allowed to move between low >= MIN_EXCHANGE_RATE && high <= MAX_EXCHANGE_RATE, 1e9 < rate < 1e27
And if this sudden slippage change of over > 0.5% is a concern to the user who is trying to mint at the current exchange rate. And to protect his slippage, there should be a minimum rToken minted validation during these rebalancing times.
uint256 low = (FIX_ONE_256 * basketsNeeded_) / supply; // D18{BU/rTok}
uint256 high = (FIX_ONE_256 * basketsNeeded_ + (supply - 1)) / supply; // D18{BU/rTok}
// here we take advantage of an implicit upcast from uint192 exchange rates
require(low >= MIN_EXCHANGE_RATE && high <= MAX_EXCHANGE_RATE, "BU rate out of range");
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L409-L413 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L483-L496 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L105
Vulnerability details
Impact
During rebalancing when trade settlement, the exchange rate between total supply of rToken and backing needed will be volatile and user can incur slippage loss and there's no validation to check the minimum
rToken
minted.While issuance maybe paused during these times, but there will still be user's issue transaction losing to the slippage, because the first rebalancing can even happen before owner pausing issuance. Rebalancing can happen if the rToken is not frozen during trade settlement or when
tradeEnd < block.timestamp
.Proof of Concept
A user approves the token amounts and gets minted
x
rTokens. But the amount of rTokens minted depends onbasketsNeeded
andtotalSupply
an the input parameteramount
.The
basketsNeeded
is volatile irrespective or independent oftotalSupply
in the following flow of rebalancing the backing manager. BackingManagerP1::settleTrade >> BackingManagerP1::rebalance >> BackingManagerP1::compromiseBasketsNeeded >> rToken.setBasketsNeededSo, there are flows where exchange rate between total supply of rToken and backing needed, it can be allowed to move between
low >= MIN_EXCHANGE_RATE && high <= MAX_EXCHANGE_RATE
, 1e9 < rate < 1e27And if this sudden slippage change of over > 0.5% is a concern to the user who is trying to mint at the current exchange rate. And to protect his slippage, there should be a minimum rToken minted validation during these rebalancing times.
rToken.setBasketsNeeded
rToken::issueTo and rToken::_scaleUp
Tools Used
Vs code
Recommended Mitigation Steps
Modify rToken::issueTo and rToken::_scaleUp
Assessed type
MEV