Sandwich Attack Vulnerability in AmirX::stablecoinSwap function
Summary
The AmirX contract is vulnerable to sandwich attacks during stablecoin swaps and DeFi swap operations, potentially allowing attackers to exploit the order of transactions for profit.
Vulnerability Detail
The stablecoinSwap function in the AmirX contract facilitates stablecoin swaps and triggers DeFi swap operations based on the provided StablecoinSwap and DefiSwap structs. However, this function lacks proper safeguards against sandwich attacks, making it susceptible to front-running and back-running attacks by malicious actors.
function stablecoinSwap(
address wallet,
address safe,
StablecoinSwap memory ss,
DefiSwap memory defi
) external payable onlyRole(SWAPPER_ROLE) {
// checks if it will fail
_verifyStablecoin(wallet, safe, ss, defi);
//eXYZ ot eXYZ
if (isXYZ(ss.origin) && isXYZ(ss.target)) {
swapAndSend(wallet, ss);
return;
}
//stablecoin swap
if (isXYZ(ss.origin) && !isXYZ(ss.target))
convertFromEXYZ(wallet, safe, ss);
//defi swap
uint256 iBalance = ERC20(ss.origin).balanceOf(wallet);
if (defi.walletData.length != 0) defiSwap(wallet, safe, defi);
uint256 fBalance = ERC20(ss.origin).balanceOf(wallet);
// //stablecoin swap
if (!isXYZ(ss.origin) && isXYZ(ss.target)) {
if (fBalance - iBalance != 0) ss.oAmount = fBalance - iBalance;
convertToEXYZ(wallet, safe, ss);
}
}
Impact
Attacker is able to exploit user transactions for profit, potentially resulting in significant financial losses for users executing stablecoin swaps or DeFi swap operations through the AmirX contract.
Allow users to specify a maximum allowed slippage for their swaps, reverting transactions if the slippage exceeds the specified threshold due to front-running.
Implement measures to minimize the predictability of transaction ordering, such as using commit-reveal schemes.
cheatcode
medium
Sandwich Attack Vulnerability in AmirX::stablecoinSwap function
Summary
The
AmirX
contract is vulnerable to sandwich attacks during stablecoin swaps and DeFi swap operations, potentially allowing attackers to exploit the order of transactions for profit.Vulnerability Detail
The
stablecoinSwap
function in theAmirX
contract facilitates stablecoin swaps and triggers DeFi swap operations based on the providedStablecoinSwap
andDefiSwap
structs. However, this function lacks proper safeguards against sandwich attacks, making it susceptible to front-running and back-running attacks by malicious actors.Impact
Attacker is able to exploit user transactions for profit, potentially resulting in significant financial losses for users executing stablecoin swaps or DeFi swap operations through the
AmirX
contract.Code Snippet
https://github.com/sherlock-audit/2024-02-telcoin-platform-audit-update/blob/main/telcoin-contracts/contracts/swap/AmirX.sol#L66
Tool used
Manual Review
Recommendation
Allow users to specify a maximum allowed slippage for their swaps, reverting transactions if the slippage exceeds the specified threshold due to front-running.
Implement measures to minimize the predictability of transaction ordering, such as using commit-reveal schemes.