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

Bad source of randomness

Summary

Both PuppyRaffle::selectWinner()::winnerIndex and PuppyRaffle::selectWinner()::rarity use deterministic randomness.

The code generates randomness based on the sender's address (msg.sender), the block's difficulty (block.difficulty), and in the case of winnerIndex the current block's timestamp (block.timestamp).

However, this approach is deterministic, meaning that the same input parameters will always produce the same result. This can potentially be exploited by malicious users who might try to predict or influence the outcome by timing their transactions.

Vulnerability Details

Miner Manipulation: Miners have control over the order in which transactions are included in a block, and they can choose to include or exclude transactions. This means they can manipulate the block.timestamp and block.difficulty to some extent, which could further undermine the randomness of this approach.

Predictability: If participants can anticipate the result, they might game the system by submitting transactions at specific times to increase their chances of winning. Block-related pseudo-random properties like block.coinbase, block.difficulty, block.gaslimit, block.number and block.timestamp are available to any attacker if their transaction is in the same block information as the victim's transaction. In the case of PuppyRaffle contract this in easy to achieve since PuppyRaffle::selectWinner() is public and anyone can call it even the attacker.

Tools Used

Solidity

Recommendations

To enhance the security and fairness of random number generation in smart contracts, it's generally advisable to use an external source of randomness, such as Chainlink VRF (Verifiable Random Function) or another decentralized oracle service. These services provide a more tamper-resistant source of randomness, making it much more difficult for anyone, including miners, to predict or manipulate the outcome.

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

weak-randomness

Root cause: bad RNG Impact: manipulate winner

Support

FAQs

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

Give us feedback!