Skip to free scan

Security Patterns

Commit-Reveal Scheme

A commit-reveal scheme is a two-phase protocol where a participant first submits a hash of a secret value (the commit), then later submits the value itself (the reveal). Because the value is hidden during the commit phase, it cannot be front-run or copied, and no single party controls a combined outcome.

How It Works

  1. Commit: submit keccak256(value, salt). The value is hidden but binding.
  2. Reveal: later submit value and salt; the contract verifies the hash matches.
mapping(address => bytes32) public commitment;

function commit(bytes32 hash) external { commitment[msg.sender] = hash; }

function reveal(uint256 value, bytes32 salt) external {
    require(commitment[msg.sender] == keccak256(abi.encodePacked(value, salt)), "bad reveal");
    // use value now that it can't be front-run
}

Common Uses

  • Preventing front-running of bids, votes, or moves.
  • Contributing entropy for randomness without any party seeing others' inputs first (mitigating weak randomness).

Frequently Asked Questions

Q: How does commit-reveal stop front-running?

A: During the commit phase the value is only a hash, so observers and block proposers cannot see or copy it. By the time it is revealed, ordering no longer gives an advantage.


Q: Is commit-reveal a full randomness solution?

A: It helps by combining multiple hidden inputs, but a single participant can still refuse to reveal. For strong on-chain randomness, combine it with an external source like Chainlink VRF.

Firepan

Scan Your Contracts

Run a free surface scan — results in minutes, no credit card required.

Run Free Scan →