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

Weak Randomness

Summary

The RapBattle::_battle function implements randomness using the keccak256 hash function with a combination of block.timestamp, block.prevrandao, and msg.sender as inputs, resulting a weak randomness.

Vulnerability Details

Here's a breakdown of the weak randomness implemented in the RapBattle::_battle function:

  1. Inputs for keccak256: The inputs to the keccak256 function are block.timestamp, block.prevrandao, and msg.sender. These inputs are packed together using abi.encodePacked to form a single input for the hash function.

  2. Hashing: The keccak256 function is applied to this input, producing a 256-bit hash. The keccak256 function is a cryptographic hash function that is part of the Ethereum Virtual Machine (EVM) and is used for various purposes, including generating pseudo-random numbers.

  3. Modulo Operation: The resulting hash is then converted to an unsigned integer (uint256) and a modulo operation is applied to it with the total battle skill as the modulus. This operation effectively reduces the hash to a number within a specific range, in this case, the range of the total battle skill.

  4. Random Number Generation: The result of the modulo operation is the pseudo-random number used to determine the outcome of the battle.

Impact

  1. The predictability of block.timestamp and the potential for miners to influence it can make the outcome of the pseudo-random number generation predictable.

  2. Since msg.sender is part of the input, an attacker could potentially manipulate the outcome by choosing when to call the function. This could lead to an unfair advantage to the attacker over other participants.

Tools Used

Slither was used.

Recommendations

For applications that require higher levels of randomness, using external sources of randomness, such as Chainlink VRF (Verifiable Random Function), is probably one of the best choices. Chainlink VRF provides provably fair and verifiable random numbers that are resistant to manipulation by miners or other attackers.

Updates

Lead Judging Commences

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

Weak Randomness

Support

FAQs

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