- Commit to a value without revealing it (commit phase)
- Reveal the value later to prove they knew it in advance (reveal phase)
- Blind Auctions: Bidders commit to their bids first, then reveal them after the bidding period
- Voting Systems: Voters commit their votes early, revealing them only after voting ends
- Knowledge Proofs/Attestations: Proving you knew information at a specific time without revealing it immediately
- Fair Random Number Generation: Players commit to random numbers that get combined later, making it harder to manipulate the outcome
How It Works
-
Commit Phase:
- User generates a value (
secret
) - User creates a hash of this value
- User submits only the hash on-chain (
commit
)
- User generates a value (
-
Reveal Phase:
- User submits the original value (
reveal
) - Contract verifies that the hash of the submitted value matches the previously committed hash
- If it matches then it proves that the user knew the value at the commitment time
- User submits the original value (
Minimal commit-reveal contract:
- The commit phase must complete before any reveals can start
- Users might choose not to reveal if the outcome is unfavorable (consider adding stake/slashing mechanics to ensure reveals)