In the 'enterRaffle' function, two loops are used to check if the player's address is already in the 'players' list. This makes it cheaper for the first participants, but more expensive for those who join later because we have to check through a longer list of players leading to the computational overhead.
Below is the outcome of a test in foundry which checks the gas used for entering the first 100 players into the puppy raffle compared to the gas used to enter the next 100 players into the raffle. The gas consumption is approx. 189% more for the later participants.
'Denial of Service attack' is possible if an attacker enters the raffle with loads of addresses at the beginning making it extremely expensive for the consecutive players to enter leading to an 'out of gas' error.
Excessive amount of gas makes it unfair for upcoming players to enter the raffle.
Foundry
Mapping 'mapping(address => bool)' can be created for every player address to store his presence. Hence we can simply check the boolean value to determine whether the address is already present or not.
'enterRaffle' can be modified to include the below code.
Gas used throw this method is as below
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.