The claimAllRewards
function in the MysteryBox contract is also vulnerable to a reentrancy attack, similar to the claimSingleReward
function. This vulnerability could allow an attacker to drain more funds from the contract than they are entitled to.
The vulnerable code is in the claimAllRewards
function:
The issue lies in the order of operations:
The function calculates the total value of all rewards.
It then sends the total ETH to the user.
Only after sending the ETH does it delete all the rewards from the user's account.
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 rewards are deleted, potentially draining all ETH from the contract.
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.
Compounded Risk: This vulnerability is even more severe than the one in claimSingleReward
as it allows claiming all rewards at once, potentially leading to larger losses in a single attack.
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, use the OpenZeppelin ReentrancyGuard
contract:
By implementing one of these solutions, the contract can protect itself against reentrancy attacks in both the claimSingleReward
and claimAllRewards
functions.
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.