Growing of totalSupply after successive lock/unlockCapital can freeze protection pools by uint overflow
The protection pool's share price can become extremely small after capital is locked, so each new deposit mints a huge number of shares and totalSupply grows exponentially. Eventually the exchange rate can round to zero, blocking all new deposits and halting the pool.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/118
Found by
clems4ever
Summary
In a protection pool, after enough cycles of locking capital/depositing, totalSupply can grow to overflow uint256.
Vulnerability Detail
In convertToSToken:
https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L589-L606
_getExchangeRate() can become arbitrarily small after a funds locking, since locked funds are substracted from totalSTokenUnderlying;
This means that new depositors can get a lot more shares than depositors from before funds locking.
This behavior is correct, because otherwise previous depositors would have an oversized share of the new capital. However this has the negative effect of growing totalSupply exponentially, eventually reaching type(uint).max and overflowing (reverting every new deposit).
Impact
Protocol can come to a halt if totalSupply reaches type(uint).max.
Code Snippet
Tool used
Manual Review
Recommendation
Design the token in a way that it can be rebased regularly.
Discussion
vnadoda
@clems4ev3r Technically it is possible but I don't think this can happen in practice. Cc @taisukemino
clems4ev3r
@vnadoda actually the risk here is to have _getExchangeRate() == 0 after a few lock events.
If the protection pool contains 1M USDC (10**12), and a locking event leaves a dust amount in the pool (let's say 1 wei),
next deposits for 1M USDC will multiply totalSupply by 10**12.
This means that after a few such events, and for a reasonable amount of underlying in the pool _getExchangeRate() == 0 and all deposits to the pool are blocked.
Agreed that was not clearly stated in the original report. And it technically should not overflow uint.
vnadoda
@clems4ev3r the scenario you described is same as #117, right?
vnadoda
@clems4ev3r can we close this as a duplicate of #117?
clems4ev3r
@vnadoda not exactly the same since this will happen if some funds stay in the contract after locking. Each time a lock happens, depositing back capital will multiply totalSupply by a factor proportional to the locking, eventually forcing _getExchangeRate() to zero and blocking deposits for the ProtectionPool
vnadoda
@clems4ev3r lets' discuss this on the call
vnadoda
@hrishibhat we are planning to fix this
vnadoda
@clems4ev3r @hrishibhat there is no code change for this issue. Please see my comment: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/117#issuecomment-1485956386
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 share exchange rate is recalculated after locked funds are subtracted from the pool's underlying total, so repeated lock events drive the rate towards zero and cause share minting to explode.
Impact
The protocol could halt because totalSupply may reach its maximum and every new deposit reverts; the reporter later clarified that the practical risk is the exchange rate reaching zero and blocking deposits.
What the attacker needed
A protection pool with depositors; repeated lock events leaving dust; new deposits after each lock
The fix
The token should be designed so it can be rebased regularly, though the protocol team stated no code change was planned.
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 gives depositors shares in exchange for their money. The share price is total money divided by total shares. When some money is locked away, the remaining money is small, so the share price drops. New depositors then get many more shares for the same money. Repeating this makes the total number of shares grow very fast until the share price becomes zero, and no one can deposit any more.
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.