Commit-Reveal Explained in Detail
Commit-reveal is a two-step pattern. First, a user submits a commitment, usually a hash of a value plus a secret salt. Later, the user reveals the value and salt so the contract can verify the commitment.
The goal is to prevent other users from copying or reacting to the value before it is locked in.
Smart contract example
A sealed-bid auction can store a commitment first:
bytes32 commitment = keccak256(abi.encode(bidAmount, salt));
During the reveal phase, the bidder submits bidAmount and salt. The contract recomputes the hash and checks that it matches the stored commitment.
Commit-Reveal in Auditing
Commit-reveal can reduce front-running, but small design mistakes can make the scheme ineffective. The reveal phase, deadlines, salts, deposits, and non-reveal behavior matter as much as the hash.
If missing reveals are not penalized or handled, users can reveal only when the outcome benefits them.
Red flags in code
-
Commitment uses
abi.encodePackedwith ambiguous dynamic fields. -
Salt is small, predictable, or reused.
-
Commit and reveal windows overlap incorrectly.
-
No deadline or phase transition enforcement.
-
Users can reveal someone else's value for advantage.
-
No handling for users who commit but never reveal.
-
Revealed value does not include sender, chain, or contract context when needed.
How to test or review it
-
Test early reveal, late reveal, duplicate reveal, wrong salt, wrong sender, and missing reveal.
-
Check whether the commitment binds to the user and contract when needed.
-
Verify phase transitions cannot be skipped or extended by an attacker.
-
Use the Keccak-256 tool to reproduce simple commitments during review.
-
Consider whether MEV risk remains during the reveal phase.
Keep learning this topic
Front-Running
Front-running is a transaction-ordering attack where an attacker observes a pending transaction and submits their own transaction so it executes first.
MEV
MEV, or maximal extractable value, is value that can be extracted from transaction inclusion, exclusion, or ordering beyond normal block rewards and fees.
Signature Replay
Signature replay happens when a valid signature can be reused more than once or reused in a different context than the signer intended.
Frontrunning & Sandwich Attacks
Frontrunning and sandwich attacks in Solidity: how MEV bots extract value from DeFi traders, real examples, and slippage-based protections.
Replay Attacks
See how this vulnerability appears in real smart contract audits.
Keccak256 Online
Use this SCH tool to turn the concept into practical audit work.
Smart Contract Audit Checklist
Use this SCH tool to turn the concept into practical audit work.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Commit-Reveal into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.