Need for Buffer in Spot Price Validation During AMM Swaps
Summary
The _ammSwap function in the smart contract strictly validates that the new spot price after a swap does not exactly hit the upper or lower bounds of the permitted price range. This rigid check can lead to unnecessary transaction rejections in volatile markets where spot prices might briefly touch these boundaries.
Vulnerability Detail
In the smart contract, after performing a swap, the resulting new spot price (sqrtSpotPriceX96New) is checked against the low (sqrtPriceLowX96Cache) and high (sqrtPriceHighX96Cache) price bounds. If the new spot price is exactly equal to either boundary, the transaction is reverted. This strict equality check does not account for minor fluctuations that are common in highly volatile trading environments, potentially leading to failed transactions even under normal trading conditions.
Impact
Increased Transaction Failures: Users may experience increased transaction failures during normal market volatility, leading to frustration and potential financial losses due to missed trading opportunities.
Reduced Market Efficiency: Strict spot price checks can prevent the execution of legitimate trades, reducing the overall efficiency and fluidity of the market operations on the platform.
Implement a small buffer or tolerance around the low and high price bounds. This would allow for slight deviations in the spot price without causing a transaction to revert.
example ->
uint160 buffer = 5; // This can be adjusted based on further analysis if (sqrtSpotPriceX96New <= (sqrtPriceLowX96Cache + buffer) || sqrtSpotPriceX96New >= (sqrtPriceHighX96Cache - buffer)) { revert HOT___ammSwap_invalidSpotPriceAfterSwap(); }
0xrobsol
medium
Need for Buffer in Spot Price Validation During AMM Swaps
Summary
The _ammSwap function in the smart contract strictly validates that the new spot price after a swap does not exactly hit the upper or lower bounds of the permitted price range. This rigid check can lead to unnecessary transaction rejections in volatile markets where spot prices might briefly touch these boundaries.
Vulnerability Detail
In the smart contract, after performing a swap, the resulting new spot price (sqrtSpotPriceX96New) is checked against the low (sqrtPriceLowX96Cache) and high (sqrtPriceHighX96Cache) price bounds. If the new spot price is exactly equal to either boundary, the transaction is reverted. This strict equality check does not account for minor fluctuations that are common in highly volatile trading environments, potentially leading to failed transactions even under normal trading conditions.
Impact
Code Snippet
https://github.com/sherlock-audit/2024-03-arrakis/blob/main/valantis-hot/src/HOT.sol#L868-L871
Tool used
Manual Review
Recommendation
Implement a small buffer or tolerance around the low and high price bounds. This would allow for slight deviations in the spot price without causing a transaction to revert. example ->
uint160 buffer = 5; // This can be adjusted based on further analysis if (sqrtSpotPriceX96New <= (sqrtPriceLowX96Cache + buffer) || sqrtSpotPriceX96New >= (sqrtPriceHighX96Cache - buffer)) { revert HOT___ammSwap_invalidSpotPriceAfterSwap(); }