I'm looking at making gambling apps is ethereum. Currently made a contract that can flip a coin. After looking at this question:
How can I securely generate a random number in my smart contract?
and thinking about the problem that large lotteries face, in that players would need to put up a huge deposit in order to guarantee that they do in fact reveal their random number, I thought of a potential solution. It is my understanding that, in order to participate in a 4 way flip, each player would have to put up a bet of 1 unit and a deposit of 9 units (in order to pay each other player 3 units if they don't reveal). I have an idea for an alternative approach that works as follows:
- Players 1, 2, 3, and 4 put up a bet of 1 unit and a deposit of 1 unit.
- They all submit and reveal their random number.
- P1 & P2's numbers are used to determine a winner between the two of them, the loser gets their deposit of 1 back.
- The same occurs with P3 & P4.
- Let's assume P1 & P3 win. They now have 3 units each. They put up a bet of 1.5 units and a deposit of 1.5 units.
- Let's assume P1 wins. He now has 4.5 units and P3 has 1.5 units. This could end here so that P1 wins first place of 3.5 units and P3 gets 2nd for 0.5 units(a net gain of 2.5 for P1 and a net loss of 0.5 for P3).
Alternatively:
- They each put up a bet and deposit of 0.5 units each and flip again. If P1 wins, he has 5 units and P3 has 1 unit (his deposit) and the bet is over. If P3 wins, P1 has 4 units and P3 has 2 units and we proceed to step 8.
- They each put up a bet and deposit of 1 units each and flip again. If P1 wins, he has 5 units and P3 has 1 unit (his deposit) and the bet is over. If P3 wins, P1 has 3 units and P3 has 3 units and we go back to step 5.
A new random number must be submitted and revealed each time. A limit could be set on number of flips and, if a winner is not found, the current payments are paid out. I'm aware that this is the same as just upping the stakes every time you bet but a contract that implements this on a large scale seems in no way different to a normal lottery.
In order to prevent players from "chickening out" after winning several flips, an additional small deposit could be made. For example a bet of 1 unit, a standard deposit of 1 unit to prevent gaining an edge by cheating and a deposit of some amount, say 0.2 units, to prevent people being denied their large flip. The other player either gets their flip or gets bought out of it.
This can be applied to allow 2^x people to gamble with 1 winner or a series of progressively larger winners. Is this all logically sound and do you think it solves the problem that lotteries face? Any other problems with it?