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
This part of the code is inside the swap function, which is responsible for handling both DeFi and stablecoin swaps.
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;
this line captures the initial balance of the user's ss.origin token (the token the user is going to swap from) before any operation happens. It does this by calling the balanceOf function
if (defi.walletData.length != 0) _defiSwap(wallet, defi);
If there is a DeFi swap, the function _defiSwap(wallet, defi) is called
After performing the DeFi swap this line captures the final balance of ss.origin token after the swap. The idea is to check how the balance has changed as a result of the operation
This line calculates the difference between the final balance (fBalance) and the initial balance (iBalance). This difference represents the amount of tokens spent or received due to the DeFi swap
If the balance has changed (i.e., fBalance - iBalance != 0), it adjusts the amount. The oAmount represents the current balance of the wallet however the code assumes that fbalance (received amount) which can be wronf and if the initial balance every exceeds this code will fail to capture the users balance
loss of funds for users if balance ever exceeds received amount as the code will fail to capture the latest balance
PoC
No response
Mitigation
remove the check check if the amount received is more than initial balance
The text was updated successfully, but these errors were encountered:
sherlock-admin3
changed the title
Brave Gingham Orangutan - incorrect assumption can be problematic
nikhilx0111 - incorrect assumption can be problematic
Nov 17, 2024
nikhilx0111
High
incorrect assumption can be problematic
Summary
This part of the code is inside the swap function, which is responsible for handling both DeFi and stablecoin swaps.
this line captures the initial balance of the user's ss.origin token (the token the user is going to swap from) before any operation happens. It does this by calling the balanceOf function
If there is a DeFi swap, the function _defiSwap(wallet, defi) is called
After performing the DeFi swap this line captures the final balance of ss.origin token after the swap. The idea is to check how the balance has changed as a result of the operation
This line calculates the difference between the final balance (fBalance) and the initial balance (iBalance). This difference represents the amount of tokens spent or received due to the DeFi swap
If the balance has changed (i.e., fBalance - iBalance != 0), it adjusts the amount. The oAmount represents the current balance of the wallet however the code assumes that fbalance (received amount) which can be wronf and if the initial balance every exceeds this code will fail to capture the users balance
Root Cause
https://github.com/sherlock-audit/2024-11-telcoin/blob/b9c751b59e78a7123a636e31ecafc9147046f190/telcoin-audit/contracts/swap/AmirX.sol#L93
Internal pre-conditions
balance exceeds received amount
External pre-conditions
No response
Attack Path
No response
Impact
loss of funds for users if balance ever exceeds received amount as the code will fail to capture the latest balance
PoC
No response
Mitigation
remove the check check if the amount received is more than initial balance
The text was updated successfully, but these errors were encountered: