Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token transfer' does not handle case if the tokens support fee-on-transfer #2093

Open
codehawks-bot opened this issue Aug 8, 2023 · 0 comments

Comments

@codehawks-bot
Copy link

Token transfer' does not handle case if the tokens support fee-on-transfer

Severity

Medium Risk

Relevant GitHub Links

IERC20(p.loanToken).transferFrom(

IERC20(pools[poolId].loanToken).transferFrom(

Summary

Some tokens take a transfer fee (e.g. STA, PAXG), some do not currently charge a fee but may do so in the future (e.g. USDT, USDC).

Vulnerability Details

While transfer of loan token, In the current implementation, it is assumed that the received amount is the same as the transfer amount. However, due to how fee-on-transfer tokens work, much less will be received than what was transferred.

IERC20(p.loanToken).transferFrom(
p.lender,
address(this),
p.poolBalance - currentBalance
);

Impact

The impact of such implementation will be on borrow() since the pool balance will be less than the expected which can lead to failure of borrow()

Tools Used

manual reveiw

Recommendations

In order to obtain the actual amount received by the contract, track the balance of
tokens before and after the transfer of tokens. For example, in the contract test, we recommend
implementing the following steps:

function _transfer(uint256 amount) public returns(uint256){
uint256 balanceBefore = IERC20(token).balanceOf(address(this));
IERC20Token(token).SafetransferFrom(msg.sender, address(this),amount);

   uint256 balanceAfter = IERC20(token).balanceOf(address(this));
   require(balanceAfter >= balanceBefore);
   return balanceAfter - balanceBefore;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants