Freezing of the protocol when totalSTokenUnderlying is zero but totalSupply is non-zero
When all capital is locked, the pool's total underlying becomes zero while the total supply of STokens remains non-zero. This causes new deposits and protection purchases to revert, halting the protocol until all STokens are burned.
Source: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/117
Found by
chaduke, mert_eren, Kumpa, Web3SecurityDAO, clems4ever, jprod15, Ruhum, Bauer
Summary
In some cases the protocol can contain zero funds while having a non zero totalSupply of STokens. In that case the protocol will not be able to accept any new deposits and any new protection buys, thus coming to a halt, unless all STokens are burned by their respective holders.
Vulnerability Detail
In the case lockCapital has to lock all available capital:
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L415-L419
totalSTokenUnderlying becomes zero, but totalSupply is still non-zero since no SToken have been burned.
Which means that new deposits will revert because _getExchangeRate() is zero:
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L602-L605
And convertToSToken tries to divide by _getExchangeRate();
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L602-L605
Also all new protection buying attempts will revert because _leverageRatio is zero, and thus under leverageRatioFloor.
Impact
The protocol comes to a halt, unless every SToken holder burn their shares by calling withdraw after enough cycles have passed, returning to the case totalSupply == 0.
Code Snippet
Tool used
Manual Review
Recommendation
Keep a minimum amount of totalSTokenUnderlying in the contract in any case (can be 1e6).
Discussion
vnadoda
@clems4ev3r we plan to fix this
vnadoda
@clems4ev3r As we have discussed, keeping the dust amount won't help with the situation when totalSTokenUnderlying is zero or tends to zero.
We have decided that for v1, we have to make a protection pool non-operational and deploy a new protection pool, if this situation arises.
A non-operational protection pool means nobody can buy/renew protections or deposit into the pool.
I have verified that when totalSTokenUnderlying is zero or tends to zero, because of the leverage ratio check nobody will be able to buy/renew protections plus the deposit fails because of the exchange rate being 0.
This means, there is no code change required for this issue.
@hrishibhat @clems4ev3r Let me know if you have any questions/concerns.
We will implement a "liquidation" process in the upcoming version to wind down the dead pool.
jacksanford1
No code change planned, labeling as Acknowledged by protocol team
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
Root cause
Likely the exchange rate calculation divides by totalSTokenUnderlying without handling the case where it is zero while totalSupply is non-zero.
Impact
The protocol comes to a halt: deposits and protection purchases revert until all SToken holders withdraw and burn their shares.
What the attacker needed
LockCapital locks all available capital; totalSTokenUnderlying becomes zero; totalSupply remains non-zero
The fix
The protocol team decided no code change is required for v1; they will make the pool non-operational and deploy a new one if this occurs, with a liquidation process planned for a future version.
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 protection pool holds money and gives out shares called STokens. If all the money is locked away, the pool's share price calculation divides by zero, so no one can add money or buy protection. The pool stops working until every share holder withdraws and burns their shares.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.