Lesson 13 of 15
Commitment Scheme
Cryptographic Commitment Scheme
A commitment scheme lets one party (the committer) lock in a value without revealing it, then later prove they committed to that specific value. Think of sealing a prediction in an envelope — you can't change it after the fact, but the recipient can't see it yet.
Properties
- Hiding: the commitment reveals nothing about the value
- Binding: once committed, the committer cannot change to a different value that produces the same
Construction with a Nonce
To commit to value , choose a random nonce (number used once) :
To reveal: publish . Anyone can verify by recomputing .
The nonce prevents dictionary attacks: without , guessing from is infeasible.
Applications
- Mental poker — commit to cards before any player reveals theirs
- Coin flipping over the wire — both parties commit to random bits, then reveal simultaneously
- Zero-knowledge proofs — commitments are a core building block
- Auction systems — sealed bids that are opened simultaneously
Our Simulation
We simulate commitment with a simple hash:
(1000003 is a prime that gives good mixing.)
Your Task
Implement:
commit(value, nonce)→(value * 1000003 ^ nonce) & 0xFFFFFFFFreveal(commitment, value, nonce)→bool: check if recomputing gives the same commitment
Python runtime loading...
Loading...
Click "Run" to execute your code.