# No lender is able to exit even after the market is closed

Closing a Wildcat market with a fixed-term hook leaves fixedTermEndTime unchanged, so lenders cannot withdraw until the original term expires.

- Payout: Audit contest
- Severity: medium
- Program: Wildcat
- Found by: 0xpiken
- Disclosed: 2024-10-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-08-wildcat-findings/issues/52
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-wildcat%3AM-06
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity vuln:access-control vuln:business-logic

**Target:** WildcatMarket / FixedTermLoanHooks
**Root cause:** closeMarket does not invoke the hook to reset fixedTermEndTime, and FixedTermLoanHooks does not enable the CloseMarket hook flag, so the withdrawal guard still enforces the original term end.
**Steps:**
1. Deploy FixedTermLoanHooks template and register via hooksFactory.addHooksTemplate
2. As borrower, deploy hooks instance and deployMarket with hooksData `abi.encode(block.timestamp + 365 days)`
3. As lender, deposit via `depositUpTo(50_000e18)`
4. As borrower, call `WildcatMarket(market).closeMarket()`
5. As lender, call `queueFullWithdrawal()` -> reverts with `WithdrawBeforeTermEnd`
**How found:** Reading FixedTermLoanHooks config: noticed CloseMarket hook flag not enabled and onCloseMarket empty, so closing market never updates fixedTermEndTime; wrote a forge test to confirm the revert.
**Exploitation:** Borrower closes the market early; lenders' funds remain locked until fixedTermEndTime elapses because the hook's withdrawal check still reverts, denying exit despite market closure.
**Insight:** When a hook gates withdrawals by a stored timestamp, check every state transition that should invalidate that timestamp (market close, term change) actually calls the hook; missing hook flags in the deployment config are a common gap.

## Proof of concept (copied exactly from the original report)

**Foundry test proving lender cannot exit after close**

```
function test_closeMarket_BeforeFixedTermExpired() external {
    //@audit-info deploy a FixedTermLoanHooks template
    address fixedTermHookTemplate = LibStoredInitCode.deployInitCode(type(FixedTermLoanHooks).creationCode);
    hooksFactory.addHooksTemplate(
      fixedTermHookTemplate,
      'FixedTermLoanHooks',
      address(0),
      address(0),
      0,
      0
    );
    
    vm.startPrank(borrower);
    //@audit-info borrower deploy a FixedTermLoanHooks hookInstance
    address hooksInstance = hooksFactory.deployHooksInstance(fixedTermHookTemplate, '');
    DeployMarketInputs memory parameters = DeployMarketInputs({
      asset: address(asset),
      namePrefix: 'name',
      symbolPrefix: 'symbol',
      maxTotalSupply: type(uint128).max,
      annualInterestBips: 1000,
      delinquencyFeeBips: 1000,
      withdrawalBatchDuration: 10000,
      reserveRatioBips: 10000,
      delinquencyGracePeriod: 10000,
      hooks: EmptyHooksConfig.setHooksAddress(address(hooksInstance))
    });
    //@audit-info borrower deploy a market hooked by a FixedTermLoanHooks hookInstance
    address market = hooksFactory.deployMarket(
      parameters,
      abi.encode(block.timestamp + (365 days)),
      bytes32(uint(1)),
      address(0),
      0
    );
    vm.stopPrank();
    //@audit-info lenders can only withdraw their asset one year later
    assertEq(FixedTermLoanHooks(hooksInstance).getHookedMarket(market).fixedTermEndTime, block.timestamp + (365 days));
    //@audit-info alice deposit 50K asset into market
    vm.startPrank(alice);
    asset.approve(market, type(uint).max);
    WildcatMarket(market).depositUpTo(50_000e18);
    vm.stopPrank();
    //@audit-info borrower close market in advance
    vm.prank(borrower);
    WildcatMarket(market).closeMarket();
    //@audit-info the market is closed
    assertTrue(WildcatMarket(market).isClosed());
    //@audit-info however, alice can not withdraw her asset due to the unexpired fixed term.
    vm.expectRevert(FixedTermLoanHooks.WithdrawBeforeTermEnd.selector);
    vm.prank(alice);
    WildcatMarket(market).queueFullWithdrawal();
  }
```

