# Incorrect usage of typecasting in _getAmountsForLiquidity lets an attacker steal funds from the pool

Unchecked uint256→uint128 cast in ConcentratedLiquidityPool._getAmountsForLiquidity truncates token amounts, letting an attacker mint huge liquidity for tiny payment and drain the pool.

- Payout: Audit contest
- Severity: high
- Program: Sushi
- Found by: broccoli
- Disclosed: 2021-11-30
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2021-09-sushitrident-2-findings/issues/83
- Library page: https://bugbountylibrary.com/r/c4%3A2021-09-sushitrident-2%3AH-05
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:precision-loss

**Target:** ConcentratedLiquidityPool.mint / DyDxMath.getDy
**Root cause:** Explicit downcast of DyDxMath.getDy/getDx results from uint256 to uint128 without bounds check; values exceeding type(uint128).max silently truncate, understating the tokens owed.
**Steps:**
1. Set current price at tick 500000; call `mint` with lower=100000, upper=500000, amount1Desired=(1<<128)+71914955423, amount0Desired=0.
2. Pool computes `_liquidity = amount1Desired * (1<<96) // (priceUpper - priceLower)` = 4731732988155153573010127840.
3. amount1Actual = `uint128(DyDxMath.getDy(_liquidity, priceLower, priceUpper, true))`; true value 340282366920938463463374607456141861046 exceeds uint128 max and truncates to 24373649590.
4. Attacker pays only 24373649590 token1 but receives 4731732988155153573010127840 liquidity.
5. Burn the liquidity to withdraw more token1 than paid, draining pool funds.
**How found:** Code review of ConcentratedLiquidityPool._getAmountsForLiquidity spotted explicit uint256→uint128 casts on DyDxMath.getDy/getDx results with no overflow check; reasoned that a crafted amountDesired near 2^128 makes the owed amount exceed uint128 max and truncate.
**Exploitation:** Attacker crafts amount1Desired just above 2^128 so the computed token1 owed overflows uint128 and truncates to a tiny value; mints large liquidity cheaply then burns it to extract pool reserves.
**Insight:** In concentrated-liquidity math, audit every explicit downcast of intermediate uint256 results (getDy/getDx) — attacker-controlled amountDesired can push owed amounts past uint128 max so truncation undercharges; check SafeCast usage on all liquidity math.

