Skip to content
Lattice

ICommitReveal

Git Source

Title: ICommitReveal

Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)

External interface for a generic commit–reveal primitive: hide a value behind a hash, then reveal it later. A building block for sealed-bid auctions, commit–reveal voting, and MEV mitigation. No ZK / circuits — plain keccak256 hashing.

A commitment is keccak256(abi.encode(committer, data, salt)), binding the committer's address into the hash. reveal recomputes the hash from msg.sender, so ONLY the bound committer can reveal a given commitment — front-running the commit transaction does not let anyone else reveal it. Each commitment can be revealed at most once. Commit and reveal should be in different blocks for the hiding to be meaningful (the application enforces any timing using Commitment.committedAt).

Functions

commit

Records a commitment hash. The hash should be computeCommitment(msg.sender, data, salt).

function commit(bytes32 commitment) external;

Parameters

NameTypeDescription
commitmentbytes32The commitment hash to record.

reveal

Reveals data + salt for a commitment previously made by msg.sender.

Recomputes keccak256(abi.encode(msg.sender, data, salt)) and marks that commitment revealed.

function reveal(bytes calldata data, bytes32 salt) external;

Parameters

NameTypeDescription
databytesThe committed data.
saltbytes32The blinding salt used in the commitment.

commitmentInfo

Returns the record for commitment.

function commitmentInfo(bytes32 commitment) external view returns (Commitment memory);

Parameters

NameTypeDescription
commitmentbytes32The commitment hash to query.

Returns

NameTypeDescription
<none>CommitmentThe commitment record (zero committedAt if never committed).

isRevealed

Returns whether commitment has been revealed.

function isRevealed(bytes32 commitment) external view returns (bool);

Parameters

NameTypeDescription
commitmentbytes32The commitment hash to query.

Returns

NameTypeDescription
<none>bool

computeCommitment

Computes the commitment hash for (committer, data, salt).

keccak256(abi.encode(committer, data, salt)). Use off-chain (or in a consuming contract) to build the commit hash consistently with reveal.

function computeCommitment(address committer, bytes calldata data, bytes32 salt) external pure returns (bytes32);

Parameters

NameTypeDescription
committeraddressThe address to bind into the commitment.
databytesThe data to commit.
saltbytes32The blinding salt.

Returns

NameTypeDescription
<none>bytes32The commitment hash.

Events

Committed

Emitted on commit.

event Committed(bytes32 indexed commitment, address indexed committer, uint64 committedAt);

Parameters

NameTypeDescription
commitmentbytes32The committed hash.
committeraddressThe account that committed.
committedAtuint64The commit block timestamp.

Revealed

Emitted on reveal, publishing the revealed data.

event Revealed(bytes32 indexed commitment, address indexed committer, bytes data, bytes32 salt);

Parameters

NameTypeDescription
commitmentbytes32The revealed hash.
committeraddressThe account that revealed (the address bound into the hash).
databytesThe revealed data.
saltbytes32The blinding salt.

Errors

CommitRevealZeroCommitment

Thrown when committing the zero hash.

error CommitRevealZeroCommitment();

CommitRevealAlreadyCommitted

Thrown when committing a hash that is already committed.

error CommitRevealAlreadyCommitted(bytes32 commitment);

Parameters

NameTypeDescription
commitmentbytes32The already-committed hash.

CommitRevealNotCommitted

Thrown when revealing a commitment that was never committed (or wrong data/salt/sender).

error CommitRevealNotCommitted(bytes32 commitment);

Parameters

NameTypeDescription
commitmentbytes32The recomputed hash that has no commitment.

CommitRevealAlreadyRevealed

Thrown when revealing an already-revealed commitment.

error CommitRevealAlreadyRevealed(bytes32 commitment);

Parameters

NameTypeDescription
commitmentbytes32The already-revealed hash.

Structs

Commitment

Per-commitment record.

struct Commitment {
        address committer;
        uint64 committedAt;
        bool revealed;
    }

Properties

NameTypeDescription
committeraddressThe account that submitted the commit transaction. Informational only —
reveal authorization comes from the committer's address being bound into the
commitment hash, NOT from this field (do not gate reveal on it).
committedAtuint64The block timestamp at which it was committed (0 == never committed).
revealedboolWhether it has been revealed.