Skip to content
Business logic Audit finding Intermediate

confirmUnderwriter() need to recalculate getMinTimeBetweenWithdrawalQueues

The Pool contract calculates a minimum time between withdrawal queues based on the underwriter's maximum duration, but when the underwriter is changed via confirmUnderwriter, this value is not recalculated. If the new underwriter has a larger maximum duration, the minimum time becomes too small, causing pending queues to be overwritten prematurely and loans to fail to find their queues when repaid.

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen

getMinTimeBetweenWithdrawalQueues is very important for Pool. If getMinTimeBetweenWithdrawalQueues is too small, pendingQueues will be overwritten too early, and when Loan pays off, it won’t be able to find the corresponding queues.

So we will calculate getMinTimeBetweenWithdrawalQueues by MaxDuration + _LOAN_BUFFER_TIME to make sure it won’t be overwritten too early.

    constructor(
        address _feeManager,
        address _offerHandler,
        uint256 _waitingTimeBetweenUpdates,
        OptimalIdleRange memory _optimalIdleRange,
        uint256 _maxTotalWithdrawalQueues,
        uint256 _reallocationBonus,
        ERC20 _asset,
        string memory _name,
        string memory _symbol
    ) ERC4626(_asset, _name, _symbol) LoanManager(tx.origin, _offerHandler, _waitingTimeBetweenUpdates) {

....

@>      getMinTimeBetweenWithdrawalQueues = (IPoolOfferHandler(_offerHandler).getMaxDuration() + _LOAN_BUFFER_TIME)
            .mulDivUp(1, _maxTotalWithdrawalQueues);

But switching the new getUnderwriter/_offerHandler doesn’t recalculate the getMinTimeBetweenWithdrawalQueues.

    function confirmUnderwriter(address __underwriter) external onlyOwner {
        if (getPendingUnderwriterSetTime + UPDATE_WAITING_TIME > block.timestamp) {
            revert TooSoonError();
        }
        if (getPendingUnderwriter != __underwriter) {
            revert InvalidInputError();
        }

@>      getUnderwriter = __underwriter;
        getPendingUnderwriter = address(0);
        getPendingUnderwriterSetTime = type(uint256).max;

        emit UnderwriterSet(__underwriter);
    }

This may break the expectation of getMinTimeBetweenWithdrawalQueues, and the new getUnderwriter.getMaxDuration is larger than the old one; which may cause pendingQueues to be overwritten prematurely.

Impact

The new getUnderwriter.getMaxDuration is larger than the old one, which may cause pendingQueues to be overwritten prematurely.

Recommended Mitigation

Pool overrides confirmUnderwriter() with an additional recalculation of getMinTimeBetweenWithdrawalQueues and must not be smaller than the old one, to avoid premature overwriting of the previous one.

contract Pool is ERC4626, InputChecker, IPool, IPoolWithWithdrawalQueues, LoanManager, ReentrancyGuard {
-   uint256 public immutable getMinTimeBetweenWithdrawalQueues;
+   uint256 public getMinTimeBetweenWithdrawalQueues;
...
+   function confirmUnderwriter(address __underwriter) external override onlyOwner {
+           super.confirmUnderwriter(__underwriter);
+           uint256 newMinTime = (IPoolOfferHandler(__underwriter).getMaxDuration() + _LOAN_BUFFER_TIME)
+            .mulDivUp(1, _maxTotalWithdrawalQueues);
+           require(newMinTime >= getMinTimeBetweenWithdrawalQueues,"invalid");
+           getMinTimeBetweenWithdrawalQueues = newMinTime;
+    }

Assessed type

Context

0xend (Gondi) confirmed

Gondi mitigated:

Added check (maxDuration cannot be longer).

Status: Mitigation confirmed. Full details in reports from oakcobalt, bin2chen and minhquanym.


The original report as published on Code4rena, by bin2chen. 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

The confirmUnderwriter function updates the underwriter but does not recalculate getMinTimeBetweenWithdrawalQueues, which depends on the underwriter's maximum duration.

Impact

If the new underwriter's maximum duration is larger than the old one, pendingQueues may be overwritten prematurely, potentially causing loans to fail to find their queues upon repayment.

What the attacker needed

Owner changes underwriter; new underwriter has larger maxDuration

The fix

The Pool contract should override confirmUnderwriter to recalculate getMinTimeBetweenWithdrawalQueues and ensure it is not smaller than the previous value; the mitigation added a check that maxDuration cannot be longer.

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 pool contract uses a waiting period to keep track of withdrawal requests. This period is set when the pool is created, based on the current underwriter's maximum loan duration. If the underwriter is later changed to one with a longer maximum duration, the waiting period is not updated, so old withdrawal requests can be overwritten too soon. This can cause problems when loans are repaid because the contract cannot find the correct withdrawal queue.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Gondi Invitational

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.