# deployWithdrawalQueue() need to clear _queueAccounting[lastQueueIndex]

deployWithdrawalQueue fails to clear stale _queueAccounting[lastQueueIndex], so queueClaimAll distributes received funds using outdated fractions, misallocating withdrawals.

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

**Target:** WithdrawalQueue contract (Solidity)
**Root cause:** deployWithdrawalQueue deletes _queueOutstandingValues[lastQueueIndex] and _outstandingValues but not _queueAccounting[lastQueueIndex], leaving stale thisQueueFraction data for the reused queue index.
**Steps:**
1. Call deployWithdrawalQueue() to rotate queues; _pendingQueueIndex becomes lastQueueIndex while _queueAccounting[lastQueueIndex] retains old thisQueueFraction.
2. Later call queueClaimAll() -> _queueClaimAll(_pendingQueueIndex) -> _updatePendingWithdrawalWithQueue(_pendingQueueIndex).
3. Loop reads stale _queueAccounting[secondIdx].thisQueueFraction and computes pendingForQueue = totalReceived.mulDivDown(fraction, PRINCIPAL_PRECISION), distributing totalReceived by outdated fractions.
4. Observe misallocated _pendingWithdrawal[secondIdx] values versus correct current-queue fractions.
**How found:** Code review of deployWithdrawalQueue's state-clearing block, noticing _queueAccounting[lastQueueIndex] was omitted while sibling mappings were deleted, then tracing queueClaimAll into _updatePendingWithdrawalWithQueue to confirm the stale fraction is consumed.
**Exploitation:** Any user triggering queueClaimAll after a queue rotation causes totalReceived to be split using stale fractions from the previous queue, misallocating withdrawal proceeds among queues.
**Insight:** When a contract rotates/reuses an index (here _pendingQueueIndex = lastQueueIndex), audit every mapping keyed by that index for a matching delete; sibling deletes in the same block are a strong hint one was forgotten.

