# Round-trip loop drains shared reserves

Repeated join/exit or borrow/redeem cycles that net profit from shared liquidity

_Area: DeFi accounting and math bugs. Seen in 2 disclosed reports; latest 2026-06-25. Updated 2026-11-09._

## How it works
A pool or lending contract prices each operation (join, exit, borrow, redeem) as if it were independent. The assumption that breaks is that a single operation's math is safe because it is checked in isolation; the invariant that actually matters is that a full round trip (in then out, or borrow then redeem) must never return more value than it consumed. When the per-operation formulas are asymmetric, or when a cap or accounting variable is mutated proportionally by the same operations it is meant to constrain, each loop iteration leaves a small surplus behind. Repeat it and the surplus compounds against shared reserves [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md)[E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md)[E3](https://bugbountylibrary.com/r/dhl%3A20240314-mo.md).

## Where it shows up
- Single-sided join/exit paths (`joinswapExternAmountIn`, `exitswapPoolAmountIn`) whose in and out formulas are not exact inverses [E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md)
- A cap or limit stored in a state variable that LP add/remove also writes, especially when liquidity is distributed proportionally to one ratio before another [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md)
- Auto-mirroring hooks: a pool that stakes/unstakes into a second contract on every join/exit, plus a `gulp()`/sync that pulls stale reserves [E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md)
- Lending functions where borrow and redeem can both run in one transaction with no cooldown or per-block state guard [E3](https://bugbountylibrary.com/r/dhl%3A20240314-mo.md)
- Rounding that always favors the user on one leg and the pool on the other

## How to review
State the invariant explicitly: for any sequence of operations starting and ending in the same asset, the caller's balance must not increase. Then check:
- Are join and exit formulas exact inverses for single-sided, max-size amounts? Compute a round trip by hand.
- Does any capped variable get updated by the same user-callable operations it caps? If so, can small repeated calls converge it to a favorable ratio [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md)?
- Does any hook read reserves that another call can leave stale (`gulp`)? Is the mirrored stake recomputed from fresh state [E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md)?
- Can borrow and redeem both execute in one transaction, and does each update all accounting the other reads [E3](https://bugbountylibrary.com/r/dhl%3A20240314-mo.md)?

## How finders spotted it
- Read how `ulyssesAddLP`/`ulyssesRemoveLP` distribute liquidity (proportional to diff, then weight) and hypothesized that tiny repeated add/remove cycles drive diff/weight to a constant, making bandwidth proportional to weight and defeating the cap [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md).
- Habit: when a cap lives in a variable that user operations mutate, ask whether small repeated operations converge that variable [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md).
- Discovery method for E2 and E3 is not stated in the evidence; treat the above as the only documented reasoning trail.

## Variants seen
- Cap bypass via proportional rebalancing of a bandwidth/limit variable [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md)
- Asymmetric single-sided AMM join/exit math amplified by an auto-mirroring staking hook and stale-reserve sync [E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md)
- Lending borrow/redeem loop with flawed order accounting [E3](https://bugbountylibrary.com/r/dhl%3A20240314-mo.md)

## Impact and severity
High to critical: near-total pool drain [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md), ~127.86K mOCEAN across 8 pools [E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md), ~413K USDT [E3](https://bugbountylibrary.com/r/dhl%3A20240314-mo.md). Impact scales with loop count and pool count; flash liquidity removes capital requirements [E2](https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md), and repeating the cycle scales extraction until reserves are exhausted [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md).

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-20.md
- E2: https://bugbountylibrary.com/r/dhl%3A20260625-oceanbpoolsidestaking.md
- E3: https://bugbountylibrary.com/r/dhl%3A20240314-mo.md
