`oracleSlippagePercentOrLimit` can exceed the `Constants.SLIPPAGE_LIMIT_PRECISION`
The function that executes trades only checks the slippage limit when dynamic slippage is enabled, so a trade without dynamic slippage can use an arbitrarily large slippage value. An attacker could cause a trade to settle with excessive slippage, leading to a loss of assets.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-notional-judging/issues/19
Found by
xiaoming90
Summary
Trade might be settled with a large slippage causing a loss of assets as the oracleSlippagePercentOrLimit limit is not bounded and can exceed the Constants.SLIPPAGE_LIMIT_PRECISION threshold.
Vulnerability Detail
The code at Line 73-75 only checks if the oracleSlippagePercentOrLimit is within the Constants.SLIPPAGE_LIMIT_PRECISION if useDynamicSlippage is true. If the trade is performed without dynamic slippage, the trade can be executed with an arbitrary limit.
File: StrategyUtils.sol
62: function _executeTradeExactIn(
63: TradeParams memory params,
64: ITradingModule tradingModule,
65: address sellToken,
66: address buyToken,
67: uint256 amount,
68: bool useDynamicSlippage
69: ) internal returns (uint256 amountSold, uint256 amountBought) {
70: require(
71: params.tradeType == TradeType.EXACT_IN_SINGLE || params.tradeType == TradeType.EXACT_IN_BATCH
72: );
73: if (useDynamicSlippage) {
74: require(params.oracleSlippagePercentOrLimit <= Constants.SLIPPAGE_LIMIT_PRECISION);
75: }
76:
77: // Sell residual secondary balance
78: Trade memory trade = Trade(
79: params.tradeType,
80: sellToken,
81: buyToken,
82: amount,
83: useDynamicSlippage ? 0 : params.oracleSlippagePercentOrLimit,
84: block.timestamp, // deadline
85: params.exchangeData
86: );
The StrategyUtils._executeTradeExactIn function is utilized by the Curve Vault.
Impact
Trade might be settled with a large slippage causing a loss of assets.
Code Snippet
Tool used
Manual Review
Recommendation
Consider restricting the slippage limit when a trade is executed without dynamic slippage.
function _executeTradeExactIn(
TradeParams memory params,
ITradingModule tradingModule,
address sellToken,
address buyToken,
uint256 amount,
bool useDynamicSlippage
) internal returns (uint256 amountSold, uint256 amountBought) {
require(
params.tradeType == TradeType.EXACT_IN_SINGLE || params.tradeType == TradeType.EXACT_IN_BATCH
);
if (useDynamicSlippage) {
require(params.oracleSlippagePercentOrLimit <= Constants.SLIPPAGE_LIMIT_PRECISION);
- }
+ } else {
+ require(params.oracleSlippagePercentOrLimit != 0 && params.oracleSlippagePercentOrLimit <= Constants.SLIPPAGE_LIMIT_PRECISION_FOR_NON_DYNAMIC_TRADE);
+ }
Discussion
jeffywu
Valid, I agree with the intent in this issue although I'm not sure if the proposed solution is workable. We don't have guardrails against this method being called with dynamicSlippage set to false by a non-authenticated account from an internal code perspective. We should consider some sort of internal check to ensure that this is the case.
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 slippage limit check is only applied when dynamic slippage is enabled, leaving the non-dynamic path without any bound on the slippage value.
Impact
Trades could be settled with a large slippage, causing a loss of assets.
What the attacker needed
Trade executed without dynamic slippage
The fix
The slippage limit should also be restricted when a trade is executed without dynamic slippage.
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 trading on a decentralised exchange, slippage is the difference between the expected price and the actual price you get. If slippage is set too high, you might sell your tokens for much less than they are worth. This code only checks that the slippage is not too high when a certain feature is turned on, so someone could set a very high slippage when that feature is off and lose funds.
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.