Skip to content
Business logic Audit finding Intermediate

When Convex pool is shut down while collateral type is CurveLPStakedOnConvex , users unable to deposit that asset and protocol lose the ability to accept the asset as collateral further

When a Convex pool for a collateral asset is shut down, the vault's deposit function always reverts because it tries to stake the LP token on Convex, so users can no longer deposit that asset and the protocol cannot accept it as collateral. Existing users may also face liquidation risk if the staking flag is not reset.

0xComfyCat Follow

Originally disclosed on Code4rena

Submitted by 0xComfyCat

https://github.com/code-423n4/2023-07-amphora/blob/main/core/solidity/contracts/core/VaultController.sol#L376-L412 https://github.com/code-423n4/2023-07-amphora/blob/main/core/solidity/contracts/core/Vault.sol#L93-L105 https://github.com/code-423n4/2023-07-amphora/blob/main/core/solidity/contracts/core/Vault.sol#L111-L133 https://github.com/code-423n4/2023-07-amphora/blob/main/core/solidity/contracts/core/VaultController.sol#L676-L679

When Convex pool of an asset that has CurveLPStakedOnConvex collateral type is shut down, users can no longer deposit that asset into vault since it would always revert on Convex booster deposit function, called during vault’s depositERC20 process. With lack of method to update it, protocol would the ability to accept it as collateral even as plain LP without staking. Also users that use the asset as collateral may face risk of being liquidated. This is also applicable when Convex itself shutdown their booster contract.

Proof of Concept

Based on project’s e2e test, extending CommonE2EBase contract. The test showed that depositERC20 is bricked when Convex pool is shut down.

import {CommonE2EBase} from '@test/e2e/Common.sol';

import {IERC20} from 'isolmate/interfaces/tokens/IERC20.sol';
import {IVault} from '@interfaces/core/IVault.sol';

interface IBoosterAdmin {
  function poolManager() external view returns (address);
  function shutdownPool(uint256 _pid) external;
}

contract VaultCollateralTypeVulnPoC is CommonE2EBase {
  function setUp() public override {
    super.setUp();
  }

  function testCannotDepositWhenConvexPoolIsShutDown() public {
    // Prepare Convex LP for user
    deal(USDT_LP_ADDRESS, bob, 2 ether);

    // User mints vault
    IVault bobVault = IVault(vaultController.vaultIdVaultAddress(_mintVault(bob)));

    // User deposit Convex LP to vault
    vm.startPrank(bob);
    IERC20(USDT_LP_ADDRESS).approve(address(bobVault), 1 ether);
    bobVault.depositERC20(USDT_LP_ADDRESS, 1 ether);
    vm.stopPrank();

    // Convex pool of the asset is shut down
    vm.prank(IBoosterAdmin(address(BOOSTER)).poolManager());
    IBoosterAdmin(address(BOOSTER)).shutdownPool(1);

    // User can no longer deposit that LP to vault
    vm.startPrank(bob);
    IERC20(USDT_LP_ADDRESS).approve(address(bobVault), 1 ether);
    vm.expectRevert('pool is closed');
    bobVault.depositERC20(USDT_LP_ADDRESS, 1 ether);
    vm.stopPrank();
  }
}

Tools Used

Foundry

Recommended Mitigation Steps

The fix requires 2 modifications

  1. Allow updating collateral type to Single and pool id to 0 when pool or booster contract is shutting down. By updating collateral type to Single during depositERC20 deposit to Convex would be skipped. Updating pool id to 0 prevents users from staking it manually.
      function updateRegisteredErc20(
        address _tokenAddress,
        uint256 _ltv,
        address _oracleAddress,
        uint256 _liquidationIncentive,
        uint256 _cap,
        uint256 _poolId,
        bool _shutdown
      ) external override onlyOwner {
        ...
        if (_poolId != 0) {
          (address _lpToken,,, address _crvRewards,,) = BOOSTER.poolInfo(_poolId);
          if (_lpToken != _tokenAddress) revert VaultController_TokenAddressDoesNotMatchLpAddress();
          _collateral.collateralType = CollateralType.CurveLPStakedOnConvex;
          _collateral.crvRewardsContract = IBaseRewardPool(_crvRewards);
          _collateral.poolId = _poolId;
        } else if (_shutdown) {
          (,,,,,bool _isPoolShutdown) = BOOSTER.poolInfo(_poolId);
          if (!_isPoolShutdown || !BOOSTER.isShutdown()) revert VaultController_NotShutdown();
          _collateral.collateralType = CollateralType.Single;
          // keep `crvRewardsContract` for withdrawal
          _collateral.poolId = 0;
        }
        ...
      }
  1. Update vault’s withdrawERC20 to update state variable isTokenStaked to false when withdraw all of that asset. This is important because if the asset is deposited again without actually being staked but isTokenStaked is still true, the vault will not be liquidated due to trying to withdraw while nothing is staked.

Failed liquidation if state is not reflected correctly

  function liquidateVault(
    ...
  ) external override paysInterest whenNotPaused returns (uint256 _toLiquidate) {
    ...
    // withdraw from convex
    CollateralInfo memory _assetInfo = tokenAddressCollateralInfo[_assetAddress];
    // @audit if the flag is not updated accordingly this would fail
    if (_vault.isTokenStaked(_assetAddress)) {
      _vault.controllerWithdrawAndUnwrap(_assetInfo.crvRewardsContract, _tokensToLiquidate);
    }
    ...
  }

The fix

  function withdrawERC20(address _tokenAddress, uint256 _amount) external override onlyMinter {
    ...
    if (isTokenStaked[_tokenAddress]) {
      if (!CONTROLLER.tokenCrvRewardsContract(_tokenAddress).withdrawAndUnwrap(_amount, false)) {
        revert Vault_WithdrawAndUnstakeOnConvexFailed();
        // @audit if withdraw all, reset flag to false
      } else if (_amount == balances[_tokenAddress]) {
        isTokenStaked[_tokenAddress] = false;
      }
    }
    ...
  }

0xShaito (Amphora) disagreed with severity and commented:

While true, this needs the action of a third party (convex) and is not an attack that someone can do. We consider this to be of medium severity.

User deposits are also safe in case this happens but the collateral gets bricked for new deposits.

LSDan (judge) decreased severity to Medium and commented:

I agree with the sponsor here. Medium is more appropriate. There are clear external factors.

0xShaito (Amphora) confirmed


The original report as published on Code4rena, by 0xComfyCat. 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

Root cause

The deposit logic always attempts to stake the LP token on Convex when the collateral type is CurveLPStakedOnConvex, with no fallback or update mechanism if the Convex pool is shut down.

Impact

Users cannot deposit the affected asset, the protocol loses the ability to accept it as collateral, and existing users may face liquidation risk if the staking flag is not reset; the sponsor notes user deposits are safe but the collateral is bricked for new deposits.

What the attacker needed

Convex pool or booster is shut down; asset uses CurveLPStakedOnConvex type

The fix

The report recommends allowing the owner to update the collateral type to Single and pool id to 0 when the pool or booster is shut down, and resetting the isTokenStaked flag when all of the asset is withdrawn.

How it was found

  1. A user deposits a Convex LP token into their vault.
  2. The Convex pool for that asset is shut down by its pool manager.
  3. The user tries to deposit more of the same LP token.
  4. The deposit reverts with 'pool is closed'.

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.

This is a smart contract bug in a lending protocol. The protocol lets people deposit a special token that represents a stake in a third-party pool (Convex). If that third-party pool is shut down, the deposit code still tries to stake the token there, which fails, so nobody can deposit that token any more. The protocol also has no way to switch the token to a simpler mode, so it loses the ability to accept it as collateral.

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 from Amphora Protocol

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.