# Inverted or wrong comparison guards

Check comparison direction and operands in guards; valid ops reverting or invalid passing

_Area: DeFi accounting and math bugs. Seen in 5 disclosed reports; latest 2025-03-05. Updated 2026-10-23._

## How it works
A guard encodes a rule ("revert if already claimed", "revert if below margin", "revert if allowance remains") but the comparison direction, operand, or the state it reads is wrong. The rule the code enforces is not the rule intended, so either every valid call reverts or an invalid one passes. The root assumption that breaks: that the guard's condition matches the revert's stated meaning and the state it checks is the state that actually matters.

## Where it shows up
- Revert messages like `AlreadyClaimed`, `AlreadyClaimedMoreThanThis`, `insufficient`, `notZero` — verify the condition matches the words.
- `>=` vs `<=` in claim/withdraw/repay guards [E4](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AH-11.md).
- Guards applied to a path that does not change the state they protect (pure repayment, zero-collateral removal) [E5](https://bugbountylibrary.com/r/sherlock%3A2022-11-isomorph%3AH-1.md).
- `assert(x == 0)` after calls that legitimately leave residue (allowances, dust) [E3](https://bugbountylibrary.com/r/sherlock%3A2024-03-zivoe%3AM-2.md).
- Reset/increase functions that reuse a decrease-oriented check [E2](https://bugbountylibrary.com/r/sherlock%3A2025-03-symm-io-stacking%3AM-3.md).
- Exit conditions that check one thing (a child exists) while the economic invariant depends on another (stake amount) [E1](https://bugbountylibrary.com/r/c4%3A2024-05-arbitrum-foundation%3AH-01.md).

## How to review
For each guard, state the invariant in words, then confirm the code reverts exactly when the invariant is violated and passes otherwise. Check: does the comparison direction match the message [E4](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AH-11.md)? Is the guard on a path that actually changes the protected quantity [E5](https://bugbountylibrary.com/r/sherlock%3A2022-11-isomorph%3AH-1.md)? Does an increase path reuse a decrease check [E2](https://bugbountylibrary.com/r/sherlock%3A2025-03-symm-io-stacking%3AM-3.md)? Are post-call asserts guaranteed by the call's semantics, or only usually true [E3](https://bugbountylibrary.com/r/sherlock%3A2024-03-zivoe%3AM-2.md)? For parameter-dependent exits, does the exit condition read the same snapshot the payout uses [E1](https://bugbountylibrary.com/r/c4%3A2024-05-arbitrum-foundation%3AH-01.md)?

## Variants seen
- Inverted claim guard blocks all claims [E4](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AH-11.md).
- Margin check wrongly applied to repayment-only path [E5](https://bugbountylibrary.com/r/sherlock%3A2022-11-isomorph%3AH-1.md).
- Allowance-zero assert fails on slippage-minimum calls [E3](https://bugbountylibrary.com/r/sherlock%3A2024-03-zivoe%3AM-2.md).
- Reset check reverts valid locked-amount increases [E2](https://bugbountylibrary.com/r/sherlock%3A2025-03-symm-io-stacking%3AM-3.md).
- Exit checks child existence, not stake amount, after config decrease [E1](https://bugbountylibrary.com/r/c4%3A2024-05-arbitrum-foundation%3AH-01.md).

## Impact and severity
Permanent loss of claimable principal [E4](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AH-11.md), locked funds and forced default near liquidation [E5](https://bugbountylibrary.com/r/sherlock%3A2022-11-isomorph%3AH-1.md), blocked liquidity provision [E3](https://bugbountylibrary.com/r/sherlock%3A2024-03-zivoe%3AM-2.md), blocked deposits [E2](https://bugbountylibrary.com/r/sherlock%3A2025-03-symm-io-stacking%3AM-3.md), and insolvency enabling stake arbitrage [E1](https://bugbountylibrary.com/r/c4%3A2024-05-arbitrum-foundation%3AH-01.md). Worse when the guard sits on the only exit path or when a parameter change shifts the economics the guard assumed.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-05-arbitrum-foundation%3AH-01.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2025-03-symm-io-stacking%3AM-3.md
- E3: https://bugbountylibrary.com/r/sherlock%3A2024-03-zivoe%3AM-2.md
- E4: https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AH-11.md
- E5: https://bugbountylibrary.com/r/sherlock%3A2022-11-isomorph%3AH-1.md
