CommitRevealLib
Title: CommitRevealLib
Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)
Library implementing a generic commit–reveal primitive (sealed bids / auctions / MEV mitigation). The commitment binds the committer's address, so only the bound committer can reveal it — front-running the commit transaction cannot hijack the reveal.
Three-layer pattern: this library holds the logic + namespaced storage; the stateless CommitReveal facet forwards to it. Permissionless — anyone may commit and reveal their own.
Functions
commitRevealStorage
function commitRevealStorage() internal pure returns (CommitRevealStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | CommitRevealStorage |
__CommitReveal_init
Initializes the CommitReveal module.
Must be called inside a pre/postInitializer block. Registers ICommitReveal for ERC-165.
function __CommitReveal_init() internal;registerInterface
Registers support for the ICommitReveal interface via ERC-165.
function registerInterface() internal;commit
Records a commitment hash (computeCommitment(msg.sender, data, salt)).
function commit(bytes32 commitment) internal;Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 | The commitment hash to record. |
reveal
Reveals data + salt for a commitment previously made by msg.sender.
Only the address bound into the commitment can produce a matching hash, so reveal is front-run-proof regardless of who submitted the commit transaction.
function reveal(bytes calldata data, bytes32 salt) internal;Parameters
| Name | Type | Description |
|---|---|---|
| data | bytes | The committed data. |
| salt | bytes32 | The blinding salt. |
commitmentInfo
Returns the record for commitment.
function commitmentInfo(bytes32 commitment) internal view returns (ICommitReveal.Commitment memory);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | ICommitReveal.Commitment |
isRevealed
Returns whether commitment has been revealed.
function isRevealed(bytes32 commitment) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| commitment | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
computeCommitment
Computes keccak256(abi.encode(committer, data, salt)).
function computeCommitment(address committer, bytes calldata data, bytes32 salt) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| committer | address | |
| data | bytes | |
| salt | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |