# Self-referential price guards

Guards or pricing branches that read the same live pool price or balance they are meant to constrain

_Area: DeFi oracles, liquidations and flash loans. Seen in 3 disclosed reports; latest 2025-08-04. Updated 2026-11-14._

## How it works
A check is supposed to bound an outcome: a minimum output, a spread, a capacity decision. It fails when the reference value it compares against is derived from the same live state the action itself moves or depends on. The guard then measures the thing it is guarding, so it always agrees with itself. The same shape appears when a pricing helper branches on a capacity test but is handed the wrong amount, flipping it into the wrong branch.

## Where it shows up
- Slippage guards where `minOutput`/`minAmountOut` comes from `getAmountsOut` or the same pool quote used for execution [E3](https://bugbountylibrary.com/r/c4%3A2025-04-virtuals-protocol%3AM-06.md)
- Pricing helpers that branch on `poolCanDeposit(amount)` or similar capacity checks [E1](https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md)
- Callers passing a contract-wide balance where a per-user deposit amount is expected [E1](https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md)
- Spread or premium formulas that read current inventory but ignore the incoming order size [E2](https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md)
- Any deviation, min-out or capacity check whose reference is a live spot value

## How to review
For each guard, trace where the reference value comes from. The invariant: the bound must be computed from a source independent of the execution price and of the amount being acted on. Ask:
- Is `minOutput` an independent oracle or a caller-supplied floor, or is it the same `getAmountsOut` the swap uses? If the latter, the guard is vacuous [E3](https://bugbountylibrary.com/r/c4%3A2025-04-virtuals-protocol%3AM-06.md).
- Does the pricing helper receive the user's actual deposit, or the contract's whole balance? A large balance can flip a capacity branch and select a worse price [E1](https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md).
- Does the spread/premium formula take the incoming order amount as an input? If not, order sequencing can reset inventory and bypass it [E2](https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md).
- Does crossing zero exposure get evaluated with the new position in mind, or only the current one? [E2](https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md)

## How finders spotted it
- Read `stake()`'s underlyingValue loop and noticed `ethPerDerivative` was passed `derivatives[i].balance()` rather than the deposit amount, then saw the branch on `poolCanDeposit` of that argument [E1](https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md).
- Noted the order-amount parameter was unused in `_getBasePriceWithSpread`, then reasoned about the zero-crossing case where the Maker thinks it de-risks but accumulates opposite exposure [E2](https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md).
- Saw `minOutput` computed from `getAmountsOut`, the same dynamic spot source used for the swap, making the bound self-referential [E3](https://bugbountylibrary.com/r/c4%3A2025-04-virtuals-protocol%3AM-06.md).

## Variants seen
- Capacity-branch flip: whole-balance argument selects swap-only pool price over the derivative's own oracle [E1](https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md)
- Inventory-only spread: incoming order size omitted, so a reverse-then-open sequence bypasses the premium [E2](https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md)
- Self-referential slippage: min-out derived from the execution spot quote, so it always passes [E3](https://bugbountylibrary.com/r/c4%3A2025-04-virtuals-protocol%3AM-06.md)

## Impact and severity
Depositors received fewer minted shares than deserved [E1](https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md); traders could force oracle-price quotes and bypass the dynamic premium [E2](https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md); treasury swaps accepted any price, exposing funds to sandwiching [E3](https://bugbountylibrary.com/r/c4%3A2025-04-virtuals-protocol%3AM-06.md). Severity rises with the value flowing through the mispriced path and with whether an attacker can trigger the branch or sequencing at will.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AH-02.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2024-02-perpetual%3AM-1.md
- E3: https://bugbountylibrary.com/r/c4%3A2025-04-virtuals-protocol%3AM-06.md
