The claimAllRewards
function in the MysteryBox
contract allows users to claim all their rewards in Ether based on the value of the rewards they have accumulated. Ether transfer operations (call
) occurred before updating the contract's internal state.
The claimAllRewards
function in the MysteryBox
contract is responsible for allowing users to claim all of their accumulated rewards in Ether. In a scenario where the contract interacts with external accounts (e.g., transferring Ether via call
), it becomes susceptible to a reentrancy attack if state updates are not properly handled prior to external interactions.
Reentrancy vulnerabilities occur when a contract allows external calls (such as sending Ether) before updating its internal state. An attacker can exploit this by repeatedly invoking the function before the internal state (in this case, the rewards) is cleared, potentially draining the contract's funds.
If the function does not follow the Checks-Effects-Interactions (CEI) pattern, an attacker could:
Call claimAllRewards
.
Receive the Ether while simultaneously re-entering the contract through the callback mechanism.
Claim rewards multiple times by re-entering the function before the rewards are deleted, draining the contract of its funds.
Impact
The contract could lose significant funds if an attacker manages to re-enter the function before the rewards state is updated.
Manual Review
Apply CEI pattern to mitigate reentrancy attack.
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.