No lender is able to exit even after the market is closed
A market using a fixed-term hook lets the borrower close the market early, but the hook's fixed-term end time is not reset, so lenders cannot withdraw their funds until the original term expires. An attacker (the borrower) could lock all lender assets indefinitely by closing the market before the term ends.
0xpiken Follow with josephxander and 0xNirix
Originally disclosed on Code4rena
Submitted by 0xpiken, also found by josephxander and 0xNirix
When a borrower creates a market hooked by a fixed-term hook, all lenders are prohibited from withdrawing their assets from the market before the fixed-term time has elapsed.
The borrower can close the market at any time. However, fixedTermEndTime of the market is not updated, preventing lenders from withdrawing their assets if fixedTermEndTime has not yet elapsed.
Copy below codes to WildcatMarket.t.sol and run forge test —match-test testcloseMarketBeforeFixedTermExpired:
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();
}
Recommended Mitigation Steps
When a market hooked by a fixed-term hook is closed, fixedTermEndTime should be set to block.timestamp if it has not yet elapsed:
constructor(address _deployer, bytes memory /* args */) IHooks() {
borrower = _deployer;
// Allow deployer to grant roles with no expiry
_roleProviders[_deployer] = encodeRoleProvider(
type(uint32).max,
_deployer,
NotPullProviderIndex
);
HooksConfig optionalFlags = encodeHooksConfig({
hooksAddress: address(0),
useOnDeposit: true,
useOnQueueWithdrawal: false,
useOnExecuteWithdrawal: false,
useOnTransfer: true,
useOnBorrow: false,
useOnRepay: false,
useOnCloseMarket: false,
useOnNukeFromOrbit: false,
useOnSetMaxTotalSupply: false,
useOnSetAnnualInterestAndReserveRatioBips: false,
useOnSetProtocolFeeBips: false
});
HooksConfig requiredFlags = EmptyHooksConfig
.setFlag(Bit_Enabled_SetAnnualInterestAndReserveRatioBips)
+ .setFlag(Bit_Enabled_CloseMarket);
.setFlag(Bit_Enabled_QueueWithdrawal);
config = encodeHooksDeploymentConfig(optionalFlags, requiredFlags);
}
function onCloseMarket(
MarketState calldata /* state */,
bytes calldata /* hooksData */
- ) external override {}
+ ) external override {
+ HookedMarket memory market = _hookedMarkets[msg.sender];
+ if (!market.isHooked) revert NotHookedMarket();
+ if (market.fixedTermEndTime > block.timestamp) {
+ _hookedMarkets[msg.sender].fixedTermEndTime = uint32(block.timestamp);
+ }
+ }
laurenceday (Wildcat) confirmed and commented:
This is a great catch.
laurenceday (Wildcat) commented:
Fixed by wildcat-finance/v2-protocol@05958e3.
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 fixed-term hook does not handle the market-close event, so the stored fixed-term end time is never shortened when the market is closed early.
Impact
Lenders' funds could be locked until the original fixed term ends even after the market is closed, and the borrower controls when to close it.
What the attacker needed
Borrower deploys a fixed-term hooked market; lender deposits into the market; borrower closes market before term ends
The fix
The hook should handle the market-close event and set the fixed-term end time to the current block timestamp if it has not yet elapsed; the project says this was fixed.
How it was found
- Deploy a fixed-term hook template and a hook instance.
- Deploy a market hooked by that instance with a fixed term one year ahead.
- A lender deposits assets into the market.
- The borrower closes the market before the term expires.
- The lender tries to queue a full withdrawal and the transaction reverts.
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.
A lending market can be set up so lenders agree not to take their money out until a set date. The person who runs the market can shut it down early, but the code forgets to cancel that date, so lenders are still blocked from withdrawing even though the market is closed. This means their money can be stuck.
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.