IApplication

Git Source

Inherits: IOwnable

The base layer incarnation of an application running on the execution layer.

The state of the application advances through inputs sent to an IInputBox contract.

These inputs can be sent either directly, or indirectly through portals.

Reader nodes can retrieve inputs sent to the IInputBox contract through events, and feed them into the machine.

Validator nodes can also submit claims to the IOutputsMerkleRootValidator contract (see the getOutputsMerkleRootValidator function).

Once accepted, claims can be used to validate outputs generated by the machine.

Some outputs are executable, which means they can have on-chain side effects.

Every application is subscribed to some outputs Merkle root validator, and may be governed by some owner. The outputs Merkle root validator has the power to accept claims, which, in turn, are used to validate outputs. Meanwhile, the owner can replace the outputs Merkle root validator at any time. Therefore, the users of an application must trust both the outputs Merkle root validator and the application owner.

There are several ownership models to choose from:

  • no owner (address zero)
  • individual signer (externally-owned account)
  • multiple signers (multi-sig)
  • DAO (decentralized autonomous organization)
  • self-owned application (off-chain governance logic)

Functions

migrateToOutputsMerkleRootValidator

Migrate the application to a new outputs Merkle root validator.

Can only be called by the application owner.

function migrateToOutputsMerkleRootValidator(
    IOutputsMerkleRootValidator newOutputsMerkleRootValidator
) external;

Parameters

NameTypeDescription
newOutputsMerkleRootValidatorIOutputsMerkleRootValidatorThe new outputs Merkle root validator

executeOutput

Execute an output.

On a successful execution, emits a OutputExecuted event.

May raise any of the errors raised by validateOutput, as well as OutputNotExecutable and OutputNotReexecutable.

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

Parameters

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

wasOutputExecuted

Check whether an output has been executed.

function wasOutputExecuted(uint256 outputIndex) external view 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)
    external
    view;

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)
    external
    view;

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 returns (bytes32);

Returns

NameTypeDescription
<none>bytes32The application's template hash

getOutputsMerkleRootValidator

Get the current outputs Merkle root validator.

function getOutputsMerkleRootValidator()
    external
    view
    returns (IOutputsMerkleRootValidator);

Returns

NameTypeDescription
<none>IOutputsMerkleRootValidatorThe current outputs Merkle root validator

getDataAvailability

Get the data availability solution used by application.

function getDataAvailability() external view 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 returns (uint256);

Events

OutputsMerkleRootValidatorChanged

MUST trigger when a new outputs Merkle root validator is chosen.

event OutputsMerkleRootValidatorChanged(
    IOutputsMerkleRootValidator newOutputsMerkleRootValidator
);

Parameters

NameTypeDescription
newOutputsMerkleRootValidatorIOutputsMerkleRootValidatorThe new outputs Merkle root validator

OutputExecuted

MUST trigger when an output is executed.

event OutputExecuted(uint64 outputIndex, bytes output);

Parameters

NameTypeDescription
outputIndexuint64The index of the output
outputbytesThe output

Errors

OutputNotExecutable

Could not execute an output, because the application contract doesn't know how to.

error OutputNotExecutable(bytes output);

Parameters

NameTypeDescription
outputbytesThe output

OutputNotReexecutable

Could not execute an output, because it was already executed.

error OutputNotReexecutable(bytes output);

Parameters

NameTypeDescription
outputbytesThe output

InsufficientFunds

Could not execute an output, because the application contract doesn't have enough Ether.

error InsufficientFunds(uint256 value, uint256 balance);

Parameters

NameTypeDescription
valueuint256The amount of Wei necessary for the execution of the output
balanceuint256The current application contract balance

InvalidOutputHashesSiblingsArrayLength

Raised when the output hashes siblings array has an invalid size.

Please consult CanonicalMachine for the maximum number of outputs.

error InvalidOutputHashesSiblingsArrayLength();

InvalidOutputsMerkleRoot

Raised when the computed outputs Merkle root is invalid, according to the current outputs Merkle root validator.

error InvalidOutputsMerkleRoot(bytes32 outputsMerkleRoot);