# Batch loop single failure reverts all

Loops that revert on one bad entry, and per-op checks that ignore other ops in the same batch

_Area: Smart contract access control and control flow. Seen in 3 disclosed reports; latest 2024-05-01. Updated 2026-11-17._

## How it works
A batch routine processes many entries in one transaction and treats every entry as if it must succeed. Any per-entry check that reverts — a reused nonce, a revoked allowance, an empty balance, a modifier on index 0 — aborts the whole batch. The assumption that breaks is "each entry is independent": in reality one entry's state is controlled by a counterparty, or is mutated by an earlier step in the same routine, so a single bad entry takes down all the good ones. A second shape: a check that runs per-op during a validation phase, before any execution, and compares against shared state (contract balance) without tallying the other ops that will also draw on it.

## Where it shows up
- Settlement/auction loops calling `_useNonce()`, `transferFrom`, or allowance checks per order [E3](https://bugbountylibrary.com/r/sherlock%3A2022-11-opyn%3AM-4.md)
- Loops where the caller or a counterparty can pre-mutate an entry's preconditions (nonce, approval, balance) before submission [E3](https://bugbountylibrary.com/r/sherlock%3A2022-11-opyn%3AM-4.md)
- Modifiers that gate on `array[0]` or another fixed index, where a routine reorders the array [E2](https://bugbountylibrary.com/r/c4%3A2022-11-debtdao%3AH-01.md)
- ERC-4337 `validatePaymasterUserOp` doing balance/state checks per UserOp while transfers happen later in `postOp` [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md)
- Any two-phase design (validate-all-then-execute-all) with shared-resource checks in phase one [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md)

## How to review
For each loop, ask: can one entry revert, and who controls that? The invariant: a failing entry must be skippable or pre-checked, not fatal to the batch. For index-gated modifiers, confirm no routine reorders the array so the gate inspects the wrong element [E2](https://bugbountylibrary.com/r/c4%3A2022-11-debtdao%3AH-01.md). For two-phase flows, the invariant is that a validation-time check must account for every other op in the bundle that will consume the same resource during execution — sum the withdrawals, don't check each alone [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md).

## How finders spotted it
- Read the EntryPoint's two-phase validation/execution loops and noticed MagicSpend's balance check runs per-op at validation while transfers happen later in `postOp`, so concurrent withdrawals are never tallied [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md)
- Read the `whileBorrowing()` modifier alongside `stepQ()` in `_repay()` and noticed the repaid zero-principal position lands at `ids[0]`, so the gate inspects the wrong element [E2](https://bugbountylibrary.com/r/c4%3A2022-11-debtdao%3AH-01.md)
- Reviewed auction loops and `_useNonce()`, saw one order failure reverts the batch, then hunted for user-controllable preconditions (nonce, approval, balance) a counterparty can change before submission [E3](https://bugbountylibrary.com/r/sherlock%3A2022-11-opyn%3AM-4.md)

## Variants seen
- Shared-resource check in validation phase ignoring other ops in the bundle [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md)
- Index-0 gate broken by array reordering in a repay routine [E2](https://bugbountylibrary.com/r/c4%3A2022-11-debtdao%3AH-01.md)
- Batch settlement loop reverting on a single used nonce or revoked approval [E3](https://bugbountylibrary.com/r/sherlock%3A2022-11-opyn%3AM-4.md)

## Impact and severity
In E1 two withdrawals each pass validation but together exceed the balance, reverting the second `postOp` — a paymaster DoS. In E2 insolvency declaration is blocked exactly when it is needed, after a repayment shifts a zero-principal position to index 0. In E3 a market maker front-runs the auction by marking an order used or revoking approval, reverting the entire `withdrawAuction`/`depositAuction` batch. Severity rises with how cheaply one party can poison an entry and how much value or liveness the batch carries.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md
- E2: https://bugbountylibrary.com/r/c4%3A2022-11-debtdao%3AH-01.md
- E3: https://bugbountylibrary.com/r/sherlock%3A2022-11-opyn%3AM-4.md
