There is a reentrancy vulnerability in the ThePredicter::cancelRegistration()
function. This vulnerability allows an attacker to repeatedly withdraw funds during the execution of the cancelRegistration function, resulting in the attacker receiving 55 times the amount they paid for the attack.
The ThePredicter::cancelRegistration()
function in in line-62 is susceptible to a reentrancy attack. The function sends Ether back to the caller before updating the contract's state. This allows the attacker to repeatedly call ThePredicter::cancelRegistration()
through a fallback function before the contract can update its state, draining the contract's funds.
Key points:
The attacker can register as a player and then exploit the ThePredicter::cancelRegistration()
function.
The lack of proper reentrancy protection allows an attacker to repeatedly invoke cancelRegistration, withdrawing funds multiple times during a single transaction.
This process continues until the contract's balance is depleted.
Add the following to ThePrediter.test.sol
test file:
The above test confirms that an attacker can exploit the reentrancy vulnerability in the ThePredicter::cancelRegistration()
function to drain all funds from ThePredicter.sol contract.
Financial Loss: An attacker can withdraw all funds from the contract, resulting in significant financial loss.
Theft Multiplier: The attacker can steal approximately 55 times their initial investment.
Contract Insolvency: The attack leaves the contract with zero balance, making it unable to fulfill its obligations to other users (i.e, no rewards).
Manual code review
Foundry (for running test cases)
Implement Reentrancy Guard: Use a reentrancy guard mechanism, such as OpenZeppelin's ReentrancyGuard, to prevent reentrant calls to cancelRegistration.
Implement Checks-Effects-Interactions Pattern:
Modify the cancelRegistration
function to update the contract's state before sending Ether.
Use Transfer Instead of Send: Consider using transfer()
instead of call()
for Ether transactions, as it has a gas stipend that prevents reentrancy.
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.