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-6372, which proposes a standard for identifying how a smart contract represents time.

This article translates, summarizes, and supplements the material linked below.

As of September 7, 2023, ERC-6372 was in the Review stage. This is the status recorded in the original article.

Overview

Smart contracts often use time information to perform particular tasks. For example, they may need to wait until a condition is met or record timestamps to maintain a transaction history.

However, it can be difficult for external callers to determine which time source a contract uses internally. Some contracts use Ethereum block numbers, while others use timestamps representing elapsed real-world time. Integrating with other contracts without knowing this distinction is difficult.

This Ethereum Improvement Proposal (EIP) introduces a consistent way for contracts to expose their timekeeping mechanisms. Other contracts and applications can retrieve this information and use it to coordinate their operations. This improves interoperability and data consistency, providing a foundation for applications to work together reliably.

Motivation

Smart contracts need time-related information for many purposes. Timelock contracts require a waiting period before executing particular operations. Decentralized autonomous organizations (DAOs) establish voting periods during which stakeholders decide whether to accept or reject proposals. Voting tokens maintain historical voting power checkpoints and can assign rights based on past voting power.

Some contracts measure time using a timestamp (timestamp), others use the blockchain's block number, and still others may use more complex clocks.

External users and contracts cannot always readily determine which clock a particular contract uses. Without this information, integrations may be difficult and may rely on incorrect assumptions.

The proposal addresses this problem by giving external callers a simple way to identify a contract's clock, improving interoperability and making integrations more predictable for developers.

Specification

javascript
interface IERC6372 {
  function clock() external view returns (uint48);
  function CLOCK_MODE() external view returns (string);
}

The two functions are described below.

clock

javascript
function clock() external view returns (uint48);

Overview

Returns the current timepoint according to the contract's clock mode.

Details

The clock must be a non-decreasing function of the chain's progression, such as block.timestamp or block.number.

Return value

  • timepoint
    • The value representing the current timepoint.

CLOCK_MODE

javascript
function CLOCK_MODE() external view returns (string);

Overview

Returns information describing how the contract represents time.

Details

The mode describes whether the contract uses timestamps, block numbers, or another timekeeping mechanism. It must be a machine-readable string that can be decoded in JavaScript using new URLSearchParams(CLOCK_MODE), with the returned descriptor supplied as the argument.

This allows other contracts and applications to interpret the clock correctly.

Return value

  • descriptor
    • A string describing the clock mode used by the contract.
    • It must follow URL query-string syntax.

The clock() function has an important requirement: its value must never decrease as the chain progresses. Once a timepoint has been returned, subsequent timepoints must be greater than or equal to it. Equal values are allowed; the clock is non-decreasing rather than strictly increasing.

Additional Notes

The clock() function exposes time information using the uint48 data type, which provides sufficient capacity for practical clocks.

In timestamp mode, uint48 can represent dates roughly 8.9 million years into the Common Era. Even in block-number mode, assuming an exceptionally high rate of 10,000 blocks per second, it can cover approximately 892 years of block production, corresponding roughly to the year 2861 when measured from the Unix epoch as an illustrative starting point.

Using uint48 rather than uint256 can also reduce storage costs when timepoints are packed with other data in a storage slot. The savings depend on storage layout and access patterns.

As blockchain technology evolves, smaller types such as uint32 may become inadequate for absolute timepoints. The appropriate type depends on the use case.

Time differences and delays have different requirements. While uint48 is suitable for absolute timepoints, uint32 can represent relatively long durations. For a clock measured in seconds, it covers approximately 136 years.

Suppose a smart contract requires a waiting period of 10 days before an action can be executed. This waiting period is expressed as a duration or delay.

  1. Using uint48

    • Ten days corresponds to 864,000 seconds.
    • The maximum value of uint48 is 281,474,976,710,655.
    • This is more than sufficient to represent the delay.
  2. Using uint32

    • Ten days corresponds to 864,000 seconds.
    • The maximum value of uint32 is 4,294,967,295.
    • This also provides sufficient capacity.

Both types can represent a 10-day delay in a clock measured in seconds. However, uint32 can save storage space when packed with other values.

In general, uint48 is suitable for storing timepoints and uint32 for durations or delays, subject to the required range and clock units.

Security Considerations

The proposal lists no specific security considerations.

Citation

Hadrien Croubois (@Amxx), Francisco Giordano (@frangio), "ERC-6372: Contract clock [DRAFT]," Ethereum Improvement Proposals, no. 6372, January 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6372.

Conclusion

ERC-6372 proposes a common way to identify the timekeeping mechanism used by a smart contract.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/