The current implementation of the claimAllRewards and claimSingleReward functions deletes the rewardsOwned array only after transferring Ether. This opens up the contract to a reentrancy attack, allowing malicious users to repeatedly call the claim functions and withdraw all funds from the contract.
The functions fail to implement the Checks-Effects-Interactions (CEI) pattern, which is a best practice in Solidity to prevent reentrancy vulnerabilities. Specifically, the rewards are deleted after the Ether transfer, allowing attackers to reenter the contract and claim rewards multiple times.
Here are the vulnerable functions:
Since the array is only modified after transferring funds, a malicious user can reenter the contract within the transfer and claim additional rewards, potentially draining all funds.
An attacker could exploit this reentrancy vulnerability to repeatedly withdraw rewards, effectively draining all funds in the contract and leaving legitimate users without access to their rewards.
Manual Review
To mitigate this vulnerability, follow the Checks-Effects-Interactions (CEI) pattern by updating the state (i.e., deleting the reward) before transferring Ether. Here's a secure implementation:
This modification ensures that the reward is deleted before any Ether transfer occurs, preventing reentrancy attacks.
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.