ICommitReveal
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
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
| data | bytes | The committed data. |
| salt | bytes32 | The blinding salt used in the commitment. |
commitmentInfo
Returns the record for commitment.
function commitmentInfo(bytes32 commitment) external view returns (Commitment memory);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The commitment hash to query. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | Commitment | The commitment record (zero committedAt if never committed). |
isRevealed
Returns whether commitment has been revealed.
function isRevealed(bytes32 commitment) external view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The commitment hash to query. |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| committer | address | The address to bind into the commitment. |
| data | bytes | The data to commit. |
| salt | bytes32 | The blinding salt. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 | The commitment hash. |
Events
Committed
Emitted on commit.
event Committed(bytes32 indexed commitment, address indexed committer, uint64 committedAt);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The committed hash. |
| committer | address | The account that committed. |
| committedAt | uint64 | The commit block timestamp. |
Revealed
Emitted on reveal, publishing the revealed data.
event Revealed(bytes32 indexed commitment, address indexed committer, bytes data, bytes32 salt);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The revealed hash. |
| committer | address | The account that revealed (the address bound into the hash). |
| data | bytes | The revealed data. |
| salt | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The already-committed hash. |
CommitRevealNotCommitted
Thrown when revealing a commitment that was never committed (or wrong data/salt/sender).
error CommitRevealNotCommitted(bytes32 commitment);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The recomputed hash that has no commitment. |
CommitRevealAlreadyRevealed
Thrown when revealing an already-revealed commitment.
error CommitRevealAlreadyRevealed(bytes32 commitment);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The already-revealed hash. |
Structs
Commitment
Per-commitment record.
struct Commitment {
address committer;
uint64 committedAt;
bool revealed;
}Properties
| Name | Type | Description |
|---|---|---|
| committer | address | The 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). |
| committedAt | uint64 | The block timestamp at which it was committed (0 == never committed). |
| revealed | bool | Whether it has been revealed. |