The PuppyRaffle : : enterRaffle() function in the PuppyRaffle contract uses a nested loop to check for duplicate entries. This approach can lead to high gas costs when the number of players is large.
The inefficiency in the enterRaffle() function could potentially make the contract unusable when dealing with a large number of players due to the high gas costs
Manual
It's recommended to address this issue by implementing a more efficient method for checking duplicate entries, such as using a mapping.
Declare a mapping at the top of your contract like so: mapping(address => bool) public isPlayer;
In the enterRaffle function, before pushing a new player into the players array, check if the player is already in the isPlayer mapping. If they are, revert the transaction. If they're not, add them to the isPlayer mapping and then push them into the players array.
Here's what the updated enterRaffle function might look like:
Remember to reset the isPlayer mapping for each player in the selectWinner function after the winner is selected and the players array is deleted.
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.