AbstractConsensus
Inherits: IConsensus, ERC165, ApplicationChecker, RollupsContract
Abstract implementation of IConsensus
State Variables
EPOCH_LENGTH
The epoch length
uint256 immutable EPOCH_LENGTH
CLAIM_STAGING_PERIOD
The claim staging period
uint256 immutable CLAIM_STAGING_PERIOD
_validOutputsMerkleRoots
Indexes valid outputs Merkle roots by application contract address.
mapping(address => mapping(bytes32 => bool)) private _validOutputsMerkleRoots
_claims
Indexes claim information by application contract address, last-processed block number, and machine Merkle root.
mapping(address => mapping(uint256 => mapping(bytes32 => Claim))) private _claims
_firstUnprocessedBlockNumbers
Indexes number of the first unprocessed block by application contract address.
mapping(address => uint256) private _firstUnprocessedBlockNumbers
_lastFinalizedMachineMerkleRoots
Indexes machine merkle root of the most recently accepted claim by application contract address.
mapping(address => bytes32) private _lastFinalizedMachineMerkleRoots
_numOfAcceptedClaims
Indexes number of accepted claims by application contract address.
Must be monotonically non-decreasing in time
mapping(address => uint256) private _numOfAcceptedClaims
_numOfStagedClaims
Indexes number of staged claims by application contract address.
Must be monotonically non-decreasing in time
mapping(address => uint256) private _numOfStagedClaims
_numOfSubmittedClaims
Indexes number of submitted claims by application contract address.
Must be monotonically non-decreasing in time
mapping(address => uint256) private _numOfSubmittedClaims
Functions
constructor
Reverts if the epoch length is zero.
constructor(uint256 epochLength, uint256 claimStagingPeriod) ;
Parameters
| Name | Type | Description |
|---|---|---|
epochLength | uint256 | The epoch length |
claimStagingPeriod | uint256 | The claim staging period |
isOutputsMerkleRootValid
Check whether an outputs Merkle root is valid.
function isOutputsMerkleRootValid(address appContract, bytes32 outputsMerkleRoot)
public
view
override
returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
outputsMerkleRoot | bytes32 | The outputs Merkle root |
getLastFinalizedMachineMerkleRoot
function getLastFinalizedMachineMerkleRoot(address appContract)
public
view
override
returns (bytes32);
wasInputFinalized
function wasInputFinalized(address appContract, uint256, uint256 blockNumber)
public
view
override
returns (bool);
getEpochLength
Get the epoch length, in number of base-layer blocks.
The epoch number of a block is defined as the integer division of the block number by the epoch length.
function getEpochLength() public view override returns (uint256);
getClaimStagingPeriod
function getClaimStagingPeriod() public view override returns (uint256);
getNumberOfAcceptedClaims
Get the number of claims accepted by the consensus regarding a specific app.
function getNumberOfAcceptedClaims(address appContract)
external
view
override
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
getNumberOfStagedClaims
function getNumberOfStagedClaims(address appContract)
external
view
override
returns (uint256);
getNumberOfSubmittedClaims
Get the number of claims submitted to the consensus regarding a specific app.
function getNumberOfSubmittedClaims(address appContract)
external
view
override
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
supportsInterface
See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC165)
returns (bool);
getClaim
function getClaim(
address appContract,
uint256 lastProcessedBlockNumber,
bytes32 machineMerkleRoot
) public view override returns (Claim memory claim);
acceptClaim
function acceptClaim(
address appContract,
uint256 lastProcessedBlockNumber,
bytes32 machineMerkleRoot
) external override notForeclosed(appContract);
_validateLastProcessedBlockNumber
Validate a last processed block number.
function _validateLastProcessedBlockNumber(uint256 lastProcessedBlockNumber)
internal
view;
Parameters
| Name | Type | Description |
|---|---|---|
lastProcessedBlockNumber | uint256 | The number of the last processed block |
_submitClaim
Submit a claim.
Assumes the machine is proven to be manually yielded with an 'rx accepted' reason.
Assumes outputs Merkle root is proven to be at the start of the machine TX buffer.
Assumes the last processed block number is valid.
Checks whether the app is foreclosed.
Emits a ClaimSubmitted event.
function _submitClaim(
address submitter,
address appContract,
uint256 lastProcessedBlockNumber,
bytes32 outputsMerkleRoot,
bytes32 machineMerkleRoot
) internal notForeclosed(appContract);
Parameters
| Name | Type | Description |
|---|---|---|
submitter | address | The submitter address |
appContract | address | The application contract address |
lastProcessedBlockNumber | uint256 | The number of the last processed block |
outputsMerkleRoot | bytes32 | The output Merkle root |
machineMerkleRoot | bytes32 | The machine Merkle root |
_stageClaim
Stage a claim (if unstaged).
Assumes the machine is proven to be manually yielded with an 'rx accepted' reason.
Assumes outputs Merkle root is proven to be at the start of the machine TX buffer.
Assumes the last processed block number is valid.
Assumes the claim was previously submitted.
Checks whether the app is foreclosed.
Marks the claim as staged (if unstaged).
Emits a ClaimStaged event (if unstaged).
function _stageClaim(
address appContract,
uint256 lastProcessedBlockNumber,
bytes32 outputsMerkleRoot,
bytes32 machineMerkleRoot
) internal notForeclosed(appContract);
Parameters
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
lastProcessedBlockNumber | uint256 | The number of the last processed block |
outputsMerkleRoot | bytes32 | The output Merkle root |
machineMerkleRoot | bytes32 | The machine Merkle root |
_validateMachine
Validates a machine given its Merkle root and a validity proof.
function _validateMachine(
bytes32 machineMerkleRoot,
MachineValidityProof calldata proof
) internal pure returns (bytes32 outputsMerkleRoot);
Parameters
| Name | Type | Description |
|---|---|---|
machineMerkleRoot | bytes32 | The machine Merkle root |
proof | MachineValidityProof | The machine validity proof |
Returns
| Name | Type | Description |
|---|---|---|
outputsMerkleRoot | bytes32 | The proven outputs Merkle root |