BackingManager: rTokens might not be redeemable when protocol is paused due to missing token allowance
The BackingManager's grantRTokenAllowance function is blocked when the protocol is paused, but RToken redemption is supposed to remain available during a pause. If no allowance was granted before the pause, users cannot redeem their rTokens for that ERC20 until the protocol is unpaused.
HollaDieWaldfee Follow with unforgiven
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee, also found by unforgiven
https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/RToken.sol#L439-L514 https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/BackingManager.sol#L72-L77
The Reserve protocol allows redemption of rToken even when the protocol is paused.
The docs/system-design.md documentation describes the paused state as:
all interactions disabled EXCEPT RToken.redeem + RToken.cancel + ERC20 functions + StRSR.stake
Redemption of rToken should only ever be prohibited when the protocol is in the frozen state.
The issue is that the RToken.redeem function (https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/RToken.sol#L439-L514) relies on the BackingManager.grantRTokenAllowance function (https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/BackingManager.sol#L72-L77) to be called before redemption.
Also the only function that relies on BackingManager.grantRTokenAllowance to be called before is RToken.redeem.
Therefore BackingManager.grantRTokenAllowance can be called at any time before a specific ERC20 needs first be transferred from the BackingManager for the purpose of redemption of rToken.
The issue is that the BackingManager.grantRTokenAllowance function has the notPausedOrFrozen modifier. This means it cannot (in contrast to RToken.redeem) be called when the protocol is paused.
Therefore if rToken is for the first time redeemed for a specific ERC20 in a paused protocol state, BackingManager.grantRTokenAllowance might not have been called before.
This effectively disables redemption of rToken as long as the protocol is paused and is clearly against the usability / economic considerations to allow redemption in the paused state.
Proof of Concept
For simplicity assume there is an rToken backed by a single ERC20 called AToken
- rToken is issued and AToken is transferred to the
BackingManager. - The protocol goes into the
pausedstate before any redemptions have occurred. So theBackingManager.grantRTokenAllowancefunction might not have been called at this point. - Now the protocol is
pausedwhich should allow redemption of rToken but it is not possible because the AToken allowance cannot be granted since theBackingManager.grantRTokenAllowancefunction cannot be called in thepausedstate.
Another scenario is when the basket of a RToken is changed to include an ERC20 that was not included in the basket before. If the protocol now goes into the paused state without BackingManager.grantRTokenAllowance being called before, redemption is not possible.
Tools Used
VSCode
Recommended Mitigation Steps
The BackingManager.grantRTokenAllowance function should use the notFrozen modifier instead of the notPausedOrFrozen modifier such that allowance can be granted in the paused state:
diff --git a/contracts/p1/BackingManager.sol b/contracts/p1/BackingManager.sol
index 431e0796..7dfa29e9 100644
--- a/contracts/p1/BackingManager.sol
+++ b/contracts/p1/BackingManager.sol
@@ -69,7 +69,7 @@ contract BackingManagerP1 is TradingP1, IBackingManager {
// checks: erc20 in assetRegistry
// action: set allowance on erc20 for rToken to UINT_MAX
// Using two safeApprove calls instead of safeIncreaseAllowance to support USDT
- function grantRTokenAllowance(IERC20 erc20) external notPausedOrFrozen {
+ function grantRTokenAllowance(IERC20 erc20) external notFrozen {
require(assetRegistry.isRegistered(erc20), "erc20 unregistered");
// == Interaction ==
IERC20Upgradeable(address(erc20)).safeApprove(address(main.rToken()), 0);
I think the warden does identify a possible state of the system that could be problematic, albeit highly unlikely to be realized. Leaving open for sponsor review.
Addressed here: https://github.com/reserve-protocol/protocol/pull/584
Status: Mitigation confirmed. Full details in reports from HollaDieWaldfee, 0xA5DF, and AkshaySrivastav.
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
The grantRTokenAllowance function uses a notPausedOrFrozen modifier, while redemption is meant to work while paused, so the required allowance may never be set during a pause.
What the attacker needed
Protocol is paused; no prior allowance granted for that ERC20; user wants to redeem rToken
The fix
The grantRTokenAllowance function should use the notFrozen modifier instead of notPausedOrFrozen so allowance can be granted while paused; the project addressed this in a pull request and the mitigation was confirmed.
How it was found
- rToken is issued and the underlying ERC20 (AToken) is transferred to the BackingManager.
- The protocol enters the paused state before any redemptions have occurred, so grantRTokenAllowance may not have been called.
- A user tries to redeem rToken while paused, but the AToken allowance cannot be granted because grantRTokenAllowance cannot be called in the paused state.
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.
In this system, users can normally swap their rTokens back for the underlying tokens even when the protocol is paused. But the contract that approves those underlying tokens for transfer is itself blocked during a pause. So if that approval was never done before the pause, users are stuck and cannot redeem.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.