https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/TokenManager.sol#L113
The addTokenBalance
function in the TokenManager
contract not only lacks critical validation checks for its parameters but also emits events even when no balance modification occurs. This can lead to misleading transaction logs and potential discrepancies in the contract's state representation. The absence of proper validation and conditional event emission poses risks to the integrity and transparency of the token management system.
In the addTokenBalance
function, the parameters are not validated before being used. Specifically:
_tokenBalanceType: The function does not validate whether this is a valid TokenBalanceType that the system recognizes.
_accountAddress: The function does not check whether the _accountAddress is a valid, non-zero address. This could lead to the assignment of balances to the zero address or unintended addresses, which can be a critical issue in token management.
_tokenAddress: There is no validation to ensure that _tokenAddress is a whitelisted or supported token. This could allow unauthorized or unsupported tokens to be added to the system.
_amount: The function does not check whether the _amount is a positive value, nor does it validate that the addition does not overflow the user's balance.
Without validation, balances can be added to incorrect or unauthorized addresses, or with incorrect token types, leading to inconsistencies in the token balance tracking system. Attackers could exploit the lack of validation to manipulate token balances, potentially causing financial losses or system instability.
Also it emits an AddTokenBalance
event regardless of whether the token balance was actually modified. This can happen even if the _amount
is zero or if the balance addition is redundant (e.g., adding zero tokens). Emitting events when no state change has occurred can mislead users or developers who rely on event logs for tracking the state of the contract. It can create an illusion of activity or changes where none actually took place.
Users may end up with incorrect token balances due to the lack of validation, affecting the integrity of the system. The system could inadvertently add tokens that are not whitelisted or supported, leading to potential issues in token management. The absence of validation opens up avenues for exploitation by attackers who might add unauthorized balances or manipulate existing ones.
The logs could indicate that balances have been updated when they haven't, leading to potential confusion or misinterpretation of the contract's activity. Also the practice of emitting events without corresponding state changes can reduce the transparency and reliability of the contract's operation, making it more challenging to debug or audit.
Manual Review
Add proper validation for these parameteres in order to avoid any type of mishap.
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.