Application
The Application contract serves as the base layer representation of the application running on the execution layer. The application can interact with other smart contracts through the execution and validation of outputs. These outputs, generated by the application backend on the execution layer, can be proven in the base layer through claims submitted by a consensus contract.
Every Application is subscribed to a consensus contract and governed by a single address (owner). The consensus has the authority to submit claims, which are then used to validate outputs. The owner has complete control over the Application and can replace the consensus at any time. Consequently, users of an Application must trust both the consensus and the application owner. Depending on centralization or ownership concerns, the ownership model can be modified. This process is managed by the consensus contract. For more information about different ownership and consensus models, refer to the consensus contracts.
Functions
constructor()
constructor(
IOutputsMerkleRootValidator outputsMerkleRootValidator,
address initialOwner,
bytes32 templateHash,
bytes memory dataAvailability
) Ownable(initialOwner)
Creates an Application contract.
Parameters
| Name | Type | Description |
|---|---|---|
outputsMerkleRootValidator | IOutputsMerkleRootValidator | The initial outputs Merkle root validator contract |
initialOwner | address | The initial application owner |
templateHash | bytes32 | The initial machine state hash |
dataAvailability | bytes | The data availability solution |
receive()
receive() external payable
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.
executeOutput()
function executeOutput(bytes calldata output, OutputValidityProof calldata proof) external override nonReentrant
Execute an output.
On a successful execution, emits an OutputExecuted event.
Parameters
| Name | Type | Description |
|---|---|---|
output | bytes | The output |
proof | OutputValidityProof | The proof used to validate the output against a claim accepted to the current outputs Merkle root validator contract |
migrateToOutputsMerkleRootValidator()
function migrateToOutputsMerkleRootValidator(IOutputsMerkleRootValidator newOutputsMerkleRootValidator) external override onlyOwner
Migrate the application to a new outputs Merkle root validator.
Can only be called by the application owner.
Parameters
| Name | Type | Description |
|---|---|---|
newOutputsMerkleRootValidator | IOutputsMerkleRootValidator | The new outputs Merkle root validator |
wasOutputExecuted()
function wasOutputExecuted(uint256 outputIndex) external view override returns (bool)
Check whether an output has been executed.
Parameters
| Name | Type | Description |
|---|---|---|
outputIndex | uint256 | The index of output |
Return Values
| Name | Type | Description |
|---|---|---|
[0] | bool | Whether the output has been executed before |
validateOutput()
function validateOutput(bytes calldata output, OutputValidityProof calldata proof) public view override
Validate an output.
May raise any of the errors raised by validateOutputHash.
Parameters
| Name | Type | Description |
|---|---|---|
output | bytes | The output |
proof | OutputValidityProof | The proof used to validate the output against a claim accepted to the current outputs Merkle root validator contract |
validateOutputHash()
function validateOutputHash(bytes32 outputHash, OutputValidityProof calldata proof) public view override
Validate an output hash.
May raise InvalidOutputHashesSiblingsArrayLength or InvalidOutputsMerkleRoot.
Parameters
| Name | Type | Description |
|---|---|---|
outputHash | bytes32 | The output hash |
proof | OutputValidityProof | The proof used to validate the output against a claim accepted to the current outputs Merkle root validator contract |
getTemplateHash()
function getTemplateHash() external view override returns (bytes32)
Get the application's template hash.
Return Values
| Name | Type | Description |
|---|---|---|
[0] | bytes32 | The application's template hash |
getOutputsMerkleRootValidator()
function getOutputsMerkleRootValidator() external view override returns (IOutputsMerkleRootValidator)
Get the current outputs Merkle root validator.
Return Values
| Name | Type | Description |
|---|---|---|
[0] | IOutputsMerkleRootValidator | The current outputs Merkle root validator |
getDataAvailability()
function getDataAvailability() external view override returns (bytes memory)
Get the data availability solution used by application.
Return Values
| Name | Type | Description |
|---|---|---|
[0] | bytes | Solidity ABI-encoded function call that describes the source of inputs that should be fed to the application. |
getDeploymentBlockNumber()
function getDeploymentBlockNumber() external view override returns (uint256)
Get number of block in which contract was deployed.
Return Values
| Name | Type | Description |
|---|---|---|
[0] | uint256 | The deployment block number |
owner()
function owner() public view override(IOwnable, Ownable) returns (address)
Returns the address of the current owner.
Return Values
| Name | Type | Description |
|---|---|---|
[0] | address | The address of the current owner |
renounceOwnership()
function renounceOwnership() public override(IOwnable, Ownable)
Leaves the contract without owner. It will not be possible to call onlyOwner functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.
transferOwnership()
function transferOwnership(address newOwner) public override(IOwnable, Ownable)
Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.
Parameters
| Name | Type | Description |
|---|---|---|
newOwner | address | The new owner address |
Events
OutputExecuted()
event OutputExecuted(uint64 outputIndex, bytes output)
An output was executed from the Application.
Parameters
| Name | Type | Description |
|---|---|---|
outputIndex | uint64 | The index of the output |
output | bytes | The output |
OutputsMerkleRootValidatorChanged()
event OutputsMerkleRootValidatorChanged(IOutputsMerkleRootValidator newOutputsMerkleRootValidator)
The outputs Merkle root validator was changed.
Parameters
| Name | Type | Description |
|---|---|---|
newOutputsMerkleRootValidator | IOutputsMerkleRootValidator | The new outputs Merkle root validator |