Does mitigation of DoS in Section 4 Lesson 15 work correctly? #34
-
Hello, I am now working on Section 4 Lesson 15 and mitigating I think there's a potential issue with the 2nd recommended mitigation of DoS as follows. function enterRaffle(address[] memory newPlayers) public payable {
require(msg.value == entranceFee * newPlayers.length, "PuppyRaffle: Must send enough to enter raffle");
for (uint256 i = 0; i < newPlayers.length; i++) {
players.push(newPlayers[i]);
addressToRaffleId[newPlayers[i]] = raffleId;
}
for (uint256 i = 0; i < newPlayers.length ; i++) {
require(addressToRaffleId[newPlayers[i]] != raffleId, "PuppyRaffle: Duplicate player");
}
} The issue here is that the duplicate check will always fail. The reason is that for each new player Is my idea correct? I'd appreciate any thoughts or feedback on this propose. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Great shout! That was sort of a quick example of what one could do, but yes you're right, this would be bad. We should remove it from the recommendations section. |
Beta Was this translation helpful? Give feedback.
-
Instead you can use this check function enterRaffle(address[] memory newPlayers){
...
for (uint256 i = 0; i < newPlayers.length; i++) {
players.push(newPlayers[i]);
require(addressToRaffleId[newPlayers[i]] != raffleId, "PuppyRaffle: Duplicate player");
addressToRaffleId[newPlayers[i]] = raffleId;
}
...
} |
Beta Was this translation helpful? Give feedback.
Great shout! That was sort of a quick example of what one could do, but yes you're right, this would be bad. We should remove it from the recommendations section.