RandomAuRa
contract RandomAuRa
is UpgradeableOwned, IRandomAuRa
Generates and stores random numbers in a RANDAO manner (and controls when they are revealed by AuRa validators) and accumulates a random seed. The random seed is used to form a new validator set by the `ValidatorSetAuRa.newValidatorSet` function.
Index
- _clearOldCiphers
- _getCoinbase
- _getCurrentBlockNumber
- _revealNumber
- _revealNumberCallable
- commitHash
- commitHashCallable
- commitPhaseLength
- currentCollectRound
- currentCollectRoundStartBlock
- getCipher
- getCommit
- getCommitAndCipher
- initialize
- isCommitPhase
- isCommitted
- isInitialized
- isRevealPhase
- nextCollectRoundStartBlock
- nextCommitPhaseStartBlock
- nextRevealPhaseStartBlock
- onFinishCollectRound
- onlyBlockReward
- onlyInitialized
- revealNumber
- revealNumberCallable
- revealSecret
- revealSecretCallable
- setPunishForUnreveal
Reference
Modifiers
onlyBlockReward
modifier onlyBlockReward()
Ensures the caller is the BlockRewardAuRa contract address.
onlyInitialized
modifier onlyInitialized()
Ensures the `initialize` function was called before.
Functions
_clearOldCiphers
function _clearOldCiphers(uint256 _collectRound) internal
Removes the ciphers of all committed validators for the specified collection round.
- Parameters:
_collectRound
- The serial number of the collection round.
_getCoinbase
function _getCoinbase() internal view returns (address)
Returns the current `coinbase` address. Needed mostly for unit tests.
- Returns:
- address
_getCurrentBlockNumber
function _getCurrentBlockNumber() internal view returns (uint256)
Returns the current block number. Needed mostly for unit tests.
- Returns:
- uint256
_revealNumber
function _revealNumber(uint256 _number) internal
Used by the `revealNumber` function.
- Parameters:
_number
- The validator's number.
_revealNumberCallable
function _revealNumberCallable(address _miningAddress, uint256 _number) internal view returns (bool)
Used by the `revealNumberCallable` public getter.
- Parameters:
_miningAddress
- The mining address of validator which tries to call the `revealNumber` function._number
- The validator's number passed to the `revealNumber` function.- Returns:
- bool
commitHash
function commitHash(bytes32 _numberHash, bytes _cipher) external
Called by the validator's node to store a hash and a cipher of the validator's number on each collection round. The validator's node must use its mining address to call this function. This function can only be called once per collection round (during the `commits phase`).
- Modifiers:
- onlyInitialized
- Parameters:
_numberHash
- The Keccak-256 hash of the validator's number._cipher
- The cipher of the validator's number. Can be used by the node to restore the lost number after the node is restarted (see the `getCipher` getter).
commitHashCallable
function commitHashCallable(address _miningAddress, bytes32 _numberHash) public view returns (bool)
Returns a boolean flag of whether the `commitHash` function can be called at the current block by the specified validator. Used by the `commitHash` function and the `TxPermission` contract.
- Parameters:
_miningAddress
- The mining address of the validator which tries to call the `commitHash` function._numberHash
- The Keccak-256 hash of validator's number passed to the `commitHash` function.- Returns:
- bool
commitPhaseLength
function commitPhaseLength() public view returns (uint256)
Returns the length of the commits/reveals phase which is always half of the collection round length.
- Returns:
- uint256
currentCollectRound
function currentCollectRound() public view returns (uint256)
Returns the serial number of the current collection round.
- Returns:
- uint256
currentCollectRoundStartBlock
function currentCollectRoundStartBlock() public view returns (uint256)
Returns the number of the first block of the current collection round.
- Returns:
- uint256
getCipher
function getCipher(uint256 _collectRound, address _miningAddress) public view returns (bytes)
Returns the cipher of the validator's number for the specified collection round and the specified validator stored by the validator through the `commitHash` function.
- Parameters:
_collectRound
- The serial number of the collection round for which the cipher should be retrieved._miningAddress
- The mining address of validator.- Returns:
- bytes
getCommit
function getCommit(uint256 _collectRound, address _miningAddress) public view returns (bytes32)
Returns the Keccak-256 hash of the validator's number for the specified collection round and the specified validator stored by the validator through the `commitHash` function.
- Parameters:
_collectRound
- The serial number of the collection round for which the hash should be retrieved._miningAddress
- The mining address of validator.- Returns:
- bytes32
getCommitAndCipher
function getCommitAndCipher(uint256 _collectRound, address _miningAddress) public view returns (bytes32, bytes)
Returns the Keccak-256 hash and cipher of the validator's number for the specified collection round and the specified validator stored by the validator through the `commitHash` function.
- Parameters:
_collectRound
- The serial number of the collection round for which hash and cipher should be retrieved._miningAddress
- The mining address of validator.- Returns:
- bytes32
- bytes
initialize
function initialize(uint256 _collectRoundLength, address _validatorSet, bool _punishForUnreveal) external
Initializes the contract at network startup. Can only be called by the constructor of the `InitializerAuRa` contract or owner.
- Parameters:
_collectRoundLength
- The length of a collection round in blocks._validatorSet
- The address of the `ValidatorSet` contract._punishForUnreveal
- A boolean flag defining whether to punish validators for unrevealing.
isCommitPhase
function isCommitPhase() public view returns (bool)
Returns a boolean flag indicating whether the current phase of the current collection round is a `commits phase`. Used by the validator's node to determine if it should commit the hash of the number during the current collection round.
- Returns:
- bool
isCommitted
function isCommitted(uint256 _collectRound, address _miningAddress) public view returns (bool)
Returns a boolean flag indicating whether the specified validator has committed their number's hash for the specified collection round.
- Parameters:
_collectRound
- The serial number of the collection round for which the checkup should be done._miningAddress
- The mining address of the validator.- Returns:
- bool
isInitialized
function isInitialized() public view returns (bool)
Returns a boolean flag indicating if the `initialize` function has been called.
- Returns:
- bool
isRevealPhase
function isRevealPhase() public view returns (bool)
Returns a boolean flag indicating whether the current phase of the current collection round is a `reveals phase`. Used by the validator's node to determine if it should reveal the number during the current collection round.
- Returns:
- bool
nextCollectRoundStartBlock
function nextCollectRoundStartBlock() public view returns (uint256)
Returns the number of the first block of the next (future) collection round.
- Returns:
- uint256
nextCommitPhaseStartBlock
function nextCommitPhaseStartBlock() public view returns (uint256)
Returns the number of the first block of the next (future) commit phase.
- Returns:
- uint256
nextRevealPhaseStartBlock
function nextRevealPhaseStartBlock() public view returns (uint256)
Returns the number of the first block of the next (future) reveal phase.
- Returns:
- uint256
onFinishCollectRound
function onFinishCollectRound() external
Checks whether the current validators at the end of each collection round revealed their numbers, and removes malicious validators if needed. This function does nothing if the current block is not the last block of the current collection round. Can only be called by the `BlockRewardAuRa` contract (by its `reward` function).
- Modifiers:
- onlyBlockReward
revealNumber
function revealNumber(uint256 _number) external
Called by the validator's node to XOR its number with the current random seed. The validator's node must use its mining address to call this function. This function can only be called once per collection round (during the `reveals phase`).
- Modifiers:
- onlyInitialized
- Parameters:
_number
- The validator's number.
revealNumberCallable
function revealNumberCallable(address _miningAddress, uint256 _number) public view returns (bool)
Returns a boolean flag of whether the `revealNumber` function can be called at the current block by the specified validator. Used by the `revealNumber` function and the `TxPermission` contract.
- Parameters:
_miningAddress
- The mining address of validator which tries to call the `revealNumber` function._number
- The validator's number passed to the `revealNumber` function.- Returns:
- bool
revealSecret
function revealSecret(uint256 _number) external
The same as the `revealNumber` function (see its description). The `revealSecret` was renamed to `revealNumber`, so this function is left for backward compatibility with the previous client implementation and should be deleted in the future.
- Modifiers:
- onlyInitialized
- Parameters:
_number
- The validator's number.
revealSecretCallable
function revealSecretCallable(address _miningAddress, uint256 _number) public view returns (bool)
The same as the `revealNumberCallable` getter (see its description). The `revealSecretCallable` was renamed to `revealNumberCallable`, so this function is left for backward compatibility with the previous client implementation and should be deleted in the future.
- Parameters:
_miningAddress
- The mining address of validator which tries to call the `revealSecret` function._number
- The validator's number passed to the `revealSecret` function.- Returns:
- bool
setPunishForUnreveal
function setPunishForUnreveal(bool _punishForUnreveal) external
Changes the `punishForUnreveal` boolean flag. Can only be called by an owner.
- Modifiers:
- onlyOwner
- Parameters:
_punishForUnreveal
- bool