Skip to content
Business logic Audit finding Intermediate

ConvexStakingWrapper.exitShelter() Will Lock LP Tokens, Preventing Users From Withdrawing

The exitShelter function transfers LP tokens back to the ConvexStakingWrapper contract but does not restake them in the pool. As a result, users cannot withdraw their LP tokens because the withdraw function attempts to unstake tokens that are no longer staked, causing a revert and locking funds.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

The shelter mechanism provides emergency functionality in an effort to protect users’ funds. The enterShelter function will withdraw all LP tokens from the pool, transfer them to the shelter contract and activate the shelter for the target LP token. Conversely, the exitShelter function will deactivate the shelter and transfer all LP tokens back to the ConvexStakingWrapper.sol contract.

Unfortunately, LP tokens aren’t restaked in the pool, causing LP tokens to be stuck within the contract. Users will be unable to withdraw their LP tokens as the withdraw function attempts to withdrawAndUnwrap LP tokens from the staking pool. As a result, this function will always revert due to insufficient staked balance. If other users decide to deposit their LP tokens, then these tokens can be swiped by users who have had their LP tokens locked in the contract.

This guarantees poor UX for the protocol and will most definitely lead to LP token loss.

Proof of Concept

ConvexStakingWrapper.sol#L121-L130

function exitShelter(uint256[] calldata _pids) external onlyOwner {
    for(uint256 i = 0; i<_pids.length; i++){
        IRewardStaking pool = IRewardStaking(convexPool[_pids[i]]);
        IERC20 lpToken = IERC20(
            pool.poolInfo(_pids[i]).lptoken
        );
        amountInShelter[lpToken] = 0;
        shelter.deactivate(lpToken);
    }
}

ConvexStakingWrapper.sol#L309-L331

function withdraw(uint256 _pid, uint256 _amount)
    external
    nonReentrant
    whenNotInShelter(_pid)
{
    WithdrawRequest memory request = withdrawRequest[_pid][msg.sender];
    require(request.epoch < currentEpoch() && deposits[_pid][msg.sender].epoch + 1 < currentEpoch(), "wait");
    require(request.amount >= _amount, "too much");
    _checkpoint(_pid, msg.sender);
    deposits[_pid][msg.sender].amount -= uint192(_amount);
    if (_amount > 0) {
        IRewardStaking(convexPool[_pid]).withdrawAndUnwrap(_amount, false);
        IERC20 lpToken = IERC20(
            IRewardStaking(convexPool[_pid]).poolInfo(_pid).lptoken
        );
        lpToken.safeTransfer(msg.sender, _amount);
        uint256 pid = masterChef.pid(address(lpToken));
        masterChef.withdraw(msg.sender, pid, _amount);
    }
    delete withdrawRequest[_pid][msg.sender];
    //events
    emit Withdrawn(msg.sender, _amount);
}

Tools Used

Manual code review. Confirmation from Taek.

Recommended Mitigation Steps

Consider re-depositing LP tokens upon calling exitShelter. This should ensure the same tokens can be reclaimed by users wishing to exit the ConvexStakingWrapper.sol contract.

leekt (Concur) confirmed

Alex the Entreprenerd (judge) commented:

The warden has identified how through a combination of using the shelter and sending funds back, the funds would actually end up being stuck and non-withdrawable by depositors.

I believe that generally speaking this would be a Medium Severity finding as the funds would be stuck if the sponsor were to activate the shelter and then send the tokens back (conditionality).

However, the warden has shown that the system of Contract + Shelter is effectively broken, and for this reason I believe the finding is of High Severity.


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

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

Impact

Users cannot withdraw their LP tokens, and if other users deposit, the locked tokens can be taken by them, leading to LP token loss.

What the attacker needed

Owner activates shelter then exits shelter; User attempts to withdraw LP tokens

The fix

The exitShelter function should re-deposit the LP tokens into the staking pool after transferring them back from the shelter.

How it was found

  1. The owner calls enterShelter, which withdraws all LP tokens from the pool and transfers them to the shelter contract.
  2. The owner calls exitShelter, which deactivates the shelter and transfers LP tokens back to the ConvexStakingWrapper contract.
  3. The LP tokens are not restaked in the pool.
  4. A user calls withdraw, which attempts to withdrawAndUnwrap LP tokens from the staking pool.
  5. The withdraw function reverts due to insufficient staked balance, locking the user's LP tokens.

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.

When users deposit tokens into a pool, those tokens are staked to earn rewards. The shelter is an emergency feature that moves tokens to a separate contract. When the shelter is turned off, the tokens are moved back but not re-staked, so the system thinks they are still staked. When a user tries to withdraw, the system tries to unstake tokens that aren't there, and the withdrawal fails, leaving the tokens stuck.

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 leastwood

View all

70 more disclosed reports, best first.

More from Concur Finance contest

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.