You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UnderFlow revert in the amirX::swap function because of (fBalance - iBalance) substraction.
summary
The amirX::swap function will revert each time when the value of fBalance is less then iBalance since a swap is performed.
Vulnerability Detail
Since a swap is performed the value of token of a address can be increase or decreased depend on swap.
if the balance decreased (fBalance < IBalance) the below line will cause a underflow revert, becasue the value of a variable cannot be less then 0 in solidity.
##Impact
The underflow revert will cause the contract to not perfrom the intended task of swap function.
##Recommendation
function swap(
address wallet,
bool directional,
StablecoinSwap memory ss,
DefiSwap memory defi
) external payable onlyRole(SWAPPER_ROLE) whenNotPaused {
// checks if it will fail
if (ss.destination != address(0)) _verifyStablecoinSwap(wallet, ss);
if (defi.walletData.length != 0) _verifyDefiSwap(wallet, defi);
if (directional) {
// if only defi swap
if (ss.destination == address(0)) _defiSwap(wallet, defi);
else {
// if defi then stablecoin swap
//check balance to adjust second swap
uint256 iBalance = ERC20(ss.origin).balanceOf(wallet);
if (defi.walletData.length != 0) _defiSwap(wallet, defi);
uint256 fBalance = ERC20(ss.origin).balanceOf(wallet);
//change balance to reflect change
- if (fBalance - iBalance != 0) ss.oAmount = fBalance - iBalance;+ if (fBalance - iBalance != 0){+ ss.oAmount = (fBalance >= iBalance ) ? (fBalance - iBalance) : iBalance - fBalance;+ }
_stablecoinSwap(wallet, ss);
}
} else {
// if stablecoin swap
_stablecoinSwap(wallet, ss);
// if only stablecoin swap
if (defi.walletData.length != 0) _defiSwap(wallet, defi);
}
}
The text was updated successfully, but these errors were encountered:
sherlock-admin3
changed the title
Wobbly Mandarin Raccoon - UnderFlow revert in the amirX::swap function because of (fBalance - iBalance) substraction.
Saurabh_Singh - UnderFlow revert in the amirX::swap function because of (fBalance - iBalance) substraction.
Nov 17, 2024
Saurabh_Singh
Medium
UnderFlow revert in the
amirX::swap
function because of (fBalance - iBalance) substraction.summary
The
amirX::swap
function will revert each time when the value offBalance
is less theniBalance
since a swap is performed.Vulnerability Detail
Since a swap is performed the value of token of a address can be increase or decreased depend on swap.
if the balance decreased (fBalance < IBalance) the below line will cause a underflow revert, becasue the value of a variable cannot be less then 0 in solidity.
https://github.com/sherlock-audit/2024-11-telcoin/blob/main/telcoin-audit/contracts/swap/AmirX.sol#L93
##Impact
The underflow revert will cause the contract to not perfrom the intended task of swap function.
##Recommendation
The text was updated successfully, but these errors were encountered: