A critical vulnerability has been discovered in the ThePredicter
smart contract that allows a re-entrancy attack. This vulnerability occurs in the cancelRegistration
function, where an external call to transfer Ether back to the user is made before updating the user's status, potentially allowing the attacker to recursively call the function and withdraw funds multiple times.
The withdrawPredictionFees
and withdraw
functions in ThePredicter.sol
are susceptible to underflow errors under certain conditions, such as when the organizer calls the withdraw
function before withdrawPredictionFees
. This could prevent the organizer from withdrawing the contract's balance. Introducing state variables for allPredictionFee
and allEntranceFee
and implementing additional checks can mitigate this risk.
This is the test code of reentrancy attack.
To test this code:
Input this code to new test solidity file: test/CheckWithdrawPredictionFees.test.sol
.
Then run this command:
forge test --match-path test/CheckWithdrawPredictionFees.test.sol --match-test testWithdraw -vvvv
The result is:
As you can see, arithmetic underflow or overflow error occurs and organizer can't withdraw the contract's balance.
Underflow errors can result in incorrect calculations, leading to potential failures in fee withdrawal and reward distribution.
The current implementation may prevent the organizer from withdrawing the contract's balance under specific conditions, impacting the contract's functionality.
Manual code review
Define allPredictionFee
and allEntranceFee
as state variables to ensure consistency and facilitate validation checks.
Modify constructor.
Modify register
function.
Modify cancelRegistration
function.
Modify makePrediction
function.
Modify withdrawPredictionFees
function.
Modify withdraw
function.
withdrawPredictionFees incorrectly computes the value to be transferred to the organizer, which leads to pending players not being able to cancel their registration, approved players not being able to claim their rewards and other errors.
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.