code-423n4 / 2024-08-wildcat-findings

3 stars 1 forks source link

Lenders' funds is locked without interest in prematurely closed fixed-term loan markets #87

Closed howlbot-integration[bot] closed 2 months ago

howlbot-integration[bot] commented 2 months ago

Lines of code

https://github.com/code-423n4/2024-08-wildcat/blob/fe746cc0fbedc4447a981a50e6ba4c95f98b9fe1/src/access/FixedTermLoanHooks.sol#L857-L859

Vulnerability details

Proof of Concept

The current implementation of the Wildcat protocol can lead to a situation where lenders' funds are locked without earning interest if a fixed-term loan market is closed prematurely. This issue arises from the interaction between the WildcatMarket and FixedTermLoanHooks contracts.

In the WildcatMarket contract, the closeMarket function can be called by the borrower at any time:

function closeMarket() external onlyBorrower nonReentrant sphereXGuardExternal {
  MarketState memory state = _getUpdatedState();
  if (state.isClosed) revert_MarketAlreadyClosed();
  // ... (no check for fixed term end time)
  state.annualInterestBips = 0;
  state.isClosed = true;
  // ...
}

However, in the FixedTermLoanHooks contract, withdrawals are still restricted until the fixedTermEndTime:

function onQueueWithdrawal(
  address lender,
  uint32 /* expiry */,
  uint /* scaledAmount */,
  MarketState calldata /* state */,
  bytes calldata hooksData
) external override {
  HookedMarket memory market = _hookedMarkets[msg.sender];
  if (!market.isHooked) revert NotHookedMarket();
  if (market.fixedTermEndTime > block.timestamp) {
    revert WithdrawBeforeTermEnd();
  }
  // ...
}

This discrepancy creates a scenario where:

  1. The borrower can close the market early using closeMarket.
  2. Interest accrual stops (as closeMarket sets annualInterestBips = 0).
  3. Lenders are prevented from withdrawing their funds until the original fixedTermEndTime.

As a result, lenders' funds are locked in the market without earning interest for the period between the early closure and the original fixed term end time. This situation disadvantages lenders, who are unable to access or earn interest on their funds during this period.

Recommended Mitigation Steps

Allow withdrawals without restriction once a market is closed.

  if (market.fixedTermEndTime > block.timestamp && !state.isClosed) {
    revert WithdrawBeforeTermEnd();
  }

Assessed type

Other

c4-judge commented 1 month ago

3docSec marked the issue as satisfactory