The claimSingleReward
function in the MysteryBox contract is vulnerable to a reentrancy attack. This vulnerability could allow an attacker to drain more funds from the contract than they are entitled to.
The vulnerable code is in the claimSingleReward
function:
The issue lies in the order of operations:
The function checks if the reward exists and has value.
It then sends the ETH to the user.
Only after sending the ETH does it delete the reward from the user's rewards.
This order of operations violates the Checks-Effects-Interactions pattern and opens up the possibility for a reentrancy attack.
The impact of this vulnerability is high:
Fund Drain: An attacker could repeatedly call this function before the reward is deleted, draining more ETH from the contract than they should be able to.
Economic Loss: The contract could lose all its ETH, affecting all users of the system.
Trust Issues: Such an exploit would severely damage the trust in the system and potentially lead to its complete failure.
Manual code review.
Here's a simple attack contract that could exploit this vulnerability:
To address this vulnerability, implement the Checks-Effects-Interactions pattern:
Alternatively, you could use the OpenZeppelin ReentrancyGuard
contract:
By implementing one of these solutions, the contract can protect itself against reentrancy attacks in the claimSingleReward
function.
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.