Skip to content
Business logic Audit finding Intermediate

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:

  1. A pool is in the active state after assessStates is run.
  2. Before the next assessStates call, the pool gets into the late state, due to a missed repayment. However, in the protocol, the pool is still in the active state since assessStates hasn't been called.
  3. The malicious buyer front runts the next assessStates call and submits their transactions that buys a protection with the minimal duration for the pool. The _verifyLendingPoolIsActive function passes because the pool's state hasn't been updated in the contracts yet.
  4. The assessStates call changes the status of the pool to LateWithinGracePeriod, which disallows buying protections for the pool.
  5. 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

  1. _verifyLendingPoolIsActive checks the current status of a pool and reverts if it's not active:

ProtectionPoolHelper.sol#L412-L415

  1. Pool statuses are cached and are stored in DefaultStateManager:

DefaultStateManager.sol#L278-L280

  1. Pool statuses are updated in DefaultStateManager.assessStates:

DefaultStateManager.sol#L119

  1. DefaultStateManager.assessStates is not called by ProtectionPool.buyProtection:

ProtectionPool.sol#L162

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

The original report as published on Sherlock, by rvierdiiev. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. A pool is in the active state after assessStates is run.
  2. Before the next assessStates call, the pool becomes late due to a missed repayment, but the protocol still shows it as active.
  3. The malicious buyer front runs the next assessStates call and buys a protection with minimal duration for the pool.
  4. The _verifyLendingPoolIsActive function passes because the pool's state hasn't been updated yet.
  5. The assessStates call changes the pool status to LateWithinGracePeriod, disallowing further protection purchases.
  6. 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.

More by rvierdiiev

View all

72 more disclosed reports, best first.

More from Carapace

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.