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.
Here's a breakdown of the weak randomness implemented in the RapBattle::_battle
function:
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.
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.
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.
Random Number Generation: The result of the modulo operation is the pseudo-random number used to determine the outcome of the battle.
The predictability of block.timestamp
and the potential for miners to influence it can make the outcome of the pseudo-random number generation predictable.
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.
Slither was used.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.