Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-5732, a proposal for a simple commit interface that supports commit-reveal schemes.

The explanation below translates, summarizes, and expands on the original proposal.

I also cover a range of other ERCs.

Overview

This contract interface provides a way to conceal information on a blockchain and disclose it later. This approach, known as a commit-reveal scheme, is particularly useful for voting, asset transfers, and similar applications.

Commit-reveal schemes

Imagine a class holding a secret ballot. Each student wants to keep their vote private while voting is in progress. A commit-reveal scheme works much like the following arrangement.

Commit phase

Each student first writes their vote on a small piece of paper. They fold the paper and place it in an envelope rather than handing it over openly. They can then give the envelope to their teacher without disclosing their vote. A blockchain commitment serves a similar purpose to sealing a ballot in an envelope.

Reveal phase

Once everyone has voted, the teacher opens the envelopes and counts the ballots. Only then does each student's choice become visible. A blockchain reveal corresponds to opening the envelope and disclosing its contents.

The advantage of this approach is that voters cannot see one another's choices while voting is in progress, helping preserve fairness. Someone attempting to manipulate the vote cannot determine which concealed choices would be advantageous to change.

Blockchains use the same principle to handle votes and other important information securely. Information remains private until disclosure, supporting a fair and transparent process.

The interface includes a commit method but does not define a reveal method for disclosing information. Reveal mechanisms vary between applications, and incorporating a particular mechanism into the interface would reduce its flexibility. Applications can therefore use commit to conceal information and reveal it later through application-specific operations, such as voting or transfers.

The interface acts like a temporary seal on information recorded on a blockchain. Applications can choose how to open that seal according to their requirements. This makes it possible to keep information secret until the appropriate time to disclose it.

Motivation

Commit-reveal schemes protect privacy in blockchain voting and other applications. A user first converts sensitive information, such as a vote, into a cryptographic commitment and submits it to an on-chain contract. This is the commit phase. At this point, the underlying information is concealed from other participants.

At the designated time, the user supplies the information necessary to disclose the original value and verify the commitment. This is the reveal phase.

One advantage of this approach is that it can mitigate attacks such as front-running, back-running, and sandwich attacks. These attacks exploit transaction ordering on a blockchain to obtain an unfair advantage. A properly constructed commitment makes such attacks harder because an attacker cannot determine the concealed information during the commit phase.

This approach can make blockchain transactions safer by protecting user information and making transaction-ordering attacks more difficult.

Front-running

In a blockchain context, front-running occurs when someone learns about a large pending trade and places a trade ahead of it. The earlier trader seeks to profit from the subsequent price movement.

Back-running

Back-running involves placing a trade immediately after another person's large trade. The later trader seeks to profit from the effects of the preceding transaction.

Sandwich attacks

A sandwich attack places trades on both sides of another person's transaction: one immediately before it and another immediately afterward. The enclosed transaction may execute at a worse price, allowing the attacker to profit.

These examples illustrate how transaction ordering can undermine fair trading on a blockchain.

Specification

javascript
pragma solidity >=0.7.0 <0.9.0;

// The EIP-165 identifier of this interface is 0xf14fcbc8
interface IERC_COMMIT_CORE {
    function commit(bytes32 _commitment) payable external;
}

pragma solidity >=0.7.0 <0.9.0;

// The EIP-165 identifier of this interface is 0x67b2ec2c
interface IERC_COMMIT_GENERAL {
    event Commit(
        uint256 indexed _timePoint,
        address indexed _from,
        bytes32 indexed _commitment,
        bytes _extraData);
    function commitFrom(
        address _from,
        bytes32 _commitment,
        bytes calldata _extraData)
    payable external returns(uint256 timePoint);
}

The specification describes two interfaces for blockchain contracts: IERC_COMMIT_CORE and IERC_COMMIT_GENERAL.

  • The IERC_COMMIT_CORE interface

    • Defines a function named commit.
    • The function registers a commitment to secret data on the blockchain.
    • It is externally callable and can receive payment.
  • The IERC_COMMIT_GENERAL interface

    • Defines the Commit event and the commitFrom function.
    • The function allows a commitment to be submitted on behalf of another address, with additional information.
    • The Commit event signals that a commitment was successfully registered.

A conforming contract must implement IERC_COMMIT_CORE. Implementing IERC_COMMIT_GENERAL is also recommended. When the latter is implemented, commit serves as a simplified version of commitFrom.

The timePoint returned by commitFrom should use a value such as a block timestamp or block number to indicate commitment ordering.

The extraData field is reserved for extensions. If _from differs from the transaction signer, signature verification is recommended. For an EOA, this means verifying an ECDSA signature. For a smart contract account, it means verifying a signature using EIP-1271.

For more on ERC-1271, see the following article.

[ERC-1271] Verifying Signatures with Smart Contracts

Revealing the secret requires a mechanism for supplying an additional field called secret_salt, but the specification intentionally leaves that mechanism undefined.

Conforming contracts are also recommended to implement EIP-165. These interfaces and features are designed to support secure, efficient commitment and disclosure on blockchains.

For more on ERC-165, see the following article.

[ERC-165] Checking Whether a Contract Supports an Interface

Rationale

The proposal explains the design choices behind supporting commit-reveal schemes in blockchain contracts.

General-purpose commit interface

Commit functionality could be added separately to standards such as ERC-20 and ERC-721, but the proposal instead defines a simpler, broadly applicable interface. This allows existing ERC standards to support commit-reveal schemes without fundamentally changing their interfaces.

For more on ERC-20, see the following article.

https://chaldene.net/erc20

For more on ERC-721, see the following article.

https://chaldene.net/erc721

Standardizing the commit method

The commit operation is standardized, while the reveal mechanism remains customizable. Applications can therefore combine commitments with a variety of existing standards.

Minimal core interface

The core interface contains a simple commit method. It is compatible with existing systems such as ENS.

Adding the commitFrom method

The commitFrom method allows commitments created off-chain to be submitted by another account on the user's behalf.

The contract is designed to work with existing ERC standards and make commit-reveal schemes easier to use across blockchain applications. This allows applications to adopt the mechanism securely and efficiently.

Backward compatibility

The proposal addresses compatibility with existing ERC standards.

Compatibility with existing ERCs

The proposal is compatible with methods in existing ERC standards that accept an extraData field. Including a salt field in new EIPs can make support for this proposal easier, although it is not mandatory.

Compatibility of IERC_COMMIT_CORE

The IERC_COMMIT_CORE interface is compatible with the Ethereum Name Service (ENS) and other existing technologies.

The proposal adds new functionality while remaining compatible with existing ERC standards and systems such as ENS. It is intended to support new blockchain features without disrupting existing applications and services.

Reference implementation

Committing in ENS

When registering a domain name through the Ethereum Name Service (ENS), a contract called ETHRegistrarController uses a function named commit. This prevents someone from anticipating a registrant's intentions and claiming the name first through front-running.

In the ENS registration example, the commit function receives a commitment, checks whether the previous commitment has expired, and records the new commitment with the current timestamp.

javascript
function commit(bytes32 commitment) public {
    require(commitments[commitment] + maxCommitmentAge < now);
    commitments[commitment] = now;
}

The proposed EIP illustrates how the ENS commit function could be extended as follows.

javascript
function commit(bytes32 commitment, bytes calldata data) public {
    require(commitments[commitment] + maxCommitmentAge < now);
    commitments[commitment] = now;
    emit Commit(...);
}

This change allows additional data (data) to be accepted and a Commit event to be emitted. The aim is to make the ENS domain registration process more transparent and efficient.

Security considerations

Demonstration implementations

The provided contract code is intended for demonstration rather than real-world deployment. It is not suitable for production use as provided.

Keeping reveal information secret

Reveal transactions and parameters, particularly the secret_salt, must remain secret until disclosure.

Security of secret_salt

The secret_salt must be sufficiently long and securely generated from random values. A previously used secret_salt must not be reused. Client applications should warn users if they attempt to reuse one.

Secure contract implementation

Contracts should promptly delete the relevant sender's commitment when appropriate to reduce the risk of replay and reentrancy attacks. They can also impose constraints on the ordering of reveal transactions.

Cross-chain replay protection

To address replay attacks across blockchains with different chain IDs or across forks, commitments should include the chain ID when generated. Applications at greater risk of replay attacks should consider secure approaches such as EIP-712.

For more on EIP-712, see the following article.

[EIP-712] Hashing and Signing Typed Structured Data

Time delays to mitigate front-running

An appropriate time delay is recommended to mitigate front-running. Additional measures are needed to enforce strict ordering so that transactions in the same block do not share the same _timePoint.

These considerations are important for contract security and an effective commit-reveal implementation.

Citation

Zainan Victor Zhou (@xinbenlv), Matt Stam (@mattstam), "ERC-5732: Commit Interface," Ethereum Improvement Proposals, no. 5732, September 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5732.

Conclusion

This article covered ERC-5732, a standard proposing a simple commit interface for commit-reveal schemes.

If you have any questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/