The MysteryBox contract allows the owner to withdraw all available funds through the withdrawFunds()
function, without reserving any Ether to cover user rewards. As a result, users may receive valuable rewards (such as Gold or Silver Coins) without the contract having sufficient funds to pay out these rewards. This Ether mismanagement can lead to a situation where users are unable to claim their rewards, causing financial loss and damaging trust in the protocol.
The withdrawFunds()
function enables the owner to withdraw the entire Ether balance of the contract:
This function does not account for any Ether that needs to be reserved to pay for rewards that users have won, such as Gold and Silver Coins. By allowing the owner to withdraw all funds, the contract can be left without the necessary Ether to pay out these rewards. Users who have earned high-value rewards may not be able to claim them, resulting in financial instability for the contract.
Additionally, there is no separation between the funds needed to pay rewards and the funds that the owner can withdraw, which increases the risk of the contract being drained.
Financial Loss for Users: Users may receive rewards that the contract is unable to pay, resulting in financial losses.
Loss of Trust in the Protocol: If users are unable to claim rewards, they will lose trust in the system, which could lead to a reduction in engagement and participation.
Depletion of Contract Funds: The contract’s funds could be completely drained, leaving it unable to operate or fulfill its reward obligations.
Manual code review
Implement a Prize Pool Reserve:
Introduce a mechanism to reserve a portion of the contract’s Ether balance specifically for paying user rewards. This can be achieved by setting aside a percentage of the Ether received from box purchases for the prize pool and preventing the owner from withdrawing these funds.
Example:
Restrict Full Balance Withdrawals:
Limit the amount the owner can withdraw to ensure that enough funds remain to cover outstanding rewards. The withdrawal function should only allow the owner to withdraw funds that are not reserved for user rewards.
Track Reward Obligations:
Implement a system to track the total value of outstanding rewards and ensure that the contract holds enough Ether to cover them. Before distributing rewards, the contract should check whether it has sufficient funds to honor the rewards.
Example:
By implementing these recommendations, the contract can ensure that it always has sufficient Ether to back the rewards distributed to users, thereby preventing Ether mismanagement and preserving user trust.
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.