The TokenDivider
contract does not safely handle ERC20 token transfers in multiple functions. The code assumes that token transfers will always succeed without considering potential failures due to non-standard ERC20 implementations or other issues.
Several instances in the contract fail to properly handle the return value of the transfer
and transferFrom
functions of ERC20 tokens. This could lead to situations where token transfers fail silently without reverting, resulting in inconsistencies in balances and potentially lost funds.
Affected Functions:
transferErcTokens
The IERC20(tokenInfo.erc20Address).transferFrom(msg.sender, to, amount)
call does not check the success of the token transfer.
sellErc20
The IERC20(tokenInfo.erc20Address).transferFrom(msg.sender, address(this), amount)
call does not check the success of the token transfer.
buyOrder
The IERC20(order.erc20Address).transfer(msg.sender, order.amount)
call does not validate the success of the token transfer.
Failure to handle the return value of transfer
and transferFrom
in non-standard ERC20 tokens can lead to:
Silent Failures: Transfers might fail without reverting, leaving the contract in an inconsistent state.
Lost Tokens: Users could lose funds or tokens due to unhandled transfer failures.
Manual code review.
To mitigate this issue you can do two things:
Check Return Values: Always validate the return value of transfer
and transferFrom
calls to ensure token transfers are successful. For example:
Use OpenZeppelin's SafeERC20
Library: This library wraps ERC20 functions and automatically handles both return value checks and compatibility with non-standard ERC20 implementations.
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.