Incorrect accounting of _pendingWithdrawal in queueClaiming flow
In the queue claiming flow, the pending withdrawal amount for a queue index was overwritten rather than accumulated, so funds distributed from earlier queue indexes were lost. An attacker or user could lose received funds when multiple queues were claimed together.
Submitted by oakcobalt, also found by bin2chen
Incorrect accounting of _pendingWithdrawal in queueClaiming flow, funds received from a previous queue index will be lost.
Proof of Concept
In Pool.sol’s queueClaimAll(), each queue’s received funds getTotalReceived[_idx] (total returned funds from loans for that queue) will be distributed to all newer queues in a for-loop.
There are two for-loops in this flow. First for-loop iterate through each pendingWithdrawal index to get the received funds for that queue index (getTotalReceived[_idx]). Second for-loop iterates through each queue index again to distribute funds from _idx.
The problem is in the second for-loop, _pendingWithdrawal[secondIdx] will not accumulate distributed funds from previous queue indexes, instead it erases the value from previous loops and only records the last queue’s received funds.
//src/lib/pools/Pool.sol
function _updatePendingWithdrawalWithQueue(
uint256 _idx,
uint256 _cachedPendingQueueIndex,
uint256[] memory _pendingWithdrawal
) private returns (uint256[] memory) {
uint256 totalReceived = getTotalReceived[_idx];
uint256 totalQueues = getMaxTotalWithdrawalQueues + 1;
...
getTotalReceived[_idx] = 0;
...
for (uint256 i; i < totalQueues;) {
...
//@audit this should be _pendingWithdraw[secondIdx] += pendingForQueue; Current implementation directly erases `pendingForQueue` value distributed from other queues.
|> _pendingWithdrawal[secondIdx] = pendingForQueue;
...
Note that getTotalReceived[_idx] will be cleared before the for-loop (getTotalReceived[_idx] = 0), meaning that the erased pendingForQueue values from previous loops cannot be recovered. _pendingWithdrawal will be incorrect.
Recommended Mitigation Steps
Change into _pendingWithdrawal[secondIdx] + = pendingForQueue;.
Assessed type
Error
Missing
+.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
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 an assignment was used instead of an addition when updating the pending withdrawal amount for each queue index.
Impact
Funds received from previous queue indexes could be lost when claiming multiple queues, leading to incorrect withdrawal accounting.
What the attacker needed
Multiple withdrawal queues; queue claiming flow
The fix
The code was fixed by changing the assignment to an addition so pending withdrawal amounts accumulate.
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.
When several withdrawal queues are processed together, money received for one queue is meant to be added to the amount already recorded for later queues. Instead, the code replaced that amount, so earlier money disappeared. This is a simple arithmetic mistake in a smart contract.
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.