The claimAllRewards
and claimSingleReward
functions in the MysteryBox contract are vulnerable to reentrancy attacks. These functions transfer ETH to the user before updating the contract state, potentially allowing an attacker to recursively call the functions and drain funds from the contract.
The vulnerability exists in both the claimAllRewards
and claimSingleReward
functions:
In both functions, the ETH transfer occurs before the state is updated (i.e., before deleting the claimed rewards). This "checks-effects-interactions" pattern violation allows a malicious contract to make a reentrant call back into these functions before the state is updated, potentially claiming the same rewards multiple times.
The impact of this vulnerability is severe:
Fund Drainage: An attacker could potentially drain all available ETH from the contract by repeatedly claiming the same rewards before the state is updated.
Reward Duplication: Users could claim the same rewards multiple times, unfairly multiplying their earnings at the expense of the contract and other users.
Contract Insolvency: If exploited, this vulnerability could lead to the contract becoming insolvent, unable to pay out legitimate rewards to other users.
Economic Imbalance: The ability to claim rewards multiple times could disrupt the intended economic balance of the reward system, potentially making the game unfair or unsustainable.
The severity of this impact is heightened by the fact that the contract handles real ETH, meaning any exploit would result in direct financial losses.
Manual review of the smart contract code
To address this vulnerability, we recommend implementing the checks-effects-interactions pattern by updating the contract state before making external calls. Here's how the functions should be modified:
By implementing these changes, the contract updates its state before making external calls, significantly reducing the risk of reentrancy attacks while maintaining the core functionality of the reward claiming process.
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.