Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Reentrancy Vulnerability in `Dussehra::withdraw` May Lead to Fund Theft

[L-3] Reentrancy Vulnerability in Dussehra::withdraw May Lead to Fund Theft

Description:
The withdraw function in the Dussehra contract sends rewards to the winner (Ram) using a low-level call function. However, the state variable totalAmountGivenToRam is modified after the transfer is initiated, creating a reentrancy risk. An attacker could potentially exploit this vulnerability to drain funds from the contract.

function withdraw() public RamIsSelected OnlyRam RavanKilled {
if (totalAmountGivenToRam == 0) {
revert Dussehra__AlreadyClaimedAmount();
}
uint256 amount = totalAmountGivenToRam;
@> (bool success, ) = msg.sender.call{value: amount}("");
require(success, "Failed to send money to Ram");
@> totalAmountGivenToRam = 0;
}

Impact:
While the typical flow of the protocol might not immediately expose this vulnerability, especially since the organizer's fee is transferred upon invoking the killRavana function, it's crucial to address this issue to safeguard against potential exploits. Ensuring the integrity of fund transfers is paramount, particularly in scenarios where unexpected funds accumulate in the contract at the time of withdrawal.

Tools Used:
Manual Review
Recommended Mitigation:
To eliminate the reentrancy risk, it is advised to adjust the order of operations within the withdraw function to follow CEI (Checks, Effects, Interactions). Specifically, the state variable totalAmountGivenToRam should be reset before initiating the fund transfer. This change prevents potential reentrant calls from interfering with the contract's state during the withdrawal process.

function withdraw() public RamIsSelected OnlyRam RavanKilled {
if (totalAmountGivenToRam == 0) {
revert Dussehra__AlreadyClaimedAmount();
}
uint256 amount = totalAmountGivenToRam;
+ totalAmountGivenToRam = 0;
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Failed to send money to Ram");
- totalAmountGivenToRam = 0;
}
Updates

Lead Judging Commences

bube Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Invalid - reentrancy in withdraw

The `withdraw` function sends the given amount to Ram. If the attacker calls the `withdraw` function again before the state variable is changed, the function will revert because there are no more funds in the contract. This reentrancy has no impact for the protocol. It is recommended to follow the CEI pattern, but this is informational.

Support

FAQs

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