The PerpetualVault.sol contract's _doDexSwap() function lacks slippage protection mechanisms, making keeper-initiated swaps vulnerable to sandwich attacks.
In the PerpetualVault.sol contract, the _doDexSwap() function executes token swaps through Paraswap without implementing any slippage tolerance checks. The function is triggered when keepers invoke run() (for leverage) or runNextAction().
The critical issue lies in the swap execution logic:
Without slippage protection, malicious actors can observe keeper transactions in the mempool and execute sandwich attacks by manipulating the token prices before and after the swap.
High severity. Attackers can extract value from the protocol through sandwich attacks on keeper-initiated swaps, leading to direct financial losses.
Manual Review, Code Analysis
Implement slippage protection in the _doDexSwap() function by adding a minimum output amount check
Consider using a price oracle to validate swap rates
Add a configurable slippage tolerance parameter that can be adjusted based on market conditions
Slippage and deadline are handled externally. Paraswap implementation used by the current code (behind the proxy): https://etherscan.io/address/0xdffd706ee98953d3d25a3b8440e34e3a2c9beb2c GMX code: https://github.com/gmx-io/gmx-synthetics/blob/caf3dd8b51ad9ad27b0a399f668e3016fd2c14df/contracts/order/OrderUtils.sol#L150C15-L150C33
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.