# Duplicate entries skew aggregate selection

Caller-supplied lists aggregated or indexed without dedupe or per-element nonzero checks

_Area: Smart contract access control and control flow. Seen in 2 disclosed reports; latest 2024-06-24. Updated 2026-11-09._

## How it works
An aggregate or winner-selection routine trusts that each element of a caller-supplied list contributes once. When the code filters only by membership (is this actor allowed?) or by a modulo/equality check that zero or repeats satisfy, one caller can insert the same contribution many times, or insert zero-value entries that still consume or shift indexes. The downstream sum, weight, or index then reflects the attacker's multiplicity rather than the real set of participants. The broken assumption is "one element = one distinct contribution"; nothing enforces distinctness or nonzero-ness.

## Where it shows up
- Loops that validate each element against a set (allowlist, inferer, round) but never track seen keys or indexes.
- Batch deposit/withdraw functions where `expectedValue += amount` is compared to `msg.value`, and `amount == 0` passes a `% unit != 0` check.
- Index assignment (`entryIndex++`) that is skipped or duplicated on zero/repeat input, corrupting later winner selection.
- Per-op balance or state checks in a validation phase that runs for every item before any execution (ERC-4337 paymaster `validatePaymasterUserOp`).
- Aggregation math (`CalcForecastImpliedInferences`, weighted sums) fed directly from unfiltered arrays.

## How to review
For every list the caller supplies, ask: what makes two elements distinct, and is that enforced? The invariant: the aggregate must equal the sum over *distinct* valid contributors, and each element must be individually valid (nonzero, unique key/index) before it affects state. Check that:
- Dedupe happens before aggregation, keyed on the contributing identity (inferer, address, index).
- Per-element checks reject zero, not just the total (`amount != 0` alongside `sum == msg.value`).
- Index counters advance exactly once per accepted entry.
- Validation-phase checks account for all other items in the same bundle, since validation completes for every item before execution begins [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md).

## How finders spotted it
- Traced EntryPoint's two-phase validation/execution loops and saw the paymaster's balance check runs per-op during 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 forecast insertion path and noticed the loop checks only inferer membership, never deduplicating `ForecastElements` before they feed implied-inference math [E2](https://bugbountylibrary.com/r/sherlock%3A2024-06-allora%3AH-1.md).
- Noticed the modulo check passes for 0 and `expectedValue += 0` keeps the `msg.value` equality intact, letting a zero deposit ride alongside a legitimate one [E3](https://bugbountylibrary.com/r/sherlock%3A2024-01-looksrare%3AH-2.md).

## Variants seen
- Duplicate weighted contributions multiplying one actor's influence in aggregation [E2](https://bugbountylibrary.com/r/sherlock%3A2024-06-allora%3AH-1.md).
- Zero-value entries passing modulo/equality checks and duplicating indexes in winner selection [E3](https://bugbountylibrary.com/r/sherlock%3A2024-01-looksrare%3AH-2.md).
- Per-item balance checks that ignore other items in the same batch, over-committing funds [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md).

## Impact and severity
Attacker-controlled skew of aggregate results: arbitrary forecast-implied inference values [E2](https://bugbountylibrary.com/r/sherlock%3A2024-06-allora%3AH-1.md), corrupted winner selection in a deposit game [E3](https://bugbountylibrary.com/r/sherlock%3A2024-01-looksrare%3AH-2.md), and postOp reverts / failed withdrawals when batched ops exceed balance [E1](https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md). Severity rises with how directly the skewed aggregate drives payouts or governance outcomes and whether the entry point is unauthenticated [E2](https://bugbountylibrary.com/r/sherlock%3A2024-06-allora%3AH-1.md).

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-03-coinbase%3AM-01.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2024-06-allora%3AH-1.md
- E3: https://bugbountylibrary.com/r/sherlock%3A2024-01-looksrare%3AH-2.md
