cancelRegistration
function not correctly implement CEI (Check, Effect, Interaction), making the protocol can be exploited using reentrancy and potentially drained all contract balance.
ThePredicter.sol
:
ThePredicter.sol
not implementing CEI as shown at the snippet code above, the entranceFee
refunding after a user cancel their registration is called early before the proper playersStatus[msg.sender] = Status.Canceled;
are being set. This can be exploited because the status change are done after the contract sending the Fee.
add new file in test folder called DrainFee.sol
.
DrainFee.sol
:
add the following code to ThePredicter.test.sol
:
run the following command forge test --mt test_POCReentrancyOnCancelRegistration -vv
the result should PASS:
ThePredicter
contract balance can be drained out by malicious actor
foundry
Change ThePredicter::cancelRegistration
code so it would implement the CEI:
then run the following command again forge test --mt test_POCReentrancyOnCancelRegistration -vv
the result should FAIL:
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.