I am trying to make a smart contract that acts similar to a lottery or gambling game. Here is an example:
Alice and Bob send funds to a P2SH address. Bob is the lottery. The funds needs to be locked for some time (until the draw for example, like 5 days). For this we can use OP_CHECKLOCKTIMEVERIFY. After the nLockTime expires, if Alice guessed 3 numbers, she will get 50% of her deposit back. If she guesses 6 numbers, she will get 200% of her deposit back.
How can Bob (the lottery) commit to some numbers that Alice needs to guess before Alice funds the deposit address? Bob needs to be able to prove that the numbers were chosen before she funded the deposit address, and cannot simply deny any numbers Alice would guess.
On the other side, how can we enforce the funds go back to Alice if she guesses the numbers that were previously committed to by Bob in case Bob disappears before the draw (nLickTime expiration) time comes?
The simplest thing I can think of is Bob puts a hash of the numbers he committed to in OP_RETURN in the transaction funding the deposit address, but this is kind of a PITA and annoying and it does not offer a guarantee for Alice that she will take her money if she guesses the numbers Bob committed to even if he disappears until the draw (nLockTime expire) time comes.
Thank you.