Closed c4-bot-1 closed 3 months ago
The refPerTok value can not be 0. See: https://github.com/reserve-protocol/protocol/blob/master/docs/solidity-style.md#rates
thereksfour marked the issue as unsatisfactory: Invalid
Hi @thereksfour , @tbrent , @akshatmittal , Thanks for your review.
First, I asked about this in Discord, and tbrent | Reserve
confirmed that refPerTok
can indeed be 0
.
The link provided above (https://github.com/reserve-protocol/protocol/blob/master/docs/solidity-style.md#rates)
is related to tokens that are in a SOUND
status.
However, my concern is with tokens that have been disabled for various reasons.
Once tokens are disabled, the owner may decide to unregister
them.
Until they are unregistered
, these tokens should not impact the protocol
, but they still can.
Additionally, unregistering
these tokens can accidentally disable
the basket
, which is critical to the protocol's functionality.
Recollateralization
and basket disabling
are among the most crucial aspects of this protocol
.
I would appreciate it if you could reconsider this issue.
thanks
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/BasketHandler.sol#L397 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/AssetRegistry.sol#L112 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/BackingManager.sol#L121
Vulnerability details
Impact
Assets
are registered in theAssetRegistry
, and some of them may be part of the currentbasket
. When we unregister a token that is in thebasket
, the currentbasket
should be disabled, and switch to a newbasket
. After switching, there is awarm-up period
during which certain critical operations, likerecollateralization
in theBackingManager
, cannot be performed. Therefore, it’s important to disable thebasket
carefully. However, we mistakenly disable thebasket
when unregistering a token that is not part of it and the newbasket
will be identical to the current one, potentially causing unnecessary disruptions. Clearly, there's no need to disable thebasket
when unregistering a token that is not in the currentbasket
.Proof of Concept
At this point, we determine whether a token is in the current
basket
by checking its quantity within thebasket
. If the token is in thebasket
, therefAmts
for it will not be0
so the quantity will also be0
(line 400
). It's necessary to disable thebasket
if the quantity is non-zero.However, the
_quantity
function can also return a non-zero value (FIX_MAX
) when therefPerTok
is0
(line 397
).This means that even if the token is not in the current
basket
, thequantity
function might return a non-zero value, causing us to mistakenly disable thebasket
(line 113
).While it's possible to switch to a new
basket
immediately, this step is unnecessary because the newbasket
will be identical to the current one. Moreover, important operations likerecollateralization
andforwardRevenue
distribution cannot be performed during thewarm-up
period that follows abasket
switch (line121
).Please add below test to the
test/Main.test.ts
.Tools Used
Recommended Mitigation Steps
The
basket
should not be disabled when unregistering a token with a quantity ofFIX_MAX
if it is not in the currentbasket
.Assessed type
Invalid Validation