Skip to content

Add VEIL: a raffle with a hidden draw and an anonymous winner - #12

Open
midasbal wants to merge 1 commit into
SeismicSystems:mainfrom
midasbal:add-veil-raffle
Open

Add VEIL: a raffle with a hidden draw and an anonymous winner#12
midasbal wants to merge 1 commit into
SeismicSystems:mainfrom
midasbal:add-veil-raffle

Conversation

@midasbal

Copy link
Copy Markdown

This adds Veil, a raffle where nobody can see how many tickets anyone holds, and the winner stays anonymous unless they come forward to claim.

Entrants pay in a shielded SRC20 token, so the number of tickets someone buys never lands in a public field. Each entry reserves a private range inside a running total, and that total stays hidden until the draw opens it up. At draw time the RNG builtin picks a number, but the number itself stays shielded, so there's nothing for anyone to read off-chain and react to.

The shielding isn't only about privacy here, it's also what keeps the draw honest. draw() doesn't branch on the value it produces, so once it lands in a block it's final. And claim() can't run until a later block, so you can't bundle draw() and claim() into one transaction and revert the whole thing if you didn't win. Between those two, there's no way to grind the result: you can't preview the number, and you can't throw away a draw you don't like.

The tradeoff, and the part I'd want a reviewer to look at: because the winning number is never revealed, the draw isn't auditable after the fact. You can confirm a payout happened, but you can't independently recompute who should have won and check it against who claimed. That's the cost of keeping the winner anonymous. A publicly verifiable draw would be a different design.

Two more things worth being upfront about. The count privacy only means much with a real crowd. With one entrant the total gives away their exact count and they win by default, and with two, each can work out the other's count by subtracting their own. Also, someone has to call draw() after the deadline; nothing in the contract incentivizes it beyond wanting the prize.

There are two small leaks I left in and noted in the README: trying to enter with zero tickets is visible before it reverts, and a losing claim tells the caller they lost. Both are self-only, and neither can shift the outcome.

Builds and tests clean on ssolc 0.8.31. 25 tests, including ones that actually reproduce the two grinding attacks and show them failing, plus a reentrancy check on the payout.

Ticket stakes are shielded and paid for through an SRC20 token, so no
ticket count is ever a public value. The winning ticket number is never
declassified, and claim() can only run in a block after draw(), so
neither an off-chain read of the result nor an atomic bundle of draw()
and claim() can be used to force or preview a win.

25 tests cover correctness, guards, and both grinding attacks this
design defends against, plus a defense-in-depth reentrancy check on
claim()'s payout ordering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant