Skip to content
Business logic Audit finding Intermediate

Inconsistent accounting of undeployedAssets might result in undesired optimal range in the pool

The pool contract calculates undeployed assets inconsistently: one function subtracts collected protocol fees, while two others do not. This could cause the pool to accept loans that exceed its actual liquid assets and to rebalance to an incorrect idle-asset ratio.

oakcobalt Follow with bin2chen

Originally disclosed on Code4rena

Submitted by oakcobalt, also found by bin2chen

undeployedAssets is calculated inconsistently. Currently in _getUndeployedAssets() the protocol collected fees are subtracted; however, in validateOffer, the protocol collected fees are not subtracted.

  1. _getUndeployedAssets(): This is called in deployWithdrawalQueue() to calculate proRata liquid assets to the queue.contractAddress.
    function _getUndeployedAssets() private view returns (uint256) {
        return asset.balanceOf(address(this)) + IBaseInterestAllocator(getBaseInterestAllocator).getAssetsAllocated()
|>            - getAvailableToWithdraw - getCollectedFees;
    }
  1. uint256 undeployedAssets: This is manually calculated in validateOffer flow, which is used check whether the pool has enough undeployed Assets to cover loan.principalAmount.
    function validateOffer(bytes calldata _offer, uint256 _protocolFee) external override onlyAcceptedCallers {
...
        uint256 currentBalance = asset.balanceOf(address(this)) - getAvailableToWithdraw;
        uint256 baseRateBalance = IBaseInterestAllocator(getBaseInterestAllocator).getAssetsAllocated();
         //@audit getCollectedFees is not subtracted
|>        uint256 undeployedAssets = currentBalance + baseRateBalance;
        (uint256 principalAmount, uint256 apr) = IPoolOfferHandler(getUnderwriter).validateOffer(
            IBaseInterestAllocator(getBaseInterestAllocator).getBaseAprWithUpdate(), _offer
        );
...

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/pools/Pool.sol#L398

Note that in (2), undeployedAssets are inflated because getCollectedFees are fees protocol collected from liquidation/repayment flows and shouldn’t be considered as liquid assets to cover the loan principal amount.

  1. _reallocate(): This also manually calculate total undeployedAssets amount, but again didn’t account for getCollectedFees. _reaalocate() balances optimal target idle assets ratio by checking currentBalance/total ratio. Here, currentBalance should be additionally subtracted by getCollectedFees because fees are set aside and shouldn’t be considered idle. This affects optimal range check.
    function _reallocate() private returns (uint256, uint256) {
        /// @dev Balance that is idle and belongs to the pool (not waiting to be claimed)
        uint256 currentBalance = asset.balanceOf(address(this)) - getAvailableToWithdraw;
        if (currentBalance == 0) {
            revert AllocationAlreadyOptimalError();
        }
        uint256 baseRateBalance = IBaseInterestAllocator(getBaseInterestAllocator).getAssetsAllocated();
        uint256 total = currentBalance + baseRateBalance;
        uint256 fraction = currentBalance.mulDivDown(PRINCIPAL_PRECISION, total);
...

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/pools/Pool.sol#L572

Inconsistent accounting in various flows may result in incorrect checks or undesirable optimal ranges.

Recommended Mitigation Steps

Account for getCollectedFees in (2) and (3), noted above.

0xend (Gondi) confirmed

Gondi mitigated:

Missing collected fees in accounting.

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


The original report as published on Code4rena, by oakcobalt. 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 collected fees are subtracted in one helper function but omitted in two other places that manually compute the same undeployed-assets value.

Impact

The pool could accept a loan whose principal exceeds the truly available liquid assets, and the reallocation logic could target an incorrect idle-asset ratio.

What the attacker needed

None

The fix

The collected fees should be subtracted in the validateOffer and _reallocate calculations, and the project mitigated the issue.

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 smart contract pool tracks how much money is available to lend. Some of that money is set aside as fees for the protocol and should not be counted as available. The code counts it in some places but not others, so the pool may think it has more money than it really does.

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 oakcobalt

View all

50 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.