DocsA draw in five phases
A draw in five phases.
A draw is a state machine, and every transition is permissionless — anyone can push it forward, and none of them require a payment. Whoever advances the machine chooses the timing, never the outcome.
The calls
closeEpoch()Ends deposits for the epoch and snapshots the participant list. Open to Ladder build. Reverts unless the prize is already funded, so a winner can never be credited from an empty reserve.
buildChunk()Extends the encrypted ticket ladder by up to twenty savers, called as many times as it takes. Ladder build to Total pending on the last chunk, which also marks the running total publicly decryptable.
submitTotal(total, proof)Verifies the decryption signatures, then draws randomness on-chain and reduces it against the now-plaintext total. Total pending to Winner pending.
submitWinner(w, proof)Verifies the winning number and publishes it. Winner pending to Claimable. Ticket ranges stay encrypted, so the number cannot be traced back to a person.
claimPrize()Credits an encrypted amount — the prize if the number landed in your range, an encrypted zero if it did not. Everyone runs the same code and the contract itself cannot tell the two apart.
withdrawPrize()Moves a credited prize into your spendable balance, whenever you choose to.
abortDraw()Resets a stalled draw to open and rolls the prize forward. Callable by anyone once the timeout has passed. Any phase to Open.
Why the draw lives inside submitTotal
Randomness cannot be reduced against a total that does not exist yet, so drawing has to happen after the total is known. Giving it its own transaction would add a state to the machine and a second place the draw could sit waiting for someone to act. Folding it into the call that publishes the total removes both.
It costs nothing in trust. The total is checked against its decryption proof before the reduction runs, so a submitter who invents a total cannot get past the first statement of the function, let alone influence what number comes out of the second.