Hello,
I have an idea for a provide a provably fair lottery.
Lets say we want to draw a number between 1 and 100.
I send 0.1 CLAM to 100 addresses simultaneous with the addresses labeled from 1-100 ( all in 1 wallet).
The first address that stakes is the winner!
It's not a bad idea, but it would need some changes I think.
As I understand it, only the person who owns an address' private key can tell whether an address is ready to stake. He publishes the block, and everyone can check that it's correct. But if he doesn't want to stake at that time, he can decide to not publish the block and nobody can tell that he deliberately withheld a block. So it's not really provably fair - the guy running the lottery can deliberately make you lose by withholding the block that stakes the coin at your address.
So to make it provably fair, each player will have to run their own wallet, and stake their own address. Maybe it works like this:
* everyone who wants to play sends 1 CLAM (a) to x111 (an address owned by the guy running the lottery) and 1 CLAM (b) to x222 (a new address in their own wallet - x222 will be different for each player) in the same transaction (*)
* everyone runs their wallet 24/7, trying to stake the coin they sent to x222
* the first one to stake wins
You could insist that the address only has that single output, or you could just say that only outputs created in the same transaction as a 1 CLAM deposit to x111 count.
There's no reason the entry fee (a) and the staking size (b) need to be the same as each other. The entry fee can be adjusted based on how big people want to gamble, and the staking size can be adjusted to vary how long the 'draw' is likely to take.
You could set a rule like "each person can pick their own entry fee, and the stake size has to be N times the entry size" (for some N) - that way I can effectively buy 10 tickets at once by sending 10 CLAM to the entry address (x111) and 10*N CLAM to my staking address (x222). Bigger outputs have bigger chances of staking.
(*) To make a transaction which sends to two different addresses at once, you click 'add recipient' in the bottom left of clam-qt's 'send' tab.
Another concern is that people will enter at different times, so their staking outputs will mature at different times, and we don't get a clean start to the race. To fix that, maybe we make the following changes:
* the lottery organiser decides a date or block number when the game will start running
* everyone who wants to play sends their entry fee plus their staking amount to the lottery organiser, and indicates which of their own addresses they want to use for the race
* when the time or block number comes, the lottery organiser sends everyone's staking amount to their staking address, all in a single transaction, so they all mature at the same time and we get a good clean start to the race
* you can watch just that one transaction to see which of the outputs stakes first
* whichever output stakes first gets all the entry fees (minus the organiser's cut)
Is that workable?
Edit: we still have the obvious problem that the lottery organiser might just decide to keep all the entry fees for himself. This doesn't give us the "smart contract" property of having the blockchain automatically pay out the winner for us. I doubt such a thing is possible using CLAM.