Reputation: 23
I want contract to predifine winning boxes, is it possible to achieve this functionality solidity, so no one can detect which box is the winning box?
If so, how can I predefine winning boxes which will be unreadeable until the user opens a specific box?
I tried to use block.timestamp
to randomly choose winning boxes upon contract creation, but hacker can replicate block.timestamp and determine which box is the winning box.
Upvotes: 1
Views: 91
Reputation: 8018
Make your boxes to be the Schrödinger boxes - winners and losers at the same time. When a user selects a box and sends the Transaction to your contract - request a random number from Chainlink and make it to a winner or loser box.
Upvotes: 0
Reputation: 36
If you have a trusted party, you can hash the winning number (with a salt so people don't brute force it), then reveal it after a certain point. This has an obvious disadvantage that whoever hashed the number knows the winning number.
Your question implies you are looking for randomness, so you can used established randomness patterns like commit reveal or chainlink VRF. With commit reveal, when someone plays the game, they commit that a future blockhash will be the random number. A block producer can tamper with the hash to a certain degree, so if you are worried about that, use chainlink VRF.
Upvotes: 1