๐ Commit-Reveal: Prevent Manipulation
Learn the classic pattern for fair randomness generation
Generate provably fair random numbers on-chain
Your Progress
0 / 5 completedCommit-Reveal Schemes
**Commit-reveal** is a two-phase cryptographic protocol that prevents participants from changing their input after seeing others' choices. Users first commit to a value by submitting its hash, then reveal the actual value later. This ensures fairness in scenarios like voting, auctions, and random number generation.
The commitment phase locks in choices without revealing them. The reveal phase proves what was committed. If anyone tries to change their value, the hash won't matchโmaking manipulation cryptographically impossible.
๐ Two-Phase Protocol
Phase 1: Commit
Each participant submits H(value + salt) where H is a hash function (keccak256)
Phase 2: Reveal
Participants reveal their value and salt. Contract verifies H(value + salt) == commitment
Interactive: Commit-Reveal Demo
Experience how commit-reveal prevents cheating in a simple guessing game.
Phase: 1 - Commit
Use Cases
๐ฎ Blockchain Gaming
Players commit to their moves before reveal. Prevents front-running in poker, rock-paper-scissors, or strategy games.
๐ณ๏ธ On-Chain Voting
Voters commit to choices without revealing preferences. Final tally revealed after deadline.
๐ฐ Sealed-Bid Auctions
Bidders commit to bid amounts. Highest bidder revealed after all commits submitted.
๐ฒ Multi-Party Randomness
Each party commits to random value. Final randomness = XOR of all revealed values.
Implementation Example
โ ๏ธ Security Considerations
- โขLast revealer advantage: Last person can decide not to reveal if outcome is unfavorable
- โขPenalty for non-reveal: Require deposits that are slashed if users don't reveal
- โขTime limits: Enforce strict deadlines for both commit and reveal phases
- โขSufficient entropy: Use strong random salt (32 bytes minimum) to prevent brute-force