Skip to content
DoS Audit finding Advanced

Shortfall might be calculated incorrectly if a price value for one collateral isn’t fetched correctly

severity Follow

Originally disclosed on Code4rena

Submitted by severity

Function price() of an asset doesn’t revert. It returns values (0, FIX_MAX) for low, high values of price in case there’s a problem with fetching it. Code that calls price() is able to validate returned values to detect that returned price is incorrect.

Inside function collateralShortfall() of RecollateralizationLibP1 collateral price isn’t checked for correctness. As a result incorrect value of shortfall might be calculated if there are difficulties to fetch a price for one of the collaterals.

Proof of Concept

https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/mixins/RecollateralizationLib.sol#L449

Recommended Mitigation Steps

Check that price is correctly fetched for a collateral.

0xean (judge) commented:

Mitigation here is a little challenging to understand considering checking a price is hard on chain and hence the concern.

I think this issue is a bit too general, but would like further comments.

tbrent (Reserve) acknowledged and commented:

I think this issue is real, but it happens in a super-corner-case that I doubt the warden is thinking about.

Some related statements:

  • prepareRecollateralizationTrade checks that all collateral in the basket is SOUND before calling collateralShortfall
  • From docs/collateral.md: “Should return (0, FIX_MAX) if pricing data is unavailable or stale.”

collateralShortfall should never reach a collateral with FIX_MAX high price in the normal flow of things.

But, it is possible for one RToken system instance to have an RTokenAsset registered for a 2nd RToken. In this case, it could be that RToken 2 contains a collateral plugin that is now connected to a broken oracle, but RToken 2 may not have recognized this yet. When RToken 1 calls RTokenAsset.price(), it could end up reverting because of overflow in this line from collateralShortfall:

shortfall = shortfall.plus(needed.minus(held).mul(priceHigh, CEIL));

So I think it’s a real issue, and I would even leave it as Medium severity.

tbrent (Reserve) mitigated:

This PR simplifies and improves the basket range formula. The new logic should provide much tighter basket range estimates and result in smaller haircuts. reserve-protocol/protocol#585

Status: Mitigation confirmed with comments. Full details in reports from HollaDieWaldfee, 0xA5DF, and AkshaySrivastav.


The original report as published on Code4rena, by severity. 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.

What is known

A medium-severity doS bug in Reserve Core. Code4rena made it public on 27 April 2023. Found in the 2023-01-reserve audit contest (finding M-20).

About DoS

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 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.