Protection too expensive when some capital is locked
The leverage ratio is calculated as unlocked capital divided by total protections, so protections that have locked capital are counted twice: once by locking capital and again by increasing the denominator. This can make protection very expensive or impossible to buy even when the pool is well capitalised.
Source: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/208
Found by
jkoppel
Summary
The leverage ratio is computed as a ratio of unlocked capital to total protections. This means that each protection position which has locked capital is effectively counted twice: once to lock up capital, and once again to decrease the leverage ratio. This can lead to situations where a pool is very well capitalized to sell more protection, but cannot do so.
Vulnerability Detail
Consider: Pool has $1.1 million in deposits, and $1 million in protection positions. All pools have late payments, and so $1 million is locked. Pool now has $100k in unallocated deposits, but its leverage ratio is $100k/$1.1M ~ 0.09. Depending on the leverage floor, protection will either be really expensive or cannot be bought at all, even though the pool is well-capitalized.
Compare: If all pools defaulted and the $1M was lost, then the pool would have $100k in deposits and $0 in protection positions, and protection would be very cheap. The situation with locked capital should be treated similarly.
Impact
Protection is very expensive or impossible in some situations where it should be cheap.
Code Snippet
Note that lockCapital() decreases totalSTokenUnderlying but does not modify totalProtections. These are the two variables used to compute the leverage ratio. See https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L357
Tool used
Manual Review
Recommendation
Do not count protections which are locking up capital when computing the leverage ratio.
Discussion
vnadoda
@taisukemino Please review this issue and we can discuss it.
vnadoda
@clems4ev3r we plan to fix this issue
clems4ev3r
@vnadoda agreed this is valid. Active protections which have contributed to locking capital should not be accounted for in leverage ratio
vnadoda
@clems4ev3r PR for this issue: https://github.com/carapace-finance/credit-default-swaps-contracts/pull/70
clems4ev3r
Fix looks good
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 leverage ratio uses total protections as the denominator without excluding protections whose capital is already locked, so locked capital reduces the numerator while the related protection still inflates the denominator.
Impact
Protection could be very expensive or impossible to buy in situations where it should be cheap.
What the attacker needed
A pool with locked capital; protection positions with locked capital
The fix
The fix was to exclude active protections that have contributed to locking capital from the leverage ratio calculation.
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 pool sells protection (like insurance) and uses a leverage ratio to decide how much more it can safely sell. The ratio compares available money to the total protection sold. When some money is locked because of late payments, the protection that caused the lock is still counted in the total, so the ratio looks worse than it really is. That makes new protection look risky and expensive even though the pool still has plenty of money.
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.