Skip to main content

V2 InternalContracts

Conflux v2 hardfork has introduced three new internal contracts: ConfluxContext, PoSRegister, CrossSpaceCall

ConfluxContext#

This contract can be used to query Conflux network info including:

  • epochNumber - Current epoch number
  • posHeight - Current block height of PoS chain
  • finalizedEpochNumber - The latest finalized (by PoS chain) PoW epoch number

ConfluxContext's hex40 contract address is 0x0888000000000000000000000000000000000004

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.15;
interface ConfluxContext {
/*** Query Functions ***/
/**
* @dev get the current epoch number
* @return the current epoch number
*/
function epochNumber() external view returns (uint256);
/**
* @dev get the height of the referred PoS block in the last epoch
` * @return the current PoS block height
*/
function posHeight() external view returns (uint256);
/**
* @dev get the epoch number of the finalized pivot block.
* @return the finalized epoch number
*/
function finalizedEpochNumber() external view returns (uint256);
}

PoSRegister#

This contract is used let user participate in PoS chain. If anyone want to become a PoS node, he need to interact with this contract. This contract provide serveral methods to increase or decrease PoS votes:

  • register - Regist in PoS chain to become a PoS node
  • increaseStake - Increase PoS stake
  • retire - Decrease PoS stake

Also several methods to query one account's PoS info:

  • getVotes - Query one account's votes info, will return totalStakedVotes and totalUnlockedVotes
  • identifierToAddress - Query one PoS account's binded PoW address
  • addressToIdentifier - Query one PoW account's binded PoS address

PoSRegister's hex40 contract address is 0x0888000000000000000000000000000000000005

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
interface PoSRegister {
/**
* @dev Register PoS account
* @param indentifier - PoS account address to register
* @param votePower - votes count
* @param blsPubKey - BLS public key
* @param vrfPubKey - VRF public key
* @param blsPubKeyProof - BLS public key's proof of legality, used to against some attack, generated by conflux-rust fullnode
*/
function register(
bytes32 indentifier,
uint64 votePower,
bytes calldata blsPubKey,
bytes calldata vrfPubKey,
bytes[2] calldata blsPubKeyProof
) external;
/**
* @dev Increase specified number votes for msg.sender
* @param votePower - count of votes to increase
*/
function increaseStake(uint64 votePower) external;
/**
* @dev Retire specified number votes for msg.sender
* @param votePower - count of votes to retire
*/
function retire(uint64 votePower) external;
/**
* @dev Query PoS account's lock info. Include "totalStakedVotes" and "totalUnlockedVotes"
* @param identifier - PoS address
*/
function getVotes(bytes32 identifier) external view returns (uint256, uint256);
/**
* @dev Query the PoW address binding with specified PoS address
* @param identifier - PoS address
*/
function identifierToAddress(bytes32 identifier) external view returns (address);
/**
* @dev Query the PoS address binding with specified PoW address
* @param addr - PoW address
*/
function addressToIdentifier(address addr) external view returns (bytes32);
/**
* @dev Emitted when register method executed successfully
*/
event Register(bytes32 indexed identifier, bytes blsPubKey, bytes vrfPubKey);
/**
* @dev Emitted when increaseStake method executed successfully
*/
event IncreaseStake(bytes32 indexed identifier, uint64 votePower);
/**
* @dev Emitted when retire method executed successfully
*/
event Retire(bytes32 indexed identifier, uint64 votePower);
}

CrossSpaceCall#

A new internal contract called the CrossSpaceCall contract will be deployed at the address 0x0888000000000000000000000000000000000006 with the following interfaces. The Core space user/contract can interact with the accounts in the eSpace and process the return value in the same transaction. So the cross-space operations can be atomic.

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
interface CrossSpaceCall {
event Call(bytes20 indexed sender, bytes20 indexed receiver, uint256 value, uint256 nonce, bytes data);
event Create(bytes20 indexed sender, bytes20 indexed contract_address, uint256 value, uint256 nonce, bytes init);
event Withdraw(bytes20 indexed sender, address indexed receiver, uint256 value, uint256 nonce);
event Outcome(bool success);
function createEVM(bytes calldata init) external payable returns (bytes20);
function transferEVM(bytes20 to) external payable returns (bytes memory output);
function callEVM(bytes20 to, bytes calldata data) external payable returns (bytes memory output);
function staticCallEVM(bytes20 to, bytes calldata data) external view returns (bytes memory output);
function withdrawFromMapped(uint256 value) external;
function mappedBalance(address addr) external view returns (uint256);
function mappedNonce(address addr) external view returns (uint256);
}