Redemptions during undercollateralization can be hot-swapped to steal all funds
During undercollateralization or a basket switch, a redemption transaction can be front-run by an attacker who calls refreshBasket, causing the redemption to be partial and the redeemer to lose most of their funds. The attacker can also inflate the RToken supply to bypass redemption limits and then redeem for dust.
Submitted by Cyfrin, also found by Cyfrin
During recollateralization/a switch basket/when the protocol collateral isn’t sound, a user can have almost their entire redemption transaction hot swapped for nothing.
For example, trying to redeem 1M collateral for 1M rTokens could have the user end up with 0 collateral and 0 rTokens, just by calling the redeem function at the wrong time.
Example:
- User A issues 1M rToken for 1M tokenA
- Evil user sees tokenA is about to become disabled, and that User A sent a normally innocuous redeem tx for too much underlying collateral in the mempool
- Evil user orders transactions so they and RSR/Rtoken holders can steal user A’s funds
- They first buy a ton of tokenA and send it to the backing Manager
- They call
manageTokenswhich flash issues a ton of new Rtoken due to the inflated tokenA balance, increasing the totalSupply - The increase in total supply allows the normal redemption cap to be drastically lifted
- They then let the disabling of tokenA process, and calls refreshBasket where a backup token (tokenB) kicks in
- We are now undercollateralized, and evil user sends tokenB dust to the backingmanager
- FINALLY: the original redemption TX is ordered, and due to the inflated RToken supply, the battery discharge amount is also inflated, allowing the redemption to go through. Due to the new collateral in place, they redeem ALL their Rtoken (1M) for dust of tokenB!! The protocol has essentially honeypotted them!!
Proof of Concept
We provide the proof of code in proof of code section.
- MEV
This relies on a validator being malicious with for-profit motives. It would be pretty easy for them to setup a bot looking for this exact scenario though and just staying dormant till the time is right. If they get to order the transactions, they can make a fat profit from the victim.
- Backing manager can flash issue RToken
If the backingManger has too many excess assets, it will flash issue as many RTokens as possible to even the collateral to RTokens.
function handoutExcessAssets(IERC20[] calldata erc20s) private {
.
.
if (held.gt(needed)) {
.
.
rToken.mint(address(this), uint256(rTok));
- Increasing the supply increases the redemption and issuance block cap
The RedemptionBattery’s currentCharge function is dependent on the total supply of RTokens. So if the total supply is raised, you can redeem way more than you should be able to.
uint256 amtPerHour = (supply * battery.scalingRedemptionRate) / FIX_ONE_256;
(This also is true for issuance.)
- Anyone can call refreshBasket when a collateral is disabled
function refreshBasket() external {
assetRegistry.refresh();
require(
main.hasRole(OWNER, _msgSender()) ||
(status() == CollateralStatus.DISABLED && !main.pausedOrFrozen()),
"basket unrefreshable"
);
_switchBasket();
}
So if I see a tx where a collateral is about to be disabled, I can chain it with the refreshbasket TX myself.
- Redemptions can occur when protocol is undercollateralized
The redeem function has this check:
require(basketHandler.status() != CollateralStatus.DISABLED, "collateral default");
Which checks if the collateral is good, but NOT if the protocol is fullyCollateralized. Since we chain the disabled asset with the refreshBasket TX, the backup collateral kicks in, and the collateral status becomes SOUND. However, normally, we’d have 0 of the new collateral and any redemptions would fail, since there isn’t anything to give back.
- Sending dust to backing manager
So, if you send a tiny tiny bit of the new collateral to the protocol, the protocol will process the redemption and give them their prorata share of the collateral, which right now is almost 0, but still burn all the rToken being redeemed.
// amount is never changed, they burn all the rToken
// in our example above, all 1M Rtoken are burned!
_burn(redeemer, amount);
And we calculate how much they get back like so. We see how much $ we currently have in the basket, and hand back those amounts accordingly. Since we have almost no money, we are going to give them almost nothing for their rTokens.
(address[] memory erc20s, uint256[] memory amounts) = basketHandler.quote(baskets, FLOOR);
uint256 erc20length = erc20s.length;
// Bound each withdrawal by the prorata share, in case we're currently under-collateralized
for (uint256 i = 0; i < erc20length; ++i) {
// {qTok}
uint256 bal = IERC20Upgradeable(erc20s[i]).balanceOf(address(backingManager));
// gas-optimization: only do the full mulDiv256 if prorate is 0
uint256 prorata = (prorate > 0)
? (prorate * bal) / FIX_ONE // {qTok} = D18{1} * {qTok} / D18
: mulDiv256(bal, amount, supply); // {qTok} = {qTok} * {qRTok} / {qRTok}
if (prorata < amounts[i]) amounts[i] = prorata;
}
And just like that, a seemingly innocuous redemption transaction was a trap the whole time. The next step would be to go through the rest of the process to see how much our evil user profited (from running the auctions), as they need to be a whale to inflate the RToken supply. However, we’ve seen attacks like this, and one could consider it a highly profitable trading strategy. If they buy up majority shares in the RToken, or, they coordinate with most of the StRSR token holders they could advertise and honey pot people to do redemptions whenever a switchBasket is coming. Spread FUD like “you need to redeem otherwise you’ll lose money!” and it’s the redeeming that actually steals their money.
Tools Used
Hardhat
Recommended Mitigation Steps
Disallow issuance/redemptions while the protocol is undercollateralized.
Proof Of Code
See warden’s original submission for full details.
0xean (judge) decreased severity to Medium and commented:
Certainly a creative attack vector, will leave open for sponsor review. I am unclear on a few nuances of the attack here, but ultimately would like the sponsor to comment.
Downgrading to Medium for the moment due to a very particular sequence of events being required for this to be executed.
tbrent (Reserve) confirmed and commented:
The bug is simpler than the description. If the basket is DISABLED, then all that needs to happen is for a redeem tx to be in the mempool. An MEV searcher can order a
refreshBasket()call earlier in the block, causing the redemption to be partial. This acts as a net transfer between the RToken redeemer and RSR stakers, who will eventually collect the money.
This PR allows an RToken redeemer to specify when they require full redemptions vs accept partial (prorata) redemptions. reserve-protocol/protocol#615
Status: Not fully mitigated. Full details in reports from 0xA5DF, HollaDieWaldfee, and AkshaySrivastav. 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 redemption logic allows partial redemptions when the basket is disabled or undercollateralized, and the redemption limit depends on total supply which can be inflated.
Impact
A redeemer could lose almost all their funds, and the attacker could steal value from them, though the attack requires a specific sequence of events and a malicious validator or MEV searcher.
What the attacker needed
Redeem transaction in mempool; basket is disabled or undercollateralized; attacker can order transactions (MEV)
The fix
The fix allows a redeemer to specify whether they require full redemptions or accept partial redemptions, but it was not fully mitigated.
How it was found
- Attacker sees a redeem transaction in the mempool while the basket is about to be disabled.
- Attacker orders a refreshBasket call before the redeem transaction.
- The refreshBasket switches to a backup basket, making the protocol undercollateralized.
- The redeem transaction executes, but due to the undercollateralization, the redeemer receives only a tiny amount of the new collateral.
- Attacker may also inflate the RToken supply by sending tokens to the backing manager and calling manageTokens, which increases the redemption cap.
- Attacker then redeems their inflated RToken supply for dust, stealing funds.
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.
When a user tries to redeem their tokens for collateral, an attacker can reorder transactions so that the redemption happens at a bad moment. The user ends up with almost nothing while the attacker profits from the difference.
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.