sherlock-audit / 2024-03-arrakis-judging

0 stars 0 forks source link

0xrobsol - Need for Buffer in Spot Price Validation During AMM Swaps #70

Closed sherlock-admin2 closed 1 month ago

sherlock-admin2 commented 1 month ago

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(); }