Skip to content
Business logic Audit finding Intermediate

FixedTermLoanHooks allow Borrower to update Annual Interest before end of the “Fixed Term Period”

The FixedTermLoanHooks contract allows the borrower to change the annual interest rate (APR) even during a fixed term period when lenders cannot withdraw. This lets the borrower reduce the APR to zero, effectively denying lenders the interest they expected.

Infect3d Follow with 0xpiken and falconhoof

Originally disclosed on Code4rena

Submitted by Infect3d, also found by 0xpiken and falconhoof

Summary

While the documentation states that in case of ‘fixed term’ market the APR cannot be changed until the term ends, nothing prevents this in FixedTermLoanHooks.

Vulnerability details

In Wildcat markets, lenders know in advance how much APR the borrower will pay them. In order to allow lenders to exit the market swiftly, the market must always have at least a reserve ratio of the lender funds ready to be withdrawn.

If the borrower decides to reduce the APR, in order to allow lenders to ‘ragequit’, a new reserve ratio is calculated based on the variation of the APR as described in the link above.

Finally, is a market implement a fixed term (date until when withdrawals are not possible), it shouldn’t be able to reduce the APR, as this would allow the borrower to ‘rug’ the lenders by reducing the APR to 0% while they couldn’t do anything against that.

The issue here is that while lenders are (as expected) prevented to withdraw before end of term: https://github.com/code-423n4/2024-08-wildcat/blob/main/src/access/FixedTermLoanHooks.sol#L857-L859

File: src/access/FixedTermLoanHooks.sol
848:   function onQueueWithdrawal(
849:     address lender,
850:     uint32 /* expiry */,
851:     uint /* scaledAmount */,
852:     MarketState calldata /* state */,
853:     bytes calldata hooksData
854:   ) external override {
855:     HookedMarket memory market = _hookedMarkets[msg.sender];
856:     if (!market.isHooked) revert NotHookedMarket();
857:     if (market.fixedTermEndTime > block.timestamp) {
858:       revert WithdrawBeforeTermEnd();
859:     }

this is not the case for the borrower setting the annual interest: https://github.com/code-423n4/2024-08-wildcat/blob/main/src/access/FixedTermLoanHooks.sol#L960-L978

File: src/access/FixedTermLoanHooks.sol
960:   function onSetAnnualInterestAndReserveRatioBips(
961:     uint16 annualInterestBips,
962:     uint16 reserveRatioBips,
963:     MarketState calldata intermediateState,
964:     bytes calldata hooksData
965:   )
966:     public
967:     virtual
968:     override
969:     returns (uint16 updatedAnnualInterestBips, uint16 updatedReserveRatioBips)
970:   {
971:     return
972:       super.onSetAnnualInterestAndReserveRatioBips(
973:         annualInterestBips,
974:         reserveRatioBips,
975:         intermediateState,
976:         hooksData
977:       );
978:   }
979:

Impact

Borrower can rug the lenders by reducing the APR while they cannot quit the market.

Proof of Concept

Add this test to test/access/FixedTermLoanHooks.t.sol

  function testAudit_SetAnnualInterestBeforeTermEnd() external {
    DeployMarketInputs memory inputs;

	// "deploying" a market with MockFixedTermLoanHooks
	inputs.hooks = EmptyHooksConfig.setHooksAddress(address(hooks));
	hooks.onCreateMarket(
		address(this),				// deployer
		address(1),				// dummy market address
		inputs,					// ...
		abi.encode(block.timestamp + 365 days, 0) // fixedTermEndTime: 1 year, minimumDeposit: 0
	);

	vm.prank(address(1));
	MarketState memory state;
	// as the fixedTermEndTime isn't past yet, it's not possible to withdraw
	vm.expectRevert(FixedTermLoanHooks.WithdrawBeforeTermEnd.selector);
	hooks.onQueueWithdrawal(address(1), 0, 1, state, '');

	// but it is still possible to reduce the APR to zero
	hooks.onSetAnnualInterestAndReserveRatioBips(0, 0, state, "");
  }

Recommended Mitigation Steps

When FixedTermLoanHooks::onSetAnnualInterestAndReserveRatioBips is called, revert if market.fixedTermEndTime > block.timestamp.

laurenceday (Wildcat) disputed and commented via duplicate issue #23:

This is a valid finding, thank you - an embarrassing one for us at that, we clearly just missed this when writing the hook templates!

However, we’re a bit torn internally on whether this truly classifies as a High. We’ve definitely specified in documentation that this is a rug pull mechanic, but there are no funds directly or indirectly at risk here, unless you classify the potential of earning less than expected when you initially deposited as falling in that bucket.

So, we’re going to kick this one to the judge: does earning 10,000 on a 100,000 deposit rather than 15,000 count as funds at risk if there’s no way to ragequit for the period of time where that interest should accrue? Or is this more of a medium wherein protocol functionality is impacted?

It’s definitely a goof on our end, and we’re appreciative that the warden caught it, so thank you. With that said, we’re trying to be fair to you (the warden) while also being fair to everyone else that’s found things. This is a very gentle dispute for the judge to handle: sadly the ‘disagree with severity’ tag isn’t available to us anymore!

3docSec (judge) decreased severity to Medium and commented via duplicate issue #23:

Hi @laurenceday thanks for adding context.

“So, we’re going to kick this one to the judge: does earning 10,000 on a 100,000 deposit rather than 15,000 count as funds at risk if there’s no way to ragequit for the period of time where that interest should accrue? Or is this more of a medium wherein protocol functionality is impacted?”

I consider this a Medium issue: because it’s only future “interest” gains that are at risk, I see this more like an availability issue where the lender’s funds are locked at conditions they didn’t necessarily sign up for; the problem is the locking (as you said if there was a ragequit option, it would be a different story).

I admit this is a subjective framing, but at the same time, it’s consistent with how severity is assessed in bug bounty programs, where missing out on future returns generally has lower severity than having present funds at risk.


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

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 onSetAnnualInterestAndReserveRatioBips function in FixedTermLoanHooks does not check whether the fixed term has ended, unlike the withdrawal function which does.

What the attacker needed

A fixed-term market; borrower controls the market

The fix

The function onSetAnnualInterestAndReserveRatioBips should revert if the fixed term end time is still in the future, as recommended in the report.

How it was found

  1. Deploy a market with MockFixedTermLoanHooks and set a fixed term end time one year in the future.
  2. Attempt to queue a withdrawal as a lender; it reverts with WithdrawBeforeTermEnd because the term has not ended.
  3. Call onSetAnnualInterestAndReserveRatioBips with zero annual interest and zero reserve ratio; the call succeeds, showing the APR can be reduced before term end.

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.

In a lending market, a borrower promises to pay interest (APR) to lenders. For a fixed term, lenders cannot take their money out until the term ends, so they rely on that interest. The bug is that the borrower can still lower the interest rate during the fixed term, which means lenders earn less than agreed and cannot leave.

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 Infect3d

View all

8 more disclosed reports, best first.

More from The Wildcat Protocol

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.