Randomness
Tuna Salad ... that was random
Basedball uses getrandomresult() for a provably fair onchain randomized seed input of every single hit. Each game is composed of 30 random hits based on the set fair probabilities seeded for randomness by the Basedball contract's growing nonce iteration onchain.
The getrandomresult() function generates a pseudo-random number based on a combination of block timestamp, sender address (msg.sender
), and a nonce value (nonce
). To break it down:
block.timestamp
: This is the timestamp of the block in which the transaction is included. It provides a source of randomness based on the time at which the transaction is processed.msg.sender
: This is the address of the account that initiated the transaction. It adds an additional factor to the randomness based on the sender of the transaction.nonce
: The nonce value is incremented each time the function is called, ensuring that subsequent calls to the function produce different random numbers. This helps prevent predictability based on previous calls to the function.keccak256(abi.encodePacked(...))
: This combination is used to generate a cryptographic hash of the concatenated values of block timestamp, sender address, and nonce. Thekeccak256
hash function is deterministic, meaning the same input will always produce the same output. However, it's practically impossible to predict the output without knowing the input values.% 100
: Finally, the modulo operation is applied to limit the range of the generated number to between 0 and 99, effectively creating a random number between 0 and 99 inclusive.
Given these factors, this function appears to be reasonably secure against gaming by a player. The use of block timestamp and sender address adds entropy to the randomness, and the inclusion of a nonce prevents predictability based on previous calls.
It's essential to note that no random number generation method is entirely foolproof, and sophisticated attackers may still attempt to exploit weaknesses in the system.
It's also worth mentioning that Ethereum's block timestamp can be manipulated to some extent by miners, although it's generally considered difficult to do so profitably. Additionally, reliance on block.timestamp
for randomness introduces some vulnerabilities, such as the potential for miners to influence the outcome by manipulating block timestamps.
Last updated