sherlock-audit / 2024-01-napier-judging

8 stars 5 forks source link

Rhaydden - Need for Slippage Protection #112

Closed sherlock-admin2 closed 5 months ago

sherlock-admin2 commented 5 months ago

Rhaydden

medium

Need for Slippage Protection

Summary

The lack of explicit slippage protection be it intentional or not in the swapPtForUnderlying and swapUnderlyingForPt functions within the NapierPool.sol makes it vulnerable to significant price changes due to slippage. This issue can lead to unfair transactions.

Vulnerability Detail

The vulnerability lies in the absence of a parameter or condition to limit slippage in the swap functions. Specifically, the swap operations are performed without setting any slippage tolerance or minimum output amount, which makes the swaps susceptible to large price fluctuations.

Impact

The lack of slippage protection can lead to significant financial losses for users, especially in volatile markets. It can also create opportunities for malicious actors to exploit price differences, leading to unfair transactions. Alice a user intends to swap a large amount of tokens at a specific price. Ben, a malicious actor, knowing about this vulnerability, could monitor the transaction and execute a similar swap at a lower price, thereby profiting from the price difference.

Code Snippet

https://github.com/sherlock-audit/2024-01-napier/blob/main/v1-pool/src/NapierPool.sol#L370

https://github.com/sherlock-audit/2024-01-napier/blob/main/v1-pool/src/NapierPool.sol#L433

Both functions are executed without specifying any slippage tolerance, making them vulnerable to large price changes.

Tool used

Manual Review

Recommendation

The smart contract should be modified to include slippage protection parameters for the swap operations. This could involve passing explicit slippage tolerance parameters to the swap functions or setting a minimum output amount that must be met for the swap to be considered successful. Consider adding minimum accepted return argument and condition execution success on it so the caller can control for the realized slippage.

sherlock-admin commented 5 months ago

1 comment(s) were left on this issue during the judging contest.

tsvetanovv commented:

Invalid. We have a slippage check below