Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AbstractConsensus

Git Source

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

NameTypeDescription
epochLengthuint256The epoch length
claimStagingPerioduint256The claim staging period

isOutputsMerkleRootValid

Check whether an outputs Merkle root is valid.

function isOutputsMerkleRootValid(address appContract, bytes32 outputsMerkleRoot)
    public
    view
    override
    returns (bool);

Parameters

NameTypeDescription
appContractaddressThe application contract address
outputsMerkleRootbytes32The 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

NameTypeDescription
appContractaddressThe 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

NameTypeDescription
appContractaddressThe 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

NameTypeDescription
lastProcessedBlockNumberuint256The 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

NameTypeDescription
submitteraddressThe submitter address
appContractaddressThe application contract address
lastProcessedBlockNumberuint256The number of the last processed block
outputsMerkleRootbytes32The output Merkle root
machineMerkleRootbytes32The 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

NameTypeDescription
appContractaddressThe application contract address
lastProcessedBlockNumberuint256The number of the last processed block
outputsMerkleRootbytes32The output Merkle root
machineMerkleRootbytes32The 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

NameTypeDescription
machineMerkleRootbytes32The machine Merkle root
proofMachineValidityProofThe machine validity proof

Returns

NameTypeDescription
outputsMerkleRootbytes32The proven outputs Merkle root