Skip to content
Lattice

CommitRevealLib

Git Source

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

NameTypeDescription
$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

NameTypeDescription
commitmentbytes32The 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

NameTypeDescription
databytesThe committed data.
saltbytes32The blinding salt.

commitmentInfo

Returns the record for commitment.

function commitmentInfo(bytes32 commitment) internal view returns (ICommitReveal.Commitment memory);

Parameters

NameTypeDescription
commitmentbytes32

Returns

NameTypeDescription
<none>ICommitReveal.Commitment

isRevealed

Returns whether commitment has been revealed.

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

Parameters

NameTypeDescription
commitmentbytes32

Returns

NameTypeDescription
<none>bool

computeCommitment

Computes keccak256(abi.encode(committer, data, salt)).

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

Parameters

NameTypeDescription
committeraddress
databytes
saltbytes32

Returns

NameTypeDescription
<none>bytes32