The cancelRegistration
function in the ThePredicter
contract has a potential reentrancy vulnerability. This vulnerability arises because it transfers Ether to the caller before updating the caller's status. An attacker could exploit this to repeatedly withdraw the entrance fee by re-entering the function before their status is updated.
ThecancelRegistration
function transfers Ether to the caller before updating the caller's status. An attacker can exploit this by re-entering the function in the fallback function before the status is updated, allowing them to repeatedly withdraw the entrance fee.
The issue is in this function:
https://github.com/Cyfrin/2024-07-the-predicter/blob/main/src/ThePredicter.sol#L62-L70
Here is an example of how an attacker can execute the attack:
The attacker can drain funds from the contract, leading to financial loss.
Manual Review
Follow the "checks-effects-interactions" pattern by updating the state before making external calls.
Use OpenZeppelin’s ReentrancyGuard
to prevent reentrancy attacks.
Here is a refactored code with the necessary mitigation:
Reentrancy of ThePredicter::cancelRegistration allows a maliciour user to drain all funds.
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.