Early user can call issue() and then melt() to increase basketsNeeded to supply ratio to its maximum value and then melt() won’t work and contract features like issue() won’t work
An early user could issue a small amount of RToken and then melt almost all of it, pushing the basketsNeeded to supply ratio to its maximum allowed value. This would cause future issue() and melt() calls to revert, breaking core protocol functionality.
Originally disclosed on Code4rena
Submitted by unforgiven
https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/RToken.sol#L563-L573 https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/RToken.sol#L801-L814 https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/RToken.sol#L219 https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/Furnace.sol#L70-L84
Function melt() melt a quantity of RToken from the caller’s account, increasing the basket rate. basket rate should be between 1e9 and 1e27 and function requireValidBUExchangeRate() checks that if it’s not in interval the the code would revert. the call to requireValidBUExchangeRate() happens in the function mint(), melt() and setBasketsNeeded() which are used in issue() and handoutExcessAssets() and compromiseBasketsNeeded() which are used in multiple functionality of the systems. early malicious user can call issue(1e18) and melt(1e18 - 1) and then set the ratio between baskets needed and total supply to 1e27 and then any new action that increase the ratio would fail. because during the issue() code calls melt() so the issue() would fail for sure and other functionalities can increase the ratio because of the ratio too because of the rounding error which result in revert. so by exploiting this attacker can make RToken to be in broken state and most of the functionalities of the system would stop working.
Proof of Concept
This is melt() code:
function melt(uint256 amtRToken) external notPausedOrFrozen {
_burn(_msgSender(), amtRToken);
emit Melted(amtRToken);
requireValidBUExchangeRate();
}
As you can see it allows anyone to burn their RToken balance. This is requireValidBUExchangeRate() code:
function requireValidBUExchangeRate() private view {
uint256 supply = totalSupply();
if (supply == 0) return;
// Note: These are D18s, even though they are uint256s. This is because
// we cannot assume we stay inside our valid range here, as that is what
// we are checking in the first place
uint256 low = (FIX_ONE_256 * basketsNeeded) / supply; // D18{BU/rTok}
uint256 high = (FIX_ONE_256 * basketsNeeded + (supply - 1)) / supply; // D18{BU/rTok}
// 1e9 = FIX_ONE / 1e9; 1e27 = FIX_ONE * 1e9
require(uint192(low) >= 1e9 && uint192(high) <= 1e27, "BU rate out of range");
}
As you can see it checks and makes sure that the BU to RToken exchange rate to be in [1e-9, 1e9]. so Attacker can perform this steps:
- add
1e18RToken as first issuer by callingissue() - call
melt()and burn1e18 - 1of his RTokens. - not
basketsNeededwould be1e18andtotalSupply()of RTokens would be1and the BU to RToken exchange rate would be its maximum value1e27andrequireValidBUExchangeRate()won’t allow increasing the ratio. - now calls to
melt()would revert and becauseissue()calls tofurnace.melt()which callsRToken.melt()so all calls toissue()would revert. other functionality which result in callingmint(),melt()andsetBasketsNeeded()if they increase the ratio would fail too. as there is rounding error when converting RToken amount to basket amount so burning and minting new RTokens and increase the ratio too because of those rounding errors and those logics would revert. (handoutExcessAssets()would revert because it mint revenue RToken and updatebasketsNeededand it calculates new basket amount based on RToken amounts and rounds down so it would increase the BU to RToken ratio which cause code to revert inmint()) (redeem()would increase the ratio simillar tohandoutExcessAssets()because of rounding down) - the attacker doesn’t need to be first issuer just he needs to be one of the early issuers and by performing the attack and also if the ratio gets to higher value of the maximum allowed the protocol won’t work properly as it documented the supported rage for variables to work properly.
So attacker can make protocol logics to be broken and then RToken won’t be useless and attacker can perform this attack to any newly deployed RToken.
Tools Used
VIM
Recommended Mitigation Steps
Don’t allow everyone to melt their tokens or don’t allow melting if totalSupply() become very small.
tmattimore (Reserve) disagreed with severity and commented:
Understand that
issue()plusmelt()can brick an RTokens issuance, but redeem should still work.So, the RToken would no longer function as expected but no RToken holder funds would be lost. And in fact, RToken holders now have more funds.
Believe this is severity 2 but we should mitigate so that an annoying person / entity cannot DDOS every RToken on deployment w/ small amounts of capital. RToken holders can always continue to redeem though.
0xean (judge) decreased severity to Medium and commented:
Agreed on downgrading due to no direct loss of significant funds and this mostly being a griefing type attack.
This PR prevents melting RToken until the RToken supply is at least 1e18: reserve-protocol/protocol#619
Status: Not fully mitigated. Full details in reports from HollaDieWaldfee and 0xA5DF (here and here). Also included in Mitigation Review section below.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the melt() function allows burning tokens without a minimum supply check, enabling the basketsNeeded to supply ratio to reach its upper bound and then block any further increases.
Impact
The RToken would be in a broken state where issue() and melt() no longer work, but redeem() still works and no funds are lost; the attack is a griefing/denial-of-service that could be repeated on any newly deployed RToken.
What the attacker needed
Be an early issuer; small amount of capital
The fix
The protocol was mitigated by preventing melting RToken until the RToken supply is at least 1e18, but the mitigation was not fully effective.
How it was found
- Call issue() with 1e18 RToken as the first issuer.
- Call melt() and burn 1e18 - 1 of the RTokens.
- The basketsNeeded becomes 1e18 and totalSupply becomes 1, making the BU to RToken exchange rate reach its maximum value 1e27.
- Subsequent calls to melt() revert, and issue() also reverts because it calls furnace.melt() which calls RToken.melt().
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The protocol tracks a ratio between baskets needed and total token supply. A user could make this ratio hit its maximum by issuing tokens and then burning almost all of them. After that, any action that would increase the ratio further would fail, effectively breaking the token's issuance and melting functions.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.