Protection can be bought in late pools, allowing buyers to pay minimal premium and increase the chance of a compensation
The protocol caches pool statuses and only updates them periodically, so a buyer can purchase protection for a pool that is already late on a payment but still appears active. This lets the buyer pay a minimal premium and increase their chance of receiving a compensation.
rvierdiiev Follow with libratus, Jeiwan and 7 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/252
Found by
rvierdiiev, libratus, Jeiwan, ctf_sec, Kumpa, ast3ros, mahdikarimi, 0Kage, monrel, Allarious
Summary
A buyer can buy a protection for a pool that's already late on a payment. The buyer can pay the minimal premium and get a higher chance of getting a compensation. Protection sellers may bear higher losses due to reduced premium amounts and the increased chance of protection payments.
Vulnerability Detail
The protocol allows lenders on Goldfinch to get an insurance on the funds they lent. The insurance is paid after a repayment was late. The protocol doesn't allow protection buyers to buy protections for pools that's already late to disallow buyers abusing the protections payment mechanism. To do this, the _verifyLendingPoolIsActive function checks the current status of a pool and reverts if it's late.
However, poolStatus is cached and can be outdated when the function is called, since it's not updated in the call. Pool statuses are updated in assessStates and assessStateBatch, which are triggered on schedule separately. This allows buyers to buy protections in pools that's already late in Goldfinch but still active in Carapace.
Consider this scenario:
- A pool is in the active state after
assessStatesis run. - Before the next
assessStatescall, the pool gets into the late state, due to a missed repayment. However, in the protocol, the pool is still in the active state sinceassessStateshasn't been called. - The malicious buyer front runts the next
assessStatescall and submits their transactions that buys a protection with the minimal duration for the pool. The_verifyLendingPoolIsActivefunction passes because the pool's state hasn't been updated in the contracts yet. - The
assessStatescall changes the status of the pool toLateWithinGracePeriod, which disallows buying protections for the pool. - If the pool eventually gets into the default state (chances of that is higher since there's already a late payment), the malicious buyer will be eligible for a compensation.
Impact
Protection buyers can increase their chances of getting a compensation, while buying protections with the minimal duration and paying the minimal premium. Protection sellers will bear increased loses due to reduced premium amounts and the increased chance of a compensation.
Code Snippet
_verifyLendingPoolIsActivechecks the current status of a pool and reverts if it's not active:
ProtectionPoolHelper.sol#L412-L415
- Pool statuses are cached and are stored in
DefaultStateManager:
DefaultStateManager.sol#L278-L280
- Pool statuses are updated in
DefaultStateManager.assessStates:
DefaultStateManager.assessStatesis not called byProtectionPool.buyProtection:
Tool used
Manual Review
Recommendation
In ProtectionPoolHelper._verifyLendingPoolIsActive, consider calling DefaultStateManager._assessState to update the status of the pool for which a protection is bought.
Discussion
vnadoda
@clems4ev3r PR for this issue: https://github.com/carapace-finance/credit-default-swaps-contracts/pull/67
clems4ev3r
Fix #67 and #71 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
The pool status used to verify eligibility is cached and not refreshed during the purchase call, so it can be stale.
Impact
Protection buyers can increase their chances of getting a compensation while paying minimal premium, and protection sellers may bear higher losses.
What the attacker needed
A late payment on the pool; ability to front-run the assessStates call
The fix
The protocol should update the pool status by calling the state assessment function before verifying eligibility in the protection purchase flow.
How it was found
- A pool is in the active state after assessStates is run.
- Before the next assessStates call, the pool becomes late due to a missed repayment, but the protocol still shows it as active.
- The malicious buyer front runs the next assessStates call and buys a protection with minimal duration for the pool.
- The _verifyLendingPoolIsActive function passes because the pool's state hasn't been updated yet.
- The assessStates call changes the pool status to LateWithinGracePeriod, disallowing further protection purchases.
- If the pool eventually defaults, the malicious buyer is eligible for compensation.
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.
This is a smart contract insurance protocol where lenders can buy protection against borrower defaults. The pool's status (active or late) is stored on-chain but only refreshed by a separate scheduled function, so it can be out of date. An attacker can buy cheap insurance just before the status is updated, when the pool is already late but still looks active.
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.