Mystery Box

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

REENTRANCY IN VULNERABILITY IN `clainAllRewards()` FUNCTIONS

Summary:

 The bug occurs because the function sends Ether to  caller using `call` function  which can call back into the function before the call is updated.

Vulnerability Details:

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");
(bool success,) = payable(msg.sender).call{value: totalValue}("");
require(success, "Transfer failed");
delete rewardsOwned[msg.sender];
}

Impact:

An attacker could repeatedly call the `claimAllRewards()` function to exhaust the contracts funds. this could make the contract 
unable to fulfil its obligation, leading to a denial of service.  
  1. An attacker could exploit the reentrancy by calling the claimAllReward() function before the contract has updated the reward
    array.
    As a result the contract will transfer Ether to the attackers address and the rewards array will remain unchanged, allowing the
    attcker to claim the rewards again in subsequent calls.

Tools Used:

   Aderyn and slither.

Recommendations:

  Update the state before making external calls.
  Use the `send()` functions instead of `call()`
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

Support

FAQs

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

Give us feedback!