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.
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.
_getUndeployedAssets(): This is called indeployWithdrawalQueue()to calculate proRata liquid assets to thequeue.contractAddress.
function _getUndeployedAssets() private view returns (uint256) {
return asset.balanceOf(address(this)) + IBaseInterestAllocator(getBaseInterestAllocator).getAssetsAllocated()
|> - getAvailableToWithdraw - getCollectedFees;
}
uint256 undeployedAssets: This is manually calculated invalidateOfferflow, which is used check whether the pool has enough undeployed Assets to coverloan.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
);
...
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.
_reallocate(): This also manually calculate totalundeployedAssetsamount, but again didn’t account forgetCollectedFees._reaalocate()balances optimal target idle assets ratio by checkingcurrentBalance/totalratio. Here,currentBalanceshould be additionally subtracted bygetCollectedFeesbecause 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);
...
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.
Missing collected fees in accounting.
Status: Mitigation confirmed. Full details in reports from oakcobalt and minhquanym.
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.