To ensure the integrity of the user's state within ThePredicter::cancelRegistration
,
the function initially verifies if the user's status is Pending
.
Upon confirmation, the function processes the refund of the entrance fee.
Subsequently, it updates the user's status to Canceled
.
This sequence of operations, however, introduces a vulnerability: it allows a malicious user to re-enter
the cancelRegistration
function, potentially leading to the depletion of the contract's funds.
The impact is marked as HIGH, because it let's attackers drain all the contract's funds. In addition, any attacker can do that.
Impact: High + Likelihood: HIgh = HIGH
Slither + Manual Review and Testing
Here is the Slither output that got me looking at the issue:
```bash
Reentrancy in ThePredicter.cancelRegistration() (src/ThePredicter.sol#58-67):
External calls:
- (success,None) = msg.sender.call{value: entranceFee}() (src/ThePredicter.sol#60)
```
Here is a test the can be implemented in the ThePredicter.test.sol
file:
Step by step:
A stranger enters
Setting up the attacker contract.
The attack function calls the cancelRegistration
function.
ThePredicter
refunds the attacker. However, the attacker contract has a malicious receive function that calls cancelRegistration
. Therefore, draining the contract.
Lastly, testing to see that the amounts match.
Follow CEI: Checks, effects, interactions. Simply put, move the state change up:
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.