Menu

1 / 8

Mathematically Prohibiting 'Cheating' in On-Chain RPS: A Midnight ZK dApp Case Study

DEV Community·Haruki Kondo·6 months ago
#1uYL5KS3
#zk#blockchain#typescript#react#midnight
Reading 0:00
15s threshold

Introduction

Implementing Rock-Paper-Scissors (RPS) on-chain is surprisingly tricky.

The moment you choose "Rock" and send a transaction, your opponent can read your move from the public ledger. The game is over before it even starts.

I tried implementing a commit-reveal pattern manually, but managing salts, preventing front-running, and ensuring fair judging logic... it quickly became a rabbit hole.

That's when I turned to Midnight . I built a full-stack RPS dApp where "cheating" (looking at the opponent's move before playing) is mathematically impossible!

In this article, I'll share the ZK circuit design using Midnight's smart contract language, Compact , and the hurdles I faced during development.

Note

What ZK protects : The ZK proof ensures "confidentiality of the move during the commit phase" (fairness). After the reveal, both moves are recorded on the public ledger.

Here is what the dApp looks like:

What You'll Learn

Designing the "Hidden" vs.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.