A security review of the Pot
contract revealed a significant vulnerability in handling duplicate player addresses during contract initialization. This issue could lead to incorrect reward distribution and potential loss of funds.
The constructor of the Pot
contract doesn't check for or properly handle duplicate addresses in the players
array, leading to potential overwriting of reward values:
If the same address appears multiple times in the players
array, each subsequent occurrence will overwrite the previous reward value in the playersToRewards
mapping.
The presence of duplicate player addresses can have several serious consequences:
Incorrect Reward Distribution: Players with duplicate addresses will only receive the last reward amount assigned to them, potentially losing out on earlier, possibly larger rewards.
Fund Loss: Some rewards might become inaccessible if earlier entries for a duplicate address are overwritten, effectively locking those funds in the contract.
Inconsistent State: The sum of rewards in playersToRewards
might not match the i_totalRewards
, leading to accounting discrepancies.
Unfair Advantage: If intentional, this could be exploited to give certain players multiple entries, increasing their chances of receiving rewards unfairly.
Example scenario:
In this scenario, 100 tokens are effectively lost and Alice's initial reward is overwritten.
Manual code review
AI for report.
Implement Duplicate Address Check:
Use a data structure like OpenZeppelin's EnumerableSet
to efficiently track and handle unique addresses:
Validate Total Rewards: Ensure that the sum of all rewards matches the expected total rewards to prevent any discrepancies.
Event Emission: Consider emitting an event when a duplicate address is detected, allowing for off-chain monitoring and auditing.
Clear Documentation: Clearly document the behavior for duplicate addresses in the contract's comments and external documentation.
Unit Testing: Implement comprehensive unit tests that cover scenarios with duplicate addresses to ensure the contract behaves as expected.
By implementing these recommendations, the contract will handle duplicate player addresses safely and transparently, preventing potential fund loss and ensuring fair reward distribution.
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.