Submitted by 0xA5DF, also found by HollaDieWaldfee
The BackingManager.manageTokens() function checks if theres any deficit in collateral, in case there is, if theres a surplus from another collateral token it trades it to cover the deficit, otherwise it goes for a haircut and cuts the amount of basket needed (i.e. the number of baskets RToken claims to hold).
In order to determine how much deficit/surplus there is the protocol calculates the basket range, where the top range is the optimistic estimation of the number of baskets the token would hold after trading and the bottom range is a pessimistic estimation.
The estimation is done by dividing the total collateral value by the price of 1  basket unit (for optimistic estimation the max value is divided by min price of basket-unit and vice versa).
The problem is that this estimation is inefficient, for cases where just a little bit of collateral is missing the range band (range.top - range.bottom) would be about 4% (when oracle error deviation is 1%) instead of less than 1%.
This can cause the protocol an unnecessary haircut of a few percent where the deficit can be solved by simple trading.
This would also cause the price of RTokenAsset to deviate more than necessary before the haircut.
In the following PoC, the basket changed so that it has 99% of the required collateral for 3 tokens and 95% for the 4th.
The basket range should be 980.03% (the basket has 95% collateral + 4% of 3/4 tokens. That 4% is worth 30.03% if we account for oracle error of their prices), but in reality the protocol calculates it as ~97.92%.
That range causes the protocol to avoid trading and go to an unnecessary haircut to ~95%
Output (comments are added by me):
Change the formula so that we first calculate the base (i.e. the min amount of baskets the RToken can satisfy without trading):
0xean (judge) commented:
tmattimore (Reserve) acknowledged
tbrent (Reserve) commented:
0xean (judge) commented:
tbrent (Reserve) confirmed and commented:
tbrent (Reserve) mitigated:
Status: Not fully mitigated. Full details in report from 0xA5DF, and also included in Mitigation Review section below.
