# Wrong-token and wrong-delta balance accounting

Balance deltas or token flows inferred from user input, approved amounts, or a different token than the one measured

_Area: DeFi accounting and math bugs. Seen in 3 disclosed reports; latest 2025-02-18. Updated 2026-11-09._

## How it works
A contract needs to know how much of an asset moved. Instead of measuring it, it infers it: from a user-supplied path or step amount [E1](https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md), from an approved amount rather than the amount actually consumed [E2](https://bugbountylibrary.com/r/cantina%3Adoppler%3A3.1.7.md), or by reading one side of a subtraction from a different token than the other side [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md). The assumption that breaks is that the parameter, approval, or token the code reasons about equals the real balance change. When it doesn't, the contract's bookkeeping drifts from reality and the gap is exploitable or locks funds.

## Where it shows up
- Router/wrapper code that builds `tokensOut` or flow lists from the user's path instead of the router's returned deltas [E1](https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md)
- Batch or multi-step swaps where a later step's amount is trusted without bounding it to the prior step's output [E1](https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md)
- `approve(X)` followed by an initializer, then a balance computed as `totalSupply - X` instead of `balanceOf` [E2](https://bugbountylibrary.com/r/cantina%3Adoppler%3A3.1.7.md)
- Balance-delta code that special-cases native vs wrapped token on one side only [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md)
- Any baseline balance read from an address anyone can send tokens to [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md)

## How to review
For every accounting value, ask: is this measured or inferred? The invariant: any amount credited, locked, or reported must come from an actual balance delta (`balanceOf` before/after) or the router's own returned deltas, never from a user parameter, an approved amount, or a differently-denominated token. Check both sides of every subtraction use the same asset and the same measurement method [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md). Check that approved amounts are reconciled against consumed amounts after the downstream call [E2](https://bugbountylibrary.com/r/cantina%3Adoppler%3A3.1.7.md). Check that intermediate step amounts cannot exceed the previous step's output [E1](https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md).

## How finders spotted it
- Read how `tokensOut` was derived, noticed step amounts could exceed the prior step's output when the user owns and approved those tokens, then confirmed with Foundry [E1](https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md)
- Compared `migrate()`'s balance formula against `create()`'s `approve(numTokensToSell)` and `initialize()`'s consumption, spotting that approved != used [E2](https://bugbountylibrary.com/r/cantina%3Adoppler%3A3.1.7.md)
- Noticed an asymmetry: `initialBalance` used `_getTokenBalance(toToken)` while `finalBalance` special-cased native to read wrapped token [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md)

## Variants seen
- Wrong token in the flow list (first token only) plus trusted user step amounts [E1](https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md)
- Approved amount substituted for consumed amount [E2](https://bugbountylibrary.com/r/cantina%3Adoppler%3A3.1.7.md)
- Mismatched asset between the two sides of a delta, with a donatable baseline [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md)

## Impact and severity
E1 lets a user drain an unaccounted asset using approved tokens. E2 permanently locks unused approved tokens. E3 lets anyone skew `finalOutputAmount` by donating ETH. Severity rises when the wrong value feeds a payout or lock rather than a display, and when an attacker can influence the baseline from outside [E3](https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md).

## Evidence
- E1: https://bugbountylibrary.com/r/sherlock%3A2022-11-sentiment%3AM-3.md
- E2: https://bugbountylibrary.com/r/cantina%3Adoppler%3A3.1.7.md
- E3: https://bugbountylibrary.com/r/c4%3A2021-10-slingshot%3AM-01.md
