# Unsigned underflow reverts settlement

Subtractions on balances, weights or losses that can go negative and revert or wrap

_Area: DeFi accounting and math bugs. Seen in 6 disclosed reports; latest 2026-04-14. Updated 2026-10-29._

## How it works
A subtraction assumes the left operand is always at least the right one. When that assumption breaks — a loss exceeds a stored balance, a stored snapshot is newer than the value it is subtracted from, a prover-supplied byte exceeds the remaining value, or a library designed for wrapping math is compiled with checked arithmetic — the result goes negative. In Solidity 0.8 this reverts (panic 0x11); in Cairo field arithmetic it wraps to a huge value and the loop continues [E1](https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-02.md). Either way, the operation that depended on it (close, withdraw, liquidate, borrow) fails or produces forged output.

## Where to show up
- Unsigned balance/weight variables subtracted against realized losses or accrued rewards [E4](https://bugbountylibrary.com/r/sherlock%3A2023-08-symmetrical%3AM-2.md)[E5](https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.5.md)
- Two solvency or bonus computations using different collateral semantics (per-token vs cross-total) [E6](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-01.md)
- Vendored libraries (FullMath, Uniswap V3) whose pragma was bumped to ^0.8.x despite relying on phantom overflow [E2](https://bugbountylibrary.com/r/c4%3A2023-08-goodentry%3AH-06.md)
- Time-prorated vesting/earmark amounts subtracted from a live balance [E3](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md)[E5](https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.5.md)
- Prover/hint-supplied values used in loops without range-checking against remaining state [E1](https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-02.md)
- State variables assigned the latest snapshot in a branch that computed from a historical one [E5](https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.5.md)

## How to review
For every subtraction, identify the invariant that guarantees `a >= b` in all reachable states, not just the happy path. Check that the branch computing a value and the branch storing the accumulator use the same snapshot [E5](https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.5.md). Confirm solvency/bonus paths share one collateral definition [E6](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-01.md). Diff vendored library pragmas against upstream [E2](https://bugbountylibrary.com/r/c4%3A2023-08-goodentry%3AH-06.md). For Cairo loops, verify each hint value is range-checked before subtraction [E1](https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-02.md). The property: no reachable state drives an unsigned operand below zero, and any wrapping is intentional and bounded.

## Variants seen
- Field-prime underflow in Cairo loop lets prover forge bytes [E1](https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-02.md)
- Checked arithmetic added to phantom-overflow library freezes assets [E2](https://bugbountylibrary.com/r/c4%3A2023-08-goodentry%3AH-06.md)
- Unsigned per-position loss applied to shared balance blocks closure [E4](https://bugbountylibrary.com/r/sherlock%3A2023-08-symmetrical%3AM-2.md)
- Snapshot/latest mismatch in weight accrual underflows next sync [E5](https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.5.md)
- Mismatched solvency semantics underflow liquidation bonus [E6](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-01.md)
- Vesting subtraction underflow freezes withdrawals [E3](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md)

## Impact and severity
Led to permanent freezing of deposits/withdrawals [E2](https://bugbountylibrary.com/r/c4%3A2023-08-goodentry%3AH-06.md)[E3](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md), locked positions [E4](https://bugbountylibrary.com/r/sherlock%3A2023-08-symmetrical%3AM-2.md), blocked liquidations leaving insolvent accounts unliquidatable [E6](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-01.md), and forged addresses [E1](https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-02.md). Severity rises when the revert is on a settlement or liquidation path with no alternate exit, and when combined with a second flaw (dual tolerance) enabling extraction [E3](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md).

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-02.md
- E2: https://bugbountylibrary.com/r/c4%3A2023-08-goodentry%3AH-06.md
- E3: https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md
- E4: https://bugbountylibrary.com/r/sherlock%3A2023-08-symmetrical%3AM-2.md
- E5: https://bugbountylibrary.com/r/cantina%3Aalchemix_may2025%3A3.1.5.md
- E6: https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-01.md
