Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Insecure Randomness in increaseValuesOfParticipants Allows Malicious Selection of Ram and Unauthorized Withdrawal of Funds

Summary

The increaseValuesOfParticipants function uses insecure randomness, allowing an attacker to predict and manipulate the random outcome to become Ram. Once selected, the attacker can call the withdraw function to drain the contract's funds due to the predictable selection process. Additionally, the withdraw function lacks the check-effect-interaction pattern, exposing the contract to potential reentrancy attacks.

Vulnerability Details

The increaseValuesOfParticipants function uses insecure randomness to decide whether to increase the values of the challenger or a participant. The random number is generated using the current block timestamp, block.prevrandao, and the msg.sender address:

uint256 random = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))) % 2;

Due to the predictability of these parameters, an attacker can manipulate the inputs to control the outcome of the random number generation, allowing them to unfairly select themselves as the Ram.

Once an attacker becomes Ram, they can exploit the withdraw function to withdraw funds:

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; // Check-effect interaction is missing, causing potential reentrancy
}

Impact

Unauthorized Fund Withdrawal: An attacker can manipulate the randomness in increaseValuesOfParticipants to become Ram. Once selected, they can call the withdraw function and drain the contract's funds.

Tools Used

Manual review

Recommendations

Secure Randomness: Use a more secure method for generating randomness, such as Chainlink VRF or another verifiable random function.

Check-Effect-Interaction: Implement the check-effect-interaction pattern in the withdraw function to prevent reentrancy attacks

Updates

Lead Judging Commences

bube Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Weak randomness in `ChoosingRam::increaseValuesOfParticipants`

Support

FAQs

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