Incorrect Decoding of Swap Results Leads to Ineffective Slippage Protection #154
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
🤖_primary
AI based primary recommendation
🤖_14_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-08-superposition/blob/4528c9d2dbe1550d2660dac903a8246076044905/pkg/sol/SeawaterAMM.sol#L316
https://github.com/code-423n4/2024-08-superposition/blob/4528c9d2dbe1550d2660dac903a8246076044905/pkg/sol/SeawaterAMM.sol#L316
https://github.com/code-423n4/2024-08-superposition/blob/4528c9d2dbe1550d2660dac903a8246076044905/pkg/seawater/src/lib.rs#L194
Vulnerability details
The
swapOut5E08A399()
andswapOutPermit23273373B()
functions in theSeawaterAMM
contract incorrectly decode the results of a swap operation, leading to ineffective slippage protection. This issue arises from a mismatch between the swap direction and the order of decoded values.In both functions, a swap is executed with
zeroForOne
set tofalse
, indicating a swap from token1 to token0. However, when decoding the swap results, the order ofswapAmountIn
andswapAmountOut
is reversed, causing the slippage check to be performed on the wrong value. This is because the functionswap904369BE
returnsamount0, amount1
so is the caller which should interpret which corresponds to token in and token out. This incorrect decoding leads to a situation where the slippage protection is not applied as intended, potentially exposing users to unexpected losses.Impact
Users may receive fewer tokens than expected without the transaction reverting, leading to financial losses. This issue could be exploited by malicious actors to manipulate swap outcomes to their advantage.
Proof of Concept
swapOut5E08A399()
orswapOutPermit23273373B()
to swap token1 for token0.zeroForOne
set tofalse
.swapAmountOut
, which actually contains the input amount.Tools Used
Manual review
Recommended Mitigation Steps
Correct the decoding of swap results in both
swapOut5E08A399()
andswapOutPermit23273373B()
functions.Assessed type
Other
The text was updated successfully, but these errors were encountered: