A vulnerability has been identified in the TokenDivider
contract where transferring ERC20 tokens directly using the transfer
method of the ERC20 contract can lead to inconsistencies in the token balances maintained by the TokenDivider
contract. This issue arises because the TokenDivider
contract does not intercept or account for direct ERC20 transfers, leading to potential discrepancies in the recorded balances.
TokenDivider
contract is designed to manage the division and transfer of NFTs into ERC20 tokens. It maintains a mapping
called balances
to track the ERC20 token balances of users. The contract provides a method transferErcTokens
to securely transfer these tokens and update the balances
mapping accordingly.However, users can still transfer ERC20 tokens directly using the transfer
method of the ERC20 contract. When this happens, the TokenDivider
contract is not aware of the transfer, and the balances
mapping is not updated. This can lead to a situation where the TokenDivider
contract's recorded balances do not match the actual balances of the ERC20 tokens, causing inconsistencies and potential security issues.
Setup: Deploy the TokenDivider
contract and an ERC20 token contract.
Divide NFT: Use the divideNft
method to divide an NFT into ERC20 tokens.
Direct Transfer: Transfer the ERC20 tokens directly using the transfer
method of the ERC20 contract.
Check Balances: Compare the balances recorded in the TokenDivider
contract with the actual balances of the ERC20 tokens.
Here is an example of how the vulnerability can be exploited:
The impact of this vulnerability is significant as it can lead to:
Inconsistent Balances: The TokenDivider
contract's recorded balances may not match the actual ERC20 token balances.
Security Risks: Users may exploit this inconsistency to manipulate balances and withdraw more tokens than they actually own.
Operational Issues: Functions that rely on the balances
mapping for validation may fail or behave unexpectedly.
manual review, github copilote
To mitigate this vulnerability, consider the following approaches:
Restrict Direct Transfers: Modify the ERC20 contract to restrict direct transfers and only allow transfers through the TokenDivider
contract.
Intercept Transfers: Implement a mechanism in the TokenDivider
contract to intercept and handle direct ERC20 transfers, ensuring the balances
mapping is updated accordingly.
Here is an example of how to restrict direct transfers in the ERC20 contract:
By implementing these changes, you can ensure that all ERC20 token transfers are properly accounted for in the TokenDivider
contract, maintaining consistency and security
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.