Cyfrin Updraft.

Bài viết

Chia sẻ kiến thức của bạn.

Cyfrin Moderator Pst.
Mar 29, 2024
Hỏi đáp Chuyên Gia

Does mitigation of DoS in Section 4 Lesson 15 work correctly?

I am currently working on Section 4 Lesson 15 and addressing the PuppyRaffle::enterRaffle function. I have identified a potential issue with the second recommended mitigation of DoS.

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 concern is that the duplicate check in the function will always fail due to the way addressToRaffleId[newPlayers[i]] is being set to raffleId for each new player. This results in the condition addressToRaffleId[newPlayers[i]] != raffleId never being true for new players, rendering the duplicate check ineffective.

I would like to confirm if my understanding of this issue is correct. Any insights or feedback on this matter would be greatly appreciated.

  • Security
  • Solidity
  • Smart Contract
0
1
Chia sẻ
Bình luận
.

Câu trả lời

1
Cyfrin Moderator Ans.
Mar 29 2024, 10:49

Thank you for pointing that out. While the example provided was intended to be brief, I agree that its inclusion in the recommendations section would not be advisable. Therefore, I recommend removing it from that section.

0
Câu trả lời chính thức
Bình luận
.

Bạn có biết câu trả lời không?

Hãy đăng nhập và chia sẻ nó.

Cyfrin Updraft is an education platform specializing on teaching the next generation of smart contract developers

195Bài viết196Câu trả lời
Chúng tôi sử dụng cookie để đảm bảo bạn có trải nghiệm tốt nhất trên trang web của chúng tôi.
Thêm thông tin