The function cancelRegistration
in the contract ThePredicter
has a reentrancy vulnerability which allows a malicious player to drain the funds in the contract.
The function cancelRegistration
in the contract ThePredicter
makes a refund of the entrance fee to a Pending Player before changing their status to Canceled. This allows for a malicious contract to register as a player and then call cancelRegistration
recursively many times before its status is changed to Canceled, leading to a loss of potentially all of the funds in ThePredicter
.
The malicious contract would have to register in ThePredicter
using the register
function before the registration period finishes, and ensure that it is not approved as a player by the organizer. Once this is done the exploit can be triggered at any time, so an attacker could wait for all of the predictions for the 9 matches to be placed before triggering the exploit to maximize the amount of funds stolen.
This is a test showing a PoC of how an attacker could exploit the vulnerability, based on a test scenario already present in the repository:
Complete drain of funds of the system
Foundry
Fix the cancelRegistration
function by following the Check-Effects-Interactions pattern.
Optionally
If no contracts are expected to interact with the system, add checks to the functions transferring funds to check that the msg.sender
is not a contract.
Have a virtual balance to distinguish between funds collected from entrance fees and prediction fees. Add checks to cancelRegistration
to ensure only the funds collected from entrance fees are refunded.
Implement events on user registration, approval and cancellation to have better visibility of the state of each user in the system.
Add reentrancy guards to the functions that make external calls.
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.