I am thinking about creating a lottery with more than one winner and one round for users. Please don't consider usual 'commit-reveal' scheme. However, person can claim rewards on their own at the end of the lottery.
So, generation of pseudorandom number is essential.
I'm looking forward for approaches without 3d party involvement.
I would be very grateful to all answers!
- 13
- 2
-
Yes, I saw this too. I'm interested in the most effective/secure approaches, many answers for question are outdated for 2023, from my point of view – Victor Aug 11 '23 at 06:37
2 Answers
This question already has been asked and answered more than once.
If you are building a lottery, pseudorandom is not safe, for lotteries or gambling since it can be found or manipulated.
However, on top of all the other solution easy to find with a simple search, there is now a new solution to pseudo-randomness and answering this now could prevent future duplicates:
- Since the Ethereum merge the new opcode
prevrandaomade its appearance, to replace the previousdifficulty:
Useful links:
- 561
- 3
- 17
In short:
There's no "safe" way to generate pseudo-random numbers in smart contracts if those numbers are used for critical functions. The only plausible solution (for now) is an Oracle.
In your case, creating a pseudo-random number in a smart contract for something like a lottery is a bit like trying to keep a secret everyone can figure out. Since everything on the blockchain is transparent, anyone with enough know-how can predict the number. So you need to account for that.
If you can implement the lottery system such that knowing the results of the pseudo-random-number generating function offers no advantage, you are good. But I don't see a legit way fo accomplish that.
- 2,282
- 2
- 7
- 26
