Skip to content
DoS Audit finding Intermediate

Custom redemption might revert if old assets were unregistered

The custom redemption function assumes the number of assets in a basket never exceeds the current asset registry size, but an old basket can contain an unregistered asset, causing an index out-of-bounds revert. This could temporarily prevent users from redeeming their tokens.

0xA5DF Follow

Originally disclosed on Code4rena

Submitted by 0xA5DF

quoteCustomRedemption() works under the assumption that the maximum size of the erc20sAll should be assetRegistry.size(), however there can be cases where an asset was unregistered but still exists in an old basket, making the size of the old basket greater than assetRegistry.size(). In that case the function will revert with an index out of bounds error.

Impact

Users might not be able to use redeemCustom when needed.

I think this should be considered high severity, since being able to redeem the token at all time is an essential feature for the protocol that’s allowed also while frozen. Not being able to redeem can result in a depeg or in governance becoming malicious and stealing RToken collateral.

Proof of Concept

Consider the following scenario:

  • RToken deployed with 0.9 USDC, 0.05 USDT, 0.05 DAI
  • Governance passed a vote to change it to 0.9 DAI and 0.1 USDC and un-register USDT
  • Trading is paused before execution, so the basket switch occurs but the re-balance can’t be executed. Meaning the actual assets that the backing manager holds are in accordance with the old basket
  • A user wants to redeem using the old basket, but custom redemption reverts

As for the revert:

  • erc20sAll is created here with the length of assetRegistry.size(), which is 2 in our case.
  • Then in this loop the function tries to push 3 assets into erc20sAll which will result in an index-out-of-bonds error

(the function doesn’t include in the final results assets that aren’t registered, but it does push them too into erc20sAll)

Recommended Mitigation Steps

Allow the user to specify the length of the array erc20sAll to avoid this revert

0xean (judge) commented:

I believe this to be a stretch for high severity. It has several pre-conditions to end up in the proposed state and I do believe it would be entirely possible for governance to change back to the original state (USDC, USDT, DAI), so assets wouldn’t be lost and the impact would more be along the lines of a temporary denial of service.

Look forward to warden and sponsor comments.

tbrent (Reserve) confirmed and commented:

@0xA5DF - nice find! Thoughts on an alternative mitigation?

  • Could move L438 to just after L417, so that erc20sAll never includes unregistered ERC20s
  • Would probably have to cache the assets as assetsAll for re-use around L438
  • Has side-effect of making the ERC20 return list never include unregistered ERC20s. Current implementation can return a 0 value for an unregistered ERC20. This is properly handled by the RToken contract, but still, nice-to-have.

0xA5DF (warden) commented:

Hey @tbrent - That can work as well, the only downside I can think of is that in case there’s an asset that’s not registered and is repeated across different baskets - the toAsset() would be called multiple times for that asset (while under the current implementation and under the mitigation I’ve suggested it’ll be called only once), this would cost about 300 gas units per additional call (100 for the call, 2 sloads to a warm slot inside the call itself)

tbrent (Reserve) commented:

@0xA5DF - Noted, good point.

tbrent (Reserve) confirmed

0xean (judge) commented:

@tbrent - do you care to comment on your thoughts on severity? I am leaning towards M on this, but it sounds like you believe it is correct as labeled (high).

tbrent (Reserve) commented:

@0xean - Correct, I think high is appropriate.

Reserve mitigated:

Fix redeemCustom. PR: https://github.com/reserve-protocol/protocol/pull/857

Status: Mitigation confirmed. Full details in reports from ronnyx2017, 0xA5DF, and rvierdiiev - and also shared below in the Mitigation Review section.


The original report as published on Code4rena, by 0xA5DF. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Impact

Users might temporarily be unable to redeem their tokens, which could lead to a depeg or governance abuse, though the judge noted it is more of a temporary denial of service.

What the attacker needed

An asset was unregistered but still in an old basket; trading paused so rebalancing cannot occur; user attempts custom redemption

The fix

The issue was mitigated by adjusting the code so that unregistered assets are not included in the array, as confirmed in the mitigation review.

How it was found

  1. Deploy an RToken with a basket containing three assets, one of which is later unregistered.
  2. Governance votes to change the basket and unregister one asset.
  3. Trading is paused so the basket switch occurs but rebalancing cannot execute, leaving the old basket assets in place.
  4. A user attempts a custom redemption using the old basket, which reverts due to the array size mismatch.

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.

A smart contract lets users redeem tokens for a mix of underlying assets. The code that builds the list of assets to return uses a fixed-size array based on how many assets are currently registered. If an asset was removed from the registry but still appears in an older basket, the code tries to add more items than the array can hold, so the whole redemption fails.

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.

More by 0xA5DF

View all

35 more disclosed reports, best first.

More from Reserve Core

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.