Skip to content
Business logic Audit finding Intermediate

Oracle slippage rate is used for checking primary and secondary ratio

The oracle slippage setting is reused to check the ratio of primary and secondary tokens deposited into a pool, which is unrelated to oracle prices. Changing this setting can unexpectedly break the reinvestReward function under certain conditions.

xiaoming90 Follow

Originally disclosed on Sherlock

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

Found by

xiaoming90

Summary

The oracle slippage rate (oraclePriceDeviationLimitPercent) is used for checking the ratio of the primary and secondary tokens to be deposited into the pool.

As a result, changing the oraclePriceDeviationLimitPercent setting to increase or decrease the allowable slippage between the spot and oracle prices can cause unexpected side-effects to the _checkPrimarySecondaryRatio function, which might break the reinvestReward function that relies on the _checkPrimarySecondaryRatio function under certain condition.

Vulnerability Detail

The _checkPriceLimit function is for the purpose of comparing the spot price with the oracle price. Thus, the slippage (oraclePriceDeviationLimitPercent) is specially selected for this purpose.

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/vaults/common/internal/strategy/StrategyUtils.sol#L21

Solidity
File: StrategyUtils.sol
21:     function _checkPriceLimit(
22:         StrategyContext memory strategyContext,
23:         uint256 oraclePrice,
24:         uint256 poolPrice
25:     ) internal pure {
26:         uint256 lowerLimit = (oraclePrice * 
27:             (VaultConstants.VAULT_PERCENT_BASIS - strategyContext.vaultSettings.oraclePriceDeviationLimitPercent)) / 
28:             VaultConstants.VAULT_PERCENT_BASIS;
29:         uint256 upperLimit = (oraclePrice * 
30:             (VaultConstants.VAULT_PERCENT_BASIS + strategyContext.vaultSettings.oraclePriceDeviationLimitPercent)) / 
31:             VaultConstants.VAULT_PERCENT_BASIS;
32: 
33:         if (poolPrice < lowerLimit || upperLimit < poolPrice) {
34:             revert Errors.InvalidPrice(oraclePrice, poolPrice);
35:         }
36:     }

However, it was observed that _checkPriceLimit function is repurposed for checking if the ratio of the primary and secondary tokens to be deposited to the pool is more or less proportional to the pool's balances within the _checkPrimarySecondaryRatio function during reinvestment.

The oraclePriceDeviationLimitPercent setting should not be used here as it does not involve any oracle data. Thus, the correct way is to define another setting specifically for checking if the ratio of the primary and secondary tokens to be deposited to the pool is more or less proportional to the pool's balances.

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

Solidity
File: Curve2TokenPoolUtils.sol
147:     function _checkPrimarySecondaryRatio(
148:         StrategyContext memory strategyContext,
149:         uint256 primaryAmount, 
150:         uint256 secondaryAmount, 
151:         uint256 primaryPoolBalance, 
152:         uint256 secondaryPoolBalance
153:     ) private pure {
154:         uint256 totalAmount = primaryAmount + secondaryAmount;
155:         uint256 totalPoolBalance = primaryPoolBalance + secondaryPoolBalance;
156: 
157:         uint256 primaryPercentage = primaryAmount * CurveConstants.CURVE_PRECISION / totalAmount;        
158:         uint256 expectedPrimaryPercentage = primaryPoolBalance * CurveConstants.CURVE_PRECISION / totalPoolBalance;
159: 
160:         strategyContext._checkPriceLimit(expectedPrimaryPercentage, primaryPercentage);
161: 
162:         uint256 secondaryPercentage = secondaryAmount * CurveConstants.CURVE_PRECISION / totalAmount;
163:         uint256 expectedSecondaryPercentage = secondaryPoolBalance * CurveConstants.CURVE_PRECISION / totalPoolBalance;
164: 
165:         strategyContext._checkPriceLimit(expectedSecondaryPercentage, secondaryPercentage);
166:     }

Impact

Changing the oraclePriceDeviationLimitPercent setting to increase or decrease the allowable slippage between the spot price and oracle price can cause unexpected side-effects to the _checkPrimarySecondaryRatio function, which might break the reinvestReward function that relies on the _checkPrimarySecondaryRatio function under certain condition.

Additionally, the value chosen for the oraclePriceDeviationLimitPercent is to compare the spot price with the oracle price. Thus, it might not be the optimal value for checking if the ratio of the primary and secondary tokens deposited to the pool is more or less proportional to the pool's balances.

Code Snippet

https://github.com/sherlock-audit/2023-02-notional/blob/main/leveraged-vaults/contracts/vaults/common/internal/strategy/StrategyUtils.sol#L21

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

Tool used

Manual Review

Recommendation

There is a difference between the slippage for the following two items:

  • Allowable slippage between the spot price and oracle price
  • Allowable slippage between the ratio of the primary and secondary tokens to be deposited to the pool against the pool's balances

Since they serve a different purposes, they should not share the same slippage. Consider defining a separate slippage setting and function for checking if the ratio of the primary and secondary tokens deposited to the pool is more or less proportional to the pool's balances.

Discussion

jeffywu

Valid, should add a second setting here.

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 same slippage setting is reused for two unrelated checks: comparing spot and oracle prices, and comparing deposit ratios to pool balances.

Impact

Changing the oracle slippage setting could cause the reinvestReward function to break under certain conditions, and the chosen value may not be optimal for the ratio check.

What the attacker needed

None

The fix

A separate slippage setting and function should be defined for checking the ratio of primary and secondary tokens against pool balances.

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 smart contract uses one setting meant for comparing prices to also check whether token amounts are balanced. If that setting is changed, the balance check can fail and stop a reward reinvestment function from working.

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.