Mystery Box

First Flight #25
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

claimAllRewards - Reentrancy

Summary/ Vulnerability Details/ Impact :

The Ether transfer (Interaction) is performed before the contract's internal state (Effects) is updated. This means that if a reentrancy attack is performed via the user's fallback function or receive function, the user could potentially call claimAllRewards again before their rewards are removed, allowing them to claim the same rewards multiple times.

Tools Used :

Slither, Wake, Foundry


Recommendations :

To respect the CEI model, the order of Effects and Interactions must be reversed:

function claimAllRewards() public {
uint256 totalValue = 0;
for (uint256 i = 0; i < rewardsOwned[msg.sender].length; i++) {
totalValue += rewardsOwned[msg.sender][i].value;
}
require(totalValue > 0, "No rewards to claim");
// Effects: Mise à jour de l'état AVANT l'interaction
delete rewardsOwned[msg.sender];
// Interactions: Transfert d'Ether APRÈS la mise à jour de l'état
(bool success,) = payable(msg.sender).call{value: totalValue}("");
require(success, "Transfer failed");
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

`claimAllRewards` reentrancy

dayeneris1 Submitter
about 1 year ago
inallhonesty Lead Judge
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

`claimAllRewards` reentrancy

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.