Application

Git Source

Inherits: IApplication, Ownable, ERC721Holder, ERC1155Holder, ReentrancyGuard

State Variables

_deploymentBlockNumber

Deployment block number

uint256 immutable _deploymentBlockNumber = block.number;

_templateHash

The initial machine state hash.

See the getTemplateHash function.

bytes32 internal immutable _templateHash;

_executed

Keeps track of which outputs have been executed.

See the wasOutputExecuted function.

BitMaps.BitMap internal _executed;

_outputsMerkleRootValidator

The current outputs Merkle root validator contract.

See the getOutputsMerkleRootValidator and migrateToOutputsMerkleRootValidator functions.

IOutputsMerkleRootValidator internal _outputsMerkleRootValidator;

_dataAvailability

The data availability solution.

See the getDataAvailability function.

bytes internal _dataAvailability;

Functions

constructor

Creates an Application contract.

Reverts if the initial application owner address is zero.

constructor(
    IOutputsMerkleRootValidator outputsMerkleRootValidator,
    address initialOwner,
    bytes32 templateHash,
    bytes memory dataAvailability
) Ownable(initialOwner);

Parameters

NameTypeDescription
outputsMerkleRootValidatorIOutputsMerkleRootValidatorThe initial outputs Merkle root validator contract
initialOwneraddressThe initial application owner
templateHashbytes32The initial machine state hash
dataAvailabilitybytes

receive

Accept Ether transfers.

If you wish to transfer Ether to an application while informing the backend of it, then please do so through the Ether portal contract.

receive() external payable;

executeOutput

Execute an output.

On a successful execution, emits a OutputExecuted event.

function executeOutput(bytes calldata output, OutputValidityProof calldata proof)
    external
    override
    nonReentrant;

Parameters

NameTypeDescription
outputbytesThe output
proofOutputValidityProofThe proof used to validate the output against a claim accepted to the current outputs Merkle root validator contract

migrateToOutputsMerkleRootValidator

Migrate the application to a new outputs Merkle root validator.

Can only be called by the application owner.

function migrateToOutputsMerkleRootValidator(
    IOutputsMerkleRootValidator newOutputsMerkleRootValidator
) external override onlyOwner;

Parameters

NameTypeDescription
newOutputsMerkleRootValidatorIOutputsMerkleRootValidatorThe new outputs Merkle root validator

wasOutputExecuted

Check whether an output has been executed.

function wasOutputExecuted(uint256 outputIndex) external view override returns (bool);

Parameters

NameTypeDescription
outputIndexuint256The index of output

Returns

NameTypeDescription
<none>boolWhether the output has been executed before

validateOutput

Validate an output.

May raise any of the errors raised by validateOutputHash.

function validateOutput(bytes calldata output, OutputValidityProof calldata proof)
    public
    view
    override;

Parameters

NameTypeDescription
outputbytesThe output
proofOutputValidityProofThe proof used to validate the output against a claim accepted to the current outputs Merkle root validator contract

validateOutputHash

Validate an output hash.

May raise InvalidOutputHashesSiblingsArrayLength or InvalidOutputsMerkleRoot.

function validateOutputHash(bytes32 outputHash, OutputValidityProof calldata proof)
    public
    view
    override;

Parameters

NameTypeDescription
outputHashbytes32The output hash
proofOutputValidityProofThe proof used to validate the output against a claim accepted to the current outputs Merkle root validator contract

getTemplateHash

Get the application's template hash.

function getTemplateHash() external view override returns (bytes32);

Returns

NameTypeDescription
<none>bytes32The application's template hash

getOutputsMerkleRootValidator

Get the current outputs Merkle root validator.

function getOutputsMerkleRootValidator()
    external
    view
    override
    returns (IOutputsMerkleRootValidator);

Returns

NameTypeDescription
<none>IOutputsMerkleRootValidatorThe current outputs Merkle root validator

getDataAvailability

Get the data availability solution used by application.

function getDataAvailability() external view override returns (bytes memory);

Returns

NameTypeDescription
<none>bytesSolidity ABI-encoded function call that describes the source of inputs that should be fed to the application.

getDeploymentBlockNumber

Get number of block in which contract was deployed

function getDeploymentBlockNumber() external view override returns (uint256);

owner

function owner() public view override(IOwnable, Ownable) returns (address);

renounceOwnership

function renounceOwnership() public override(IOwnable, Ownable);

transferOwnership

function transferOwnership(address newOwner) public override(IOwnable, Ownable);

_isOutputsMerkleRootValid

Check if an outputs Merkle root is valid, according to the current outputs Merkle root validator.

function _isOutputsMerkleRootValid(bytes32 outputsMerkleRoot)
    internal
    view
    returns (bool);

Parameters

NameTypeDescription
outputsMerkleRootbytes32The output Merkle root

_executeVoucher

Executes a voucher

function _executeVoucher(bytes calldata arguments) internal;

Parameters

NameTypeDescription
argumentsbytesABI-encoded arguments

_executeDelegateCallVoucher

Executes a delegatecall voucher

function _executeDelegateCallVoucher(bytes calldata arguments) internal;

Parameters

NameTypeDescription
argumentsbytesABI-encoded arguments