Skip to content
Business logic Audit finding Intermediate

Slippage/Minimum amount does not work during single-side redemption

The vault automatically computes the minimum amount for single-sided redemptions using a proportional share of the pool, which is much lower than the actual expected output. An attacker could exploit this to cause the vault to accept significant slippage, resulting in losses for vault shareholders.

xiaoming90 Follow

Originally disclosed on Sherlock

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

Found by

xiaoming90

Summary

The slippage or minimum amount of tokens to be received is set to a value much smaller than expected due to the use of TwoTokenPoolUtils._getMinExitAmounts function to automatically compute the slippage or minimum amount on behalf of the callers during a single-sided redemption. As a result, the vault will continue to redeem the pool tokens even if the trade incurs significant slippage, resulting in the vault receiving fewer tokens in return, leading to losses for the vault shareholders.

Vulnerability Detail

The Curve2TokenConvexHelper._executeSettlement function is called by the following functions:

  • Curve2TokenConvexHelper.settleVault
    • Curve2TokenConvexHelper.settleVault function is called within the Curve2TokenConvexVault.settleVaultNormal and Curve2TokenConvexVault.settleVaultPostMaturity functions
  • Curve2TokenConvexHelper.settleVaultEmergency
    • Curve2TokenConvexHelper.settleVaultEmergency is called by Curve2TokenConvexVault.settleVaultEmergency

In summary, the Curve2TokenConvexHelper._executeSettlement function is called during vault settlement.

An important point to note here is that within the Curve2TokenConvexHelper._executeSettlement function, the params.minPrimary and params.minSecondary are automatically computed and overwritten by the TwoTokenPoolUtils._getMinExitAmounts function (Refer to Line 124 below). Therefore, if the caller attempts to define the params.minPrimary and params.minSecondary, they will be discarded and overwritten. The params.minPrimary and params.minSecondary is for slippage control when redeeming the Curve's LP tokens.

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/vaults/curve/external/Curve2TokenConvexHelper.sol#L112

Solidity
File: Curve2TokenConvexHelper.sol
112:     function _executeSettlement(
113:         StrategyContext calldata strategyContext,
114:         Curve2TokenPoolContext calldata poolContext,
115:         uint256 maturity,
116:         uint256 poolClaimToSettle,
117:         uint256 redeemStrategyTokenAmount,
118:         RedeemParams memory params
119:     ) private {
120:         (uint256 spotPrice, uint256 oraclePrice) = poolContext._getSpotPriceAndOraclePrice(strategyContext);
121: 
122:         /// @notice params.minPrimary and params.minSecondary are not required to be passed in by the caller
123:         /// for this strategy vault
124:         (params.minPrimary, params.minSecondary) = poolContext.basePool._getMinExitAmounts({
125:             strategyContext: strategyContext,
126:             oraclePrice: oraclePrice,
127:             spotPrice: spotPrice,
128:             poolClaim: poolClaimToSettle
129:         });

The TwoTokenPoolUtils._getMinExitAmounts function calculates the minimum amount on the share of the pool with a small discount.

Assume a Curve Pool with the following configuration:

  • Consist of two tokens (DAI and USDC). DAI is primary token, USDC is secondary token.
  • Pool holds 200 US Dollars worth of tokens (50 DAI and 150 USDC).
  • DAI <> USDC price is 1:1
  • totalSupply = 100 LP Pool Tokens

Assume that 50 LP Pool Tokens will be claimed during vault settlement.

Solidity
minPrimary = (poolContext.primaryBalance * poolClaim * strategyContext.vaultSettings.poolSlippageLimitPercent /  (totalPoolSupply * uint256(VaultConstants.VAULT_PERCENT_BASIS)
minPrimary = (50 DAI * 50 LP_TOKEN * 99.75% /  (100 LP_TOKEN * 100%)

Rewrite for clarity (ignoring rounding error):
minPrimary = 50 DAI * (50 LP_TOKEN/100 LP_TOKEN) * (99.75%/100%) = 24.9375 DAI

minSecondary = same calculation = 74.8125 USDC

TwoTokenPoolUtils._getMinExitAmounts function will return 24.9375 DAI as params.minPrimary and 74.8125 USDC as params.minSecondary.

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/vaults/common/internal/pool/TwoTokenPoolUtils.sol#L48

Solidity
File: TwoTokenPoolUtils.sol
46:     /// @notice calculates the expected primary and secondary amounts based on
47:     /// the given spot price and oracle price
48:     function _getMinExitAmounts(
49:         TwoTokenPoolContext calldata poolContext,
50:         StrategyContext calldata strategyContext,
51:         uint256 spotPrice,
52:         uint256 oraclePrice,
53:         uint256 poolClaim
54:     ) internal view returns (uint256 minPrimary, uint256 minSecondary) {
55:         strategyContext._checkPriceLimit(oraclePrice, spotPrice);
56: 
57:         // min amounts are calculated based on the share of the Balancer pool with a small discount applied
58:         uint256 totalPoolSupply = poolContext.poolToken.totalSupply();
59:         minPrimary = (poolContext.primaryBalance * poolClaim * 
60:             strategyContext.vaultSettings.poolSlippageLimitPercent) / 
61:             (totalPoolSupply * uint256(VaultConstants.VAULT_PERCENT_BASIS));
62:         minSecondary = (poolContext.secondaryBalance * poolClaim * 
63:             strategyContext.vaultSettings.poolSlippageLimitPercent) / 
64:             (totalPoolSupply * uint256(VaultConstants.VAULT_PERCENT_BASIS));
65:     }

When settling the vault, it is possible to instruct the vault to redeem the Curve's LP tokens single-sided or proportionally. Settle vault functions will trigger a chain of functions that will eventually call the Curve2TokenConvexHelper._unstakeAndExitPool function that is responsible for redeeming the Curve's LP tokens.

Within the Curve2TokenConvexHelper._unstakeAndExitPool function, if the params.secondaryTradeParams.length is zero, the redemption will be single-sided (refer to Line 242 below). Otherwise, the redemption will be executed proportionally (refer to Line 247 below). For a single-sided redemption, only the params.minPrimary will be used.

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/vaults/curve/internal/pool/Curve2TokenPoolUtils.sol#L231

Solidity
File: Curve2TokenPoolUtils.sol
231:     function _unstakeAndExitPool(
232:         Curve2TokenPoolContext memory poolContext,
233:         ConvexStakingContext memory stakingContext,
234:         uint256 poolClaim,
235:         RedeemParams memory params
236:     ) internal returns (uint256 primaryBalance, uint256 secondaryBalance) {
237:         // Withdraw pool tokens back to the vault for redemption
238:         bool success = stakingContext.rewardPool.withdrawAndUnwrap(poolClaim, false); // claimRewards = false
239:         if (!success) revert Errors.UnstakeFailed();
240: 
241:         if (params.secondaryTradeParams.length == 0) {
242:             // Redeem single-sided
243:             primaryBalance = ICurve2TokenPool(address(poolContext.curvePool)).remove_liquidity_one_coin(
244:                 poolClaim, int8(poolContext.basePool.primaryIndex), params.minPrimary
245:             );
246:         } else {
247:             // Redeem proportionally
248:             uint256[2] memory minAmounts;
249:             minAmounts[poolContext.basePool.primaryIndex] = params.minPrimary;
250:             minAmounts[poolContext.basePool.secondaryIndex] = params.minSecondary;
251:             uint256[2] memory exitBalances = ICurve2TokenPool(address(poolContext.curvePool)).remove_liquidity(
252:                 poolClaim, minAmounts
253:             );
254: 
255:             (primaryBalance, secondaryBalance) 
256:                 = (exitBalances[poolContext.basePool.primaryIndex], exitBalances[poolContext.basePool.secondaryIndex]);
257:         }
258:     }

Assume that the caller decided to perform a single-sided redemption of 50 LP Pool Tokens, using the earlier example. In this case,

  • poolClaim = 50 LP Pool Tokens
  • params.minPrimary = 24.9375 DAI
  • params.minSecondary = 74.8125 USDC

The data passed into the remove_liquidity_one_coin will be as follows:

Python
@notice Withdraw a single coin from the pool
@param _token_amount Amount of LP tokens to burn in the withdrawal
@param i Index value of the coin to withdraw
@param _min_amount Minimum amount of coin to receive
@return Amount of coin received
def remove_liquidity_one_coin(
    _token_amount: uint256,
    i: int128,
    _min_amount: uint256
) -> uint256:
Solidity
remove_liquidity_one_coin(poolClaim, int8(poolContext.basePool.primaryIndex), params.minPrimary);
remove_liquidity_one_coin(50 LP_TOKEN, Index 0=DAI, 24.9375 DAI);

Assume the pool holds 200 US dollars worth of tokens (50 DAI and 150 USDC), and the total supply is 100 LP Tokens. The pool's state is imbalanced, so any trade will result in significant slippage.

Intuitively (ignoring the slippage & fee), redeeming 50 LP Tokens should return approximately 100 US dollars worth of tokens, which means around 100 DAI. Thus, the slippage or minimum amount should ideally be around 100 DAI (+/- 5%).

However, the trade will be executed in the above example even if the vault receives only 25 DAI because the params.minPrimary is set to 24.9375 DAI. This could result in a loss of around 75 DAI due to slippage (about 75% slippage rate) in the worst-case scenario.

Impact

The slippage or minimum amount of tokens to be received is set to a value much smaller than expected. Thus, the vault will continue to redeem the pool tokens even if the trade incurs significant slippage, resulting in the vault receiving fewer tokens in return, leading to losses for the vault shareholders.

Code Snippet

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/vaults/curve/external/Curve2TokenConvexHelper.sol#L112

Tool used

Manual Review

Recommendation

When performing a single-side redemption, avoid using the TwoTokenPoolUtils._getMinExitAmounts function to automatically compute the slippage or minimum amount of tokens to receive on behalf of the caller. Instead, give the caller the flexibility to define the slippage (params.minPrimary). To prevent the caller from setting a slippage that is too large, consider restricting the slippage to an acceptable range.

The proper way of computing the minimum amount of tokens to receive from a single-side trade (remove_liquidity_one_coin) is to call the Curve Pool's calc_withdraw_one_coin function off-chain to calculate the amount received when withdrawing a single LP Token, and then apply an acceptable discount.

Note that the calc_withdraw_one_coin function cannot be used solely on-chain for computing the minimum amount because the result can be manipulated since it uses spot balances for computation.

Discussion

jeffywu

Valid, similar issue to #12 but for the remove_liquidity_one_coin method.

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

The vault uses a proportional share calculation to set the minimum amount for single-sided redemptions, which does not account for the actual expected output of a single-sided trade.

Impact

The vault may accept significant slippage during single-sided redemptions, leading to losses for vault shareholders.

What the attacker needed

Vault settlement with single-sided redemption

The fix

The caller should be allowed to set the minimum amount for single-sided redemptions, with restrictions to prevent excessive slippage, and the minimum should be computed using the Curve pool's `calc_withdraw_one_coin` function off-chain.

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 you take your money out of a shared pool, you set a minimum amount you're willing to accept to avoid getting ripped off by price changes. Here, the vault automatically sets that minimum too low, so it can accept a bad trade and lose money for everyone in the vault.

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 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.

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.