ThePredicter::cancelRegistration()
allows multiple withdrawals, draining contract fundsSummary:
The cancelRegistration()
function in ThePredicter.sol
is vulnerable to reentrancy attacks, allowing malicious actors to withdraw funds multiple times before their status is updated.
Vulnerability Details:
The cancelRegistration()
function performs an external call to transfer funds before updating the player's status - does not follow CEI pattern:
This violates the Checks-Effects-Interactions pattern, allowing for reentrancy attacks.
Impact:
An attacker can exploit this vulnerability to withdraw funds multiple times, potentially draining the contract's entire balance. This denies legitimate users their funds and disrupts the intended functionality of the contract.
Proof of Concept:
Create MaliciousContract.sol
:
Add this test to ThePredicter.t.sol
and run forge test --mt testReentrancyAttack -vvvv
in terminal.
Note: Make sure to import MaliciousContract.sol
into ThePredicter.t.sol
.
This test demonstrates that an attacker can withdraw funds 5 times instead of the intended single withdrawal. So based off this test, withdrawing multiple times, a malicious user can drain the funds from the contract.
Tools Used:
Manual review, Unit test, AI (Claude 3.5) for troubleshooting
Recommended Mitigation:
Implement the Checks-Effects-Interactions pattern in the cancelRegistration()
function:
Additionally, consider implementing a reentrancy guard using OpenZeppelin's ReentrancyGuard contract for added security.
To further improve this function, it would be a great idea to add a check for zero address on msg.sender
, in addition to emitting an event when a registration is cancelled.
Further Proposed Updates to Function After Implementing Correct CEI Pattern:
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.