Closed c4-bot-2 closed 3 months ago
requires same erc20s with different target names, this relies on governance misconfiguration, invalid
thereksfour marked the issue as unsatisfactory: Invalid
Hi @thereksfour , @tbrent , @akshatmittal , Thanks for your review.
This is not a governance misconfiguration.
There could be a case where a switch is made to another collateral
that shares the same erc20
token but has a different targetName
.
This means that the two collaterals
are based on the same erc20
token, but one tracks USD
while the other tracks a different currency.
When this happens, an incorrect basket
will be created, as I described.
I would appreciate it if you could reconsider this issue.
My answer to your question was on a technical basis, purely.
If it causes issues, that is a governance misconfiguration.
It is not always an issue. It's actually necessary in at least one case: when adding management fee to an ERC20. In this case the plugin is changed so that the targetName encodes (i) the base unit, such as USD
; (ii) the interest rate, such as 1%
; and (iii) t_0
, the time the fee should be applied from. Then the prime basket is changed (must be reweightable RToken) to target this unit.
(we call that concept demurrage collateral, internally, there is some historical discussion in the repo though we are not pushing it currently)
agree! thanks
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/BasketHandler.sol#L268 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/AssetRegistry.sol#L99 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/mixins/BasketLib.sol#L303 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/mixins/BasketLib.sol#L253
Vulnerability details
Impact
In the
AssetRegistry
, it is possible to swap a registeredasset
for another. If theasset
being swapped is part of the currentbasket
, we need to switch to a newbasket
. While these twoassets
share the sameerc20
, they may have differenttarget names
, which can result in the creation of an incorrectbasket
.Although we can immediately switch to a correct
basket
afterward, the presence of the wrongbasket
can negatively impact futurecustom redemptions
.Proof of Concept
Suppose
asset A
is currently in thebasket
, and we want to swap it with a newasset B
. Bothassets
share the sameerc20
, but they have differenttarget names
—Ta
forA
andTb
forB
. (This is possible) SinceA
is being removed from thebasket
, we need to switch to a newbasket
. However, becauseB
has a differenttarget name
, theprime basket
for the nextbasket
should be different. We cannot set theprime basket
for the newbasket
before swappingA
withB
, asA
'starget name
is still in use (line 268
).The correct steps are:
A
withB
using theswapRegistered
function.prime basket
. At this point, thetarget name Tb
forasset B
will be registered.basket
.This sequence ensures that everything functions correctly.
However, if someone calls the
refreshBasket
function beforestep 2
, the oldprime basket
will be used for the newbasket
, incorrectly retainingA
'starget name, Ta
. Theasset A
is not agood collateral
becauseasset B
is now registered for this erc20 in theAssetRegistry
, it returnsTb
as thetarget name
(line 303
).This mismatch means that other tokens with
target name Ta
will be used to backasset A
, creating an invalidbasket
(line 253
).Although the owner can later complete
steps 2
and3
to switch to a new, correctbasket
with the propertarget name Tb
, any oldbaskets
in a system wherereweightable
isfalse
will permanently affectcustom redemptions
, as we cannot increaselastCollateralized
(line 187
).Therefore, it is crucial to prevent the creation of incorrect
baskets
by mistake. (Clearly, no one wants to create this temporarybasket
.)Tools Used
Recommended Mitigation Steps
At this point, the
refreshBasket
function can be called at any time by theowner
. Alternatively, anyone can call this function when thebasket
is disabled. However, there is no need to allow anyone to call this function. Theowner
should also be able to call it when thebasket
is disabled. In summary, restrict the ability to call this function to only theowner
.Assessed type
Access Control