Skip to content
Business logic Audit finding Intermediate

Existing buyer who has been regularly renewing protection will be denied renewal even when she is well within the renewal grace period

The renewal function for existing protection buyers calls a check that rejects any lending pool not in the Active state, so a buyer is denied renewal if the pool becomes LateWithinGracePeriod just after their protection expires, even though they are within the grace period. This means a buyer who has paid premiums can lose all protection exactly when a default risk first appears.

0Kage Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-carapace-judging/issues/174

Found by

0Kage

Summary

Existing buyers have an opportunity to renew their protection within grace period. If lending state update happens from Active to LateWithinGracePeriod just 1 second after a buyer's protection expires, protocol denies buyer an opportunity even when she is well within the grace period.

Since defaults are not sudden and an Active loan first transitions into LateWithinGracePeriod, it is unfair to deny an existing buyer an opportunity to renew (its alright if a new protection buyer is DOSed). This is especially so because a late loan can become active again in future (or move to default, but both possibilities exist at this stage).

All previous protection payments are a total loss for a buyer when she is denied a legitimate renewal request at the first sign of danger.

Vulnerability Detail

renewProtection first calls verifyBuyerCanRenewProtection that checks if the user requesting renewal holds same NFT id on same lending pool address & that the current request is within grace period defined by protocol.

Once successfully verified, renewProtection calls _verifyAndCreateProtection to renew protection. This is the same function that gets called when a new protection is created.

Notice that this function calls _verifyLendingPoolIsActive as part of its verification before creating new protection - this check denies protection on loans that are in LateWithinGracePeriod or Late phase (see snippet below).

Solidity
function _verifyLendingPoolIsActive(
    IDefaultStateManager defaultStateManager,
    address _protectionPoolAddress,
    address _lendingPoolAddress
  ) internal view {
    LendingPoolStatus poolStatus = defaultStateManager.getLendingPoolStatus(
      _protectionPoolAddress,
      _lendingPoolAddress
    );

    ...
    if (
      poolStatus == LendingPoolStatus.LateWithinGracePeriod ||
      poolStatus == LendingPoolStatus.Late
    ) {
      revert IProtectionPool.LendingPoolHasLatePayment(_lendingPoolAddress);
    }
    ...
}

Impact

User who has been regularly renewing protection and paying premium to protect against a future loss event will be denied that very protection when she most needs it.

If existing user is denied renewal, she can never get back in (unless the lending pool becomes active again). All her previous payments were a total loss for her.

Code Snippet

https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/core/pool/ProtectionPool.sol#L189

https://github.com/sherlock-audit/2023-02-carapace/blob/main/contracts/libraries/ProtectionPoolHelper.sol#L407

Tool used

Manual Review

Recommendation

When a user is calling renewProtection, a different implementation of verifyLendingPoolIsActive is needed that allows a user to renew even when lending pool status is LateWithinGracePeriod or Late.

Recommend using verifyLendingPoolIsActiveForRenewal function in renewal flow as shown below

Solidity
  function verifyLendingPoolIsActiveForRenewal(
    IDefaultStateManager defaultStateManager,
    address _protectionPoolAddress,
    address _lendingPoolAddress
  ) internal view {
    LendingPoolStatus poolStatus = defaultStateManager.getLendingPoolStatus(
      _protectionPoolAddress,
      _lendingPoolAddress
    );

    if (poolStatus == LendingPoolStatus.NotSupported) {
      revert IProtectionPool.LendingPoolNotSupported(_lendingPoolAddress);
    }
    //------ audit - this section needs to be commented-----//
    //if (
    //  poolStatus == LendingPoolStatus.LateWithinGracePeriod ||
    //  poolStatus == LendingPoolStatus.Late
    //) {
    //  revert IProtectionPool.LendingPoolHasLatePayment(_lendingPoolAddress);
    //}
    // ---------------------------------------------------------//

    if (poolStatus == LendingPoolStatus.Expired) {
      revert IProtectionPool.LendingPoolExpired(_lendingPoolAddress);
    }

    if (poolStatus == LendingPoolStatus.Defaulted) {
      revert IProtectionPool.LendingPoolDefaulted(_lendingPoolAddress);
    }
  }

Discussion

vnadoda

@clems4ev3r, @taisukemino and I will discuss this internally

vnadoda

@clems4ev3r planning to fix this.

clems4ev3r

@vnadoda yes this is a valid issue

Jeiwan

@vnadoda Could you please clarify why this is a valid issue? And I'd appreciate if you share how you fixed it.

In my view, the recommended mitigation introduces a different vulnerability: allowing to renew protections in LateWithinGracePeriod and Late states gives buyers an advantage and allows to time late positions because positions in these states have a higher chance of a default. This can be exploited as follows:

  1. Buyers only buy protections with the minimal duration.
  2. Expired protections are not renewed until positions get into the LateWithinGracePeriod or Late state.
  3. Multiple options here:

a) If positions don't get into the LateWithinGracePeriod state before the renewal window has expired, buyers renew positions. This allows them to not pay for the duration of the renewal window. b) When positions are in the LateWithinGracePeriod state and the grace period is close to running out, buyers renew their protections so that they cover the moment when the positions default. c) When positions are in the Late state, buyers renew their protections to cover the moment when the positions default.

This allows buyers to minimize the cost of protections while having an almost guaranteed way to get a protection if a position defaults.

vnadoda

@Jeiwan @clems4ev3r @hrishibhat Once protection is expired, buyers will have a certain time limit within which they have to renew (7-10 days). So buyers can't wait for a long time. Generally payment period for loans is 30 days. Essentially buyers have to continuously renew their protections to get the coverage.

vnadoda

@clems4ev3r PR for this fix is: https://github.com/carapace-finance/credit-default-swaps-contracts/pull/72

clems4ev3r

Fix looks good

The original report as published on Sherlock, by 0Kage. 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

Likely the renewal flow reuses the same active-pool verification as new protection creation, which rejects pools in LateWithinGracePeriod or Late states, instead of using a renewal-specific check that permits those states.

Impact

An existing buyer who has regularly renewed and paid premiums can be denied renewal when the lending pool first becomes late, losing all previous payments and protection when most needed; the text notes this is unfair for existing buyers but acceptable for new buyers.

What the attacker needed

Existing protection buyer; protection expired within grace period; lending pool becomes late

The fix

The project planned to fix it by using a separate verification for renewals that allows renewal when the pool is LateWithinGracePeriod or Late, and a pull request was made and reviewed as looking good.

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 for credit default swaps, where a buyer pays premiums to be protected if a loan defaults. The contract has a grace period after protection expires during which the buyer can renew, but a separate check blocks renewal if the loan is slightly late. So the buyer loses coverage right when trouble starts, despite being allowed to renew.

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 0Kage

View all

7 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.