# Incorrect accounting of _pendingWithdrawal in queueClaiming flow

In Gondi Pool.sol queueClaimAll, _pendingWithdrawal[secondIdx] is assigned instead of accumulated, erasing funds distributed from earlier queue indexes and losing received loan funds.

- Payout: Audit contest
- Severity: high
- Program: Gondi
- Found by: oakcobalt
- Disclosed: 2024-07-25
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-gondi-findings/issues/46
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AH-09
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error

**Target:** Pool.sol queueClaimAll / _updatePendingWithdrawalWithQueue (Solidity lending pool)
**Root cause:** In the second distribution loop, `_pendingWithdrawal[secondIdx] = pendingForQueue` overwrites rather than adds to the value accumulated from previous queue indexes; getTotalReceived[_idx] is zeroed beforehand so the erased amounts are unrecoverable.
**Steps:**
1. Call queueClaimAll() with multiple pending withdrawal queues.
2. First loop reads getTotalReceived[_idx] per queue index.
3. Second loop distributes funds; `_pendingWithdrawal[secondIdx] = pendingForQueue` overwrites prior accumulation.
4. getTotalReceived[_idx] already set to 0, so overwritten amounts are lost.
5. Fix: use `_pendingWithdrawal[secondIdx] += pendingForQueue`.
**How found:** Code review of the two-loop queueClaimAll distribution logic, spotting that the second loop assigns instead of accumulates into _pendingWithdrawal and that getTotalReceived is cleared before the loop.
**Exploitation:** Not a direct attacker extraction; incorrect accounting causes funds received from earlier queue indexes to be lost/undistributed to users during queue claiming.
**Insight:** In multi-queue distribution loops, verify each recipient's balance is accumulated (+=) across iterations, especially when the source counter is zeroed before the loop so overwrites become unrecoverable.

## Proof of concept (copied exactly from the original report)

**Buggy assignment overwriting pendingWithdrawal instead of accumulating**

```
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;
```

