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

A reentrancy attack in the `ThePredictor::cancelRegistration` function allows Users to drain the contract and steal the funds.

Description:

The ThePredictor::cancelRegistration function doesn't have any mechanism to prevent a reentrancy attack and doesn't follow the Checks-Effects-Interactions pattern. Thus it is potentially vulnerable to reentrancy attacks. This is because it first refunds the entrance fee to the msg.sender and then updates the status of the User. A malicious User contract could re-enter the cancelRegistration function, manipulate the state before the function execution is completed (before the User's status is updated).

Impact:

This vulnerability could allow a malicious User contract to drain Ether from the ThePredictor.sol contract, resulting in a loss of funds for the contract and its users.

Tools Used:

VSCode, manual review

Recommended Mitigation:

To mitigate the reentrancy vulnerability, the Checks-Effects-Interactions pattern should be followed. This pattern advises making all state changes before calling external contracts or sending Ether. In addition consider implementing mutexes or locks, such as a reentrancy guard by OpenZeppelin^[https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/ReentrancyGuard.sol].
Consider making the following changes to the ThePredicter::cancelRegistration function:

function cancelRegistration() public {
if (playersStatus[msg.sender] == Status.Pending) {
- (bool success, ) = msg.sender.call{value: entranceFee}("");
- require(success, "Failed to withdraw");
playersStatus[msg.sender] = Status.Canceled;
+ (bool success, ) = msg.sender.call{value: entranceFee}("");
+ require(success, "Failed to withdraw");
return;
}
revert ThePredicter__NotEligibleForWithdraw();
}
Updates

Lead Judging Commences

NightHawK Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Reentrancy in cancelRegistration

Reentrancy of ThePredicter::cancelRegistration allows a maliciour user to drain all funds.

Support

FAQs

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