Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Reentrancy attack in `refund` function

Summary

The refund function is vulnerable to reentrancy attacks, as it can invoke the sendValue function multiple times.

Vulnerability Details

The refund function does not adhere to the checks-effects-interactions pattern, which could allow an attacker to steal funds from the contract.

Impact

This vulnerability allows anyone to create a malicious smart contract that can invoke the refund function multiple times using the fallback or receive functions. Because the refund function doesn't follow the checks-effects-interactions pattern, the contract can send the entranceFee multiple times without changing the state of players[playerIndex] to address(0).

Tools Used

Manual Review

Recommendations

  1. To fix the bug and ensure the function follows the checks-effects-interactions pattern, move the line players[playerIndex] = address(0); before the line payable(msg.sender).sendValue(entranceFee);.

  2. Implement the use of ReentrancyGuard.sol and apply the nonReentrant modifier to protect the function from reentrancy attacks.

Updates

Lead Judging Commences

Hamiltonite Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

reentrancy-in-refund

reentrancy in refund() function

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.