# AccountingManager::resetMiddle will not behave as expected

resetMiddle on the withdraw queue fails to zero currentWithdrawGroup.totalCBAmount, so re-running calculateWithdrawShares double-counts base tokens needed, over-withdrawing funds or blocking withdrawals.

- Payout: Audit contest
- Severity: high
- Program: NOYA
- Found by: Aymen0909
- Disclosed: 2025-02-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-noya-findings/issues/1224
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-10
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error

**Target:** AccountingManager.sol withdraw queue accounting
**Root cause:** resetMiddle rewinds withdrawQueue.middle but leaves currentWithdrawGroup.totalCBAmount at its previously accumulated value; the next calculateWithdrawShares call adds the recomputed amount on top of the stale total.
**Steps:**
1. Manager calls calculateWithdrawShares(maxIterations), which advances withdrawQueue.middle and adds assetsNeededForWithdraw to currentWithdrawGroup.totalCBAmount.
2. Manager calls resetMiddle(newMiddle, false) with newMiddle < withdrawQueue.middle; middle is rewound but totalCBAmount is not reset.
3. Manager calls calculateWithdrawShares again; the same queue entries are reprocessed and totalCBAmount is incremented a second time.
4. Protocol pulls more base tokens from connectors than needed, or if totalCBAmount exceeds TVL, withdrawals are blocked.
**How found:** Code reading of calculateWithdrawShares and resetMiddle: noticed totalCBAmount is accumulated in calculateWithdrawShares but resetMiddle only rewinds the middle index, so a reset-then-recalculate sequence double-counts.
**Exploitation:** Requires manager action (privileged/operational mistake path): a reset followed by recalculation inflates totalCBAmount, forcing excess connector withdrawals (yield loss) or, when it exceeds TVL, permanently blocking the withdrawal group until new deposits arrive.
**Insight:** When a function accumulates a running total while advancing a cursor, audit every path that rewinds the cursor for a matching reset of the accumulator; asymmetric state updates between forward and backward operations are a reliable accounting-bug source.

