Any position can be closed (by repaying the debt) even after the maturity date has passed
The repay function in the settlement contract has no check on the loan's maturity timestamp, so a borrower can repay and close a position after the maturity date has passed. This lets a borrower front-run a liquidation attempt and delete the loan, causing the liquidation call to fail.
- Disclosed after under an hour
#47009 [SC-Low] Any position can be closed (by repaying the debt) even after the maturity date has passed
Submitted on Jun 7th 2025 at 19:51:39 UTC by @zeroK for IOP | Term Structure Institutional
- Report ID: #47009
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/term-structure/tsi-contract/blob/main/src/Settlement.sol
- Impacts:
- Block stuffing
Description
Brief/Intro
Any loan created has a maturity date, which is important because it enforces a repayment deadline. If the borrower does not repay on time, the position should be liquidated to ensure that the lender and the protocol are compensated. However, currently there is no restriction preventing repayment after the maturity date. Borrowers can repay or modify their position at any time, even after maturity. This undermines the liquidation process because users can front-run any attempt at liquidation by repaying their debt after maturity, effectively blocking liquidation for that loan position.
position should be liquidated right when the maturity reached for position: https://docs.institutional.ts.finance/features/liquidation-and-physical-delivery#liquidation-ltv-lltv
Vulnerability Details
we can see when a loan created, the maturity time should be set as input parameter:
function createSettlement(
string memory _settlementId,
SettleInfo calldata _settleInfo,
string[] memory _loanIds,
LoanInfo[] calldata _loans,
bytes calldata _signature
) external nonReentrant {
.....
// storage
struct LoanInfo {
bytes32 settlementId; // ID of the settlement this loan belongs to
address maker; // who created the loan
address lender; // who provides the funds
address borrower; // who receives the funds(borrow)
address collateralTokenAddr; // address of the collateral token
address debtTokenAddr; // address of the debt token
DebtData debtData;
bool settled; // has the loan been settled
}
struct DebtData {
uint256 collateralAmt; // amount of the collateral
uint256 debtAmt; // debt amount
uint256 borrowedAmt; // how muhch borrowed
uint256 feeAmt; // fee to pay to the protocol
uint64 maturity; // when the loan matures
uint32 lltv; // loan to value liquidation ratio in basis point
uint32 mltv; // maximum loan to value
}
however, there is nothing prevent the borrower to invoke the repay function, even when the maturity passed, since there is not check to prevent invoking the function when timestamp > maturity:
function repay(string memory _loanId, uint256 repayAmt, uint256 removeCollateralAmt) external nonReentrant {
bytes32 loanId = _loanId.toBytes32();
LoanInfo memory loanInfo = loans[loanId];
loanInfo.repay(repayAmt);
if (removeCollateralAmt > 0) {
loanInfo.checkBorrower(loanId, msg.sender);
loanInfo.removeCollateral(removeCollateralAmt, _oracle);
}
IERC20(loanInfo.debtTokenAddr).safeTransferFrom(msg.sender, loanInfo.lender, repayAmt);
if (removeCollateralAmt > 0) {
IERC20(loanInfo.collateralTokenAddr).safeTransferFrom(
loanInfo.lender, loanInfo.borrower, removeCollateralAmt
);
}
if (loanInfo.debtData.debtAmt == 0 && loanInfo.debtData.collateralAmt == 0) {
delete loans[loanId];
} else {
loans[loanId] = loanInfo;
}
emit Repaid(loanId, repayAmt, removeCollateralAmt);
}
this can lead calls to liquidation for mature position to fail since the loan deleted:
function liquidate(string memory _loanId, uint256 liquidationAmt) external nonReentrant {
bytes32 loanId = _loanId.toBytes32();
LoanInfo memory loanInfo = loans[loanId]; //@audit not exist
(uint256 collateralToLiquidator, uint256 collateralToProtocol) =
loanInfo.liquidate(loanId, _oracle, _minimumDebtValue, liquidationAmt);
this can block the liquidation process invoked by the bot, it can affect badly when batch of liquidation executed in one transaction.
Impact Details
maturity of the loans not respected in repay function which lead to prevent liquidations.
Recommend
add check for maturity in repay function, prevent repaying when the position passed the maturity.
Proof of Concept
Proof of Concept
- first thing create a settlement.
- set maturity to block.timestamp + 10 days.
- invoke the repay function, before that, wrap block.timestamp `wrap(block.timestamp +10 days)
- we can see the loan repaid and deleted even it get matured.
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
The repay function does not check whether the current time is past the loan's maturity, so repayment remains allowed after the deadline.
Impact
A borrower could block liquidation of a matured position by repaying first, which may disrupt batch liquidation transactions run by a bot.
What the attacker needed
An existing loan position; borrower can send a repay transaction
The fix
The repay function should be fixed to reject repayment once the position has passed its maturity date.
How it was found
- Create a settlement with a loan whose maturity is set ten days in the future.
- Advance the block timestamp past the maturity date.
- Call the repay function for the matured loan.
- Observe that the loan is repaid and deleted even though it had matured.
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 loan has a deadline (maturity). After that deadline the lender is supposed to be able to take the collateral through a process called liquidation. Here the borrower can still pay back the loan after the deadline, which removes the loan record, so the liquidation step finds nothing to act on and fails.
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.