# Checked subtraction underflow locks funds

Subtractions where the subtrahend can exceed the minuend, reverting settlement, withdrawal or liquidation paths

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

## How it works
A path subtracts one quantity from another assuming the minuend is always at least as large. When the subtrahend grows independently (accrued interest, a time-prorated vesting amount, a fee-growth delta that is legitimately negative, a counter decremented twice), it can exceed the minuend. Under checked arithmetic (Solidity 0.8, Rust `checked_sub`) the subtraction reverts, hard-DoSing that path and stranding funds or positions. Under wrapping arithmetic it produces a huge value and silently corrupts accounting. The root cause is a broken invariant: nothing guarantees minuend >= subtrahend in every reachable state. Which arithmetic mode is in force decides the impact class per report: checked means a revert/DoS, wrapping means silent corruption.

## Where it shows up
- A value subtracted at settlement that was added at a different time or rate (interest-accruing debt vs fixed bid escrow) [E3](https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-04.md).
- Ports of Uniswap-style math where a subtraction was designed to wrap (fee growth, seconds-per-liquidity) now run under checked arithmetic [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-17.md)[E2](https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AH-04.md)[E5](https://bugbountylibrary.com/r/c4%3A2023-12-particle%3AH-04.md).
- Time-prorated vesting/queued amounts subtracted from a live balance [E6](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md).
- A shared counter decremented in a delete path that can be re-triggered on the same entity [E4](https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-6.md).
- Grep for `unchecked`, `checked_sub`, `subUint`, reset/delete functions, and any `a - b` where `b` accrues over time.

## How to review
For every subtraction, name the invariant that guarantees minuend >= subtrahend and confirm it holds in all reachable states. Check the subtracted quantity equals the quantity added earlier (same source, same rounding, same accrual): e.g. bid escrow must subtract the bid, not interest-inflated debt [E3](https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-04.md). For ports, verify whether the original relied on wrapping [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-17.md)[E2](https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AH-04.md)[E5](https://bugbountylibrary.com/r/c4%3A2023-12-particle%3AH-04.md). Audit every `unchecked` block for user-controlled subtrahends. For delete paths, confirm the delete cannot be re-triggered on the same entity [E4](https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-6.md).

## Variants seen
- Wrapping math ported to checked arithmetic [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-17.md)[E2](https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AH-04.md)[E5](https://bugbountylibrary.com/r/c4%3A2023-12-particle%3AH-04.md).
- Interest-accruing debt vs fixed bid escrow [E3](https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-04.md).
- Re-triggerable delete driving a shared counter to zero [E4](https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-6.md).
- Vesting subtraction below live balance; compound report also covers dual-tolerance extraction, unrelated to underflow [E6](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md).

## Impact and severity
Locks LP positions and liquidated NFTs, blocks withdrawals and fee collection, and can permanently freeze settlement [E1](https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-17.md)[E2](https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AH-04.md)[E3](https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-04.md)[E6](https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md). Severity is high where the revert blocks liquidation or withdrawal permanently; worse when the failing branch silently skips a penalty or strands user funds. Attacker-triggerable cases (re-funding a canceled order [E4](https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-6.md)) raise severity because the lock can be induced on demand.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2023-05-maia%3AH-17.md
- E2: https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AH-04.md
- E3: https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-04.md
- E4: https://bugbountylibrary.com/r/sherlock%3A2024-10-debita%3AM-6.md
- E5: https://bugbountylibrary.com/r/c4%3A2023-12-particle%3AH-04.md
- E6: https://bugbountylibrary.com/r/dhl%3A20260414-saturnprotocol.md
- E7: https://bugbountylibrary.com/r/cantina%3Aaquarius_aug2025%3A3.2.5.md
- E8: https://bugbountylibrary.com/r/cantina%3Acircuit_puzzles%3A3.3.4.md
