Skip to content
Access control Audit finding Advanced

Risk of reward tokens being sold by malicious users under certain conditions

The Curve adaptors in the Notional leveraged vaults do not validate the token route for batch trades, allowing a malicious user to swap out reward tokens or Convex deposit tokens held by the vault under certain conditions. This could potentially drain assets from the vault if reward tokens equal primary/secondary tokens or if another exploit is found.

xiaoming90 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-notional-judging/issues/13

Found by

xiaoming90

Summary

Due to the lack of validation of the selling token within the Curve adaptors, there is a risk that the reward tokens or Convex deposit tokens of the vault being sold by malicious users under certain conditions (e.g. if reward tokens equal to primary/secondary tokens OR a new exploit is found in other parts of the code).

Vulnerability Detail

For a EXACT_IN_SINGLE trade within the Curve adaptors, the from and to addresses of the exchange function are explicitly set to trade.sellToken and trade.buyToken respectively. Thus, the swap is restricted to only trade.sellToken and trade.buyToken, which points to either the primary or secondary token of the pool. This prevents other tokens that reside in the vault from being swapped out.

However, this measure was not applied to the EXACT_IN_BATCH trade as it ignores the trade.sellToken and trade.buyToken , and allow the caller to define arbitrary data.route where the first route (_route[0]) and last route (_route[last_index]) could be any token.

The vault will hold the reward tokens (CRV, CVX, LDO) when the vault administrator claims the rewards or a malicious user claims the rewards on behalf of the vault by calling Convex's getReward function.

Assume that attacker is faster than the admin calling the reinvest function. There is a possibility that an attacker executes a EXACT_IN_BATCH trade and specifies the _route[0] as one of the reward tokens residing on the vault and swaps away the reward tokens during depositing (_tradePrimaryForSecondary) or redemption (_sellSecondaryBalance). In addition, an attacker could also sell away the Convex deposit tokens if a new exploit is found.

In addition, the vault also holds Convex deposit tokens, which represent assets held by the vault.

This issue affects the in-scope CurveV2Adapter and CurveAdapter since they do not validate the data.route provided by the users.

CurveV2Adapter

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/trading/adapters/CurveV2Adapter.sol#L37

Solidity
File: CurveV2Adapter.sol
37:     function getExecutionData(address from, Trade calldata trade)
38:         internal view returns (
39:             address spender,
40:             address target,
41:             uint256 msgValue,
42:             bytes memory executionCallData
43:         )
44:     {
45:         if (trade.tradeType == TradeType.EXACT_IN_SINGLE) {
46:             CurveV2SingleData memory data = abi.decode(trade.exchangeData, (CurveV2SingleData));
47:             executionCallData = abi.encodeWithSelector(
48:                 ICurveRouterV2.exchange.selector,
49:                 data.pool,
50:                 _getTokenAddress(trade.sellToken),
51:                 _getTokenAddress(trade.buyToken),
52:                 trade.amount,
53:                 trade.limit,
54:                 address(this)
55:             );
56:         } else if (trade.tradeType == TradeType.EXACT_IN_BATCH) {
57:             CurveV2BatchData memory data = abi.decode(trade.exchangeData, (CurveV2BatchData));
58:             // Array of pools for swaps via zap contracts. This parameter is only needed for
59:             // Polygon meta-factories underlying swaps.
60:             address[4] memory pools;
61:             executionCallData = abi.encodeWithSelector(
62:                 ICurveRouterV2.exchange_multiple.selector,
63:                 data.route,
64:                 data.swapParams,
65:                 trade.amount,
66:                 trade.limit,
67:                 pools,
68:                 address(this)
69:             );

CurveAdapter

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/trading/adapters/CurveAdapter.sol#L66

Solidity
File: CurveAdapter.sol
22:     function _exactInBatch(Trade memory trade) internal view returns (bytes memory executionCallData) {
23:         CurveBatchData memory data = abi.decode(trade.exchangeData, (CurveBatchData));
24: 
25:         return abi.encodeWithSelector(
26:             ICurveRouter.exchange.selector,
27:             trade.amount,
28:             data.route,
29:             data.indices,
30:             trade.limit
31:         );
32:     }

Following are some examples of where this vulnerability could potentially be exploited. Assume a vault that supports the CurveV2's ETH/stETH pool.

  1. Perform the smallest possible redemption to trigger the _sellSecondaryBalance function. Configure the RedeemParams to swap the reward token (CRV, CVX, or LDO) or Convex Deposit token for the primary token (ETH). This will cause the finalPrimaryBalance to increase by the number of incoming primary tokens (ETH), thus inflating the number of primary tokens redeemed.
  2. Perform the smallest possible deposit to trigger the _tradePrimaryForSecondary. Configure DepositTradeParams to swap the reward token (CRV, CVX, or LDO) or Convex Deposit token for the secondary tokens (stETH). This will cause the secondaryAmount to increase by the number of incoming secondary tokens (stETH), thus inflating the number of secondary tokens available for the deposit.

Upon further investigation, it was observed that the vault would only approve the exchange to pull the trade.sellToken, which points to either the primary token (ETH) or secondary token (stETH). Thus, the reward tokens (CRV, CVX, or LDO) or Convex deposit tokens cannot be sent to the exchanges. Thus, the vault will not be affected if none of the reward tokens/Convex Deposit tokens equals the primary or secondary token.

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/trading/TradingUtils.sol#L118

Solidity
File: TradingUtils.sol
115:     /// @notice Approve exchange to pull from this contract
116:     /// @dev approve up to trade.amount for EXACT_IN trades and up to trade.limit
117:     /// for EXACT_OUT trades
118:     function _approve(Trade memory trade, address spender) private {
119:         uint256 allowance = _isExactIn(trade) ? trade.amount : trade.limit;
120:         address sellToken = trade.sellToken;
121:         // approve WETH instead of ETH for ETH trades if
122:         // spender != address(0) (checked by the caller)
123:         if (sellToken == Constants.ETH_ADDRESS) {
124:             sellToken = address(Deployments.WETH);
125:         }
126:         IERC20(sellToken).checkApprove(spender, allowance);
127:     }

However, there might be some Curve Pools or Convex's reward contracts whose reward tokens are similar to the primary or secondary tokens of the vault. If the vault supports those pools, the vault will be vulnerable. In addition, the reward tokens of a Curve pool or Convex's reward contracts are not immutable. It is possible for the governance to add a new reward token that might be the same as the primary or secondary token.

Impact

There is a risk that the reward tokens or Convex deposit tokens of the vault are sold by malicious users under certain conditions (e.g. if reward tokens are equal to primary/secondary tokens OR a new exploit is found in other parts of the code), thus potentially draining assets from the vault.

Code Snippet

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/trading/adapters/CurveV2Adapter.sol#L37

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/trading/adapters/CurveAdapter.sol#L66

Tool used

Manual Review

Recommendation

It is recommended to implement additional checks when performing a EXACT_IN_BATCH trade with the CurveV2Adapter or CurveAdapter adaptor. The first item in the route must be the trade.sellToken, and the last item in the route must be the trade.buyToken. This will restrict the trade.sellToken to the primary or secondary token, and prevent reward and Convex Deposit tokens from being sold (Assuming primary/secondary token != reward tokens).

Solidity
route[0] == trade.sellToken
route[last index] == trade.buyToken

The vault holds many Convex Deposit tokens (e.g. cvxsteCRV). A risk analysis of the vault shows that the worst thing that could happen is that all the Convex Deposit tokens are swapped away if a new exploit is found, which would drain the entire vault. For defense-in-depth, it is recommended to check that the selling token is not a Convex Deposit token under any circumstance when using the trade adaptor.

The trade adaptors are one of the attack vectors that the attacker could potentially use to move tokens out of the vault if any exploit is found. Thus, they should be locked down or restricted where possible.

Alternatively, consider removing the EXACT_IN_BATCH trade function from the affected adaptors to reduce the attack surface if the security risk of this feature outweighs the benefit of the batch function.

Discussion

jeffywu

Valid, agree that require checks needed here. @weitianjie2000, also review that the other adapters have similar require checks for batch trades.

The original report as published on Sherlock, by xiaoming90. 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 batch trade functions in the Curve adaptors fail to validate that the first and last tokens in the user-supplied route match the intended sell and buy tokens, allowing arbitrary tokens to be swapped.

Impact

There is a risk that reward tokens or Convex deposit tokens could be sold by malicious users under certain conditions, potentially draining assets from the vault; however, the vault only approves the sellToken, so the vault is not affected if reward tokens do not equal primary or secondary tokens.

What the attacker needed

Vault holds reward tokens or Convex deposit tokens; reward tokens equal primary or secondary tokens; or a new exploit is found

The fix

It is recommended to implement additional checks when performing a `EXACT_IN_BATCH` trade with the `CurveV2Adapter` or `CurveAdapter` adaptor, requiring that the first item in the route is the `trade.sellToken` and the last item is the `trade.buyToken`.

How it was found

  1. Perform the smallest possible redemption to trigger the `_sellSecondaryBalance` function.
  2. Configure the `RedeemParams` to swap the reward token (CRV, CVX, or LDO) or Convex Deposit token for the primary token (ETH).
  3. This will cause the `finalPrimaryBalance` to increase by the number of incoming primary tokens (ETH), thus inflating the number of primary tokens redeemed.
  4. Perform the smallest possible deposit to trigger the `_tradePrimaryForSecondary`.
  5. Configure `DepositTradeParams` to swap the reward token (CRV, CVX, or LDO) or Convex Deposit token for the secondary tokens (stETH).
  6. This will cause the `secondaryAmount` to increase by the number of incoming secondary tokens (stETH), thus inflating the number of secondary tokens available for the deposit.

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.

A vault is a smart contract that holds and manages users' funds. The vault uses external exchanges (Curve) to swap tokens, and it approves only specific tokens to be swapped. However, for batch trades, the code does not check which tokens are being swapped, so an attacker could trick the vault into swapping other valuable tokens it holds, like rewards. This could lead to loss of funds.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by xiaoming90

View all

122 more disclosed reports, best first.

More from Notional Update #4

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.