Description:
The Bridge.sol::withdrawTokens
function currently lacks a mechanism to detect and prevent duplicate entries in the tokenIds array. This absence of validation allows for the possibility of the same token ID being processed multiple times within a single transaction. The function iterates over the tokenIds array to either withdraw tokens from escrow or mint new tokens, assuming each token ID is unique. If duplicates are present, the function might inadvertently perform multiple operations on the same token, leading to potential issues.
Impact:
Incorrect Token Balances: Processing duplicate tokenIds could result in multiple transfers or mintings of the same token, leading to an incorrect token balance or state within the contract.
Minting Errors: Duplicate entries might cause the contract to attempt minting the same token multiple times, which could lead to minting errors or contract failures, especially if the contract logic does not account for such scenarios.
Operational Inconsistencies: The presence of duplicate token IDs could create inconsistencies in the contract’s state, undermining the reliability and predictability of the token withdrawal process.
User Confusion and Loss of Trust: Users might experience unexpected behavior, such as receiving incorrect token balances or failed transactions, which could lead to confusion, loss of trust, and negative perceptions of the system's reliability.
Recommended Mitigation:
To prevent these potential issues, implement a check within the Bridge.sol::withdrawTokens
function to ensure that the tokenIds array contains only unique values before processing. This could be done by:
Manual Check: Implement a manual loop to compare each token ID with the others in the array, reverting the transaction if duplicates are found.
Using a Set Data Structure: Utilize a set or similar data structure that inherently disallows duplicate entries, ensuring that the tokenIds array is free of duplicates.
Please, do not suppose impacts, think about the real impact of the bug and check the CodeHawks documentation to confirm: https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity A PoC always helps to understand the real impact possible.
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.