Skip to content

Latest commit

 

History

History
103 lines (64 loc) · 6.41 KB

cip-64.md

File metadata and controls

103 lines (64 loc) · 6.41 KB
CIP No. Title Author Discussions Status Type Created
64
Get Current Epoch Number via Internal Contract
Péter Garamvölgyi <@Thegaram>
Final
Spec Breaking
2021-03-08

Simple Summary

Currently, transactions on Conflux have no direct access to the number of the epoch they are executed in. To maintain EVM compatibility, this CIP introduces a new internal contract that makes this information available to contracts.

Abstract

A common technique in dapp development is to store the block number corresponding to an event in a contract's storage and subsequently use this information to query the contract. For instance, one might want to start querying logs starting from the contract's creation. However, the query APIs of Conflux work with epoch numbers, not block numbers, which renders this technique infeasible. This CIP introduces a new internal contract that makes the execution epoch number available to contracts.

Motivation

There are two common use cases for using block numbers (block.number) in smart contracts.

The first use case is timing. The growth rate of block numbers is relatively steady and hard to influence, which makes them suitable for applications like time locks.

The second use case is querying. For instance, a contract might store its creation block number and clients might read this to know from which block they need to start querying the contract's events.

This latter use case is not feasible on Conflux as our query APIs (RPC) only support querying by epoch number, not by block number.

Specification

Starting from epoch XXX, a new internal contract is available at the address 0x0888000000000000000000000000000000000003 (cfx:type.builtin:aaejuaaaaaaaaaaaaaaaaaaaaaaaaaaaapx8thaezf). This contract has the following interface.

pragma solidity >=0.4.15;

contract ConfluxContext {
    /*** Query Functions ***/
    /**
     * @dev get the current epoch number
     */
    function epochNumber() public view returns (uint64) {}
    /**
     * @dev get the height of the referred PoS block in the last epoch
`    * @return the current PoS block height
     */
    function posHeight() public view returns (uint256) {}
    /**
     * @dev get the epoch number of the finalized pivot block.
     * @return the finalized epoch number
     */
    function finalizedEpochNumber() public view returns (uint256) {}
}

When a transaction's execution triggers a call to epochNumber(), the internal contract implementation must return the current epoch number from the transaction's execution context.

Analogous to the NUMBER opcode, the gas cost of this internal contract call should be 2.

Rationale

Instead of adding a new opcode, this functionality is implemented as an internal contract to maintain compatibility with Ethereum's EVM specification. This means that we do not need to maintain our own fork of the Solidity compiler and similar developer tools.

Backwards Compatibility

As this proposal introduces a new internal contract, it is not backwards compatible.

Test Cases

TBA.

Implementation

TBA.

Security Considerations

This proposal brings no security issues.

Copyright

Copyright and related rights waived via CC0.