Application
Inherits: IApplication, Ownable, ERC721Holder, ERC1155Holder, RollupsContract
State Variables
DEPLOYMENT_BLOCK_NUMBER
Deployment block number
uint256 immutable DEPLOYMENT_BLOCK_NUMBER = block.number
TEMPLATE_HASH
The initial machine state hash.
See the getTemplateHash function.
bytes32 immutable TEMPLATE_HASH
INPUT_BOX
The input box contract.
See the getInputBox function.
IInputBox immutable INPUT_BOX
GUARDIAN
The guardian address.
See the getGuardian function.
address immutable GUARDIAN
LOG2_LEAVES_PER_ACCOUNT
The base-2 log of leaves per account.
See the getLog2LeavesPerAccount function.
uint8 immutable LOG2_LEAVES_PER_ACCOUNT
LOG2_MAX_NUM_OF_ACCOUNTS
The base-2 log of max. num. of accounts.
See the getLog2MaxNumOfAccounts function.
uint8 immutable LOG2_MAX_NUM_OF_ACCOUNTS
ACCOUNTS_DRIVE_START_INDEX
The offset of the accounts drive.
See the getAccountsDriveStartIndex function.
uint64 immutable ACCOUNTS_DRIVE_START_INDEX
REFUND_OUTPUT_BUILDER
The refund output builder contract.
See the getRefundOutputBuilder function.
IRefundOutputBuilder immutable REFUND_OUTPUT_BUILDER
WITHDRAWAL_OUTPUT_BUILDER
The withdrawal output builder contract.
See the getWithdrawalOutputBuilder function.
IWithdrawalOutputBuilder immutable WITHDRAWAL_OUTPUT_BUILDER
_executed
Keeps track of which outputs have been executed.
See the wasOutputExecuted function.
BitMaps.BitMap internal _executed
_refunded
Keeps track of which inputs have been refunded.
See the wasRefundForInputIssued function.
BitMaps.BitMap internal _refunded
_withdrawn
Keeps track of which accounts have been withdrawn.
See the wereAccountFundsWithdrawn function.
BitMaps.BitMap internal _withdrawn
_outputsMerkleRootValidator
The current outputs Merkle root validator contract.
See the getOutputsMerkleRootValidator and migrateToOutputsMerkleRootValidator functions.
IOutputsMerkleRootValidator internal _outputsMerkleRootValidator
_isForeclosed
Whether the application has been foreclosed by the guardian.
See the isForeclosed function.
bool internal _isForeclosed
_wasAccountsDriveMerkleRootProved
Whether the accounts drive Merkle root was proved.
See the getAccountsDriveMerkleRoot and
proveAccountsDriveMerkleRoot functions.
bool internal _wasAccountsDriveMerkleRootProved
_accountsDriveMerkleRoot
The accounts drive Merkle root.
See the getAccountsDriveMerkleRoot and
proveAccountsDriveMerkleRoot functions.
bytes32 internal _accountsDriveMerkleRoot
_numOfExecutedOutputs
The number of outputs executed by the application.
See the getNumberOfExecutedOutputs function.
uint256 _numOfExecutedOutputs
_numOfIssuedRefunds
The number of refunds issued by the application.
See the getNumberOfIssuedRefunds function.
uint256 _numOfIssuedRefunds
_numOfWithdrawals
The number of withdrawals from the application.
See the getNumberOfWithdrawals function.
uint256 _numOfWithdrawals
Functions
constructor
Creates an Application contract.
Reverts if the initial application owner address is zero.
constructor(
IOutputsMerkleRootValidator outputsMerkleRootValidator,
address initialOwner,
bytes32 templateHash,
IInputBox inputBox,
IRefundOutputBuilder refundOutputBuilder,
WithdrawalConfig memory withdrawalConfig
) Ownable(initialOwner);
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 |
inputBox | IInputBox | The input box contract |
refundOutputBuilder | IRefundOutputBuilder | The refund output builder |
withdrawalConfig | WithdrawalConfig | The withdrawal configuration |
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;
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 |
issueRefund
function issueRefund(uint256 inputIndex, bytes calldata input)
external
override
onlyForeclosed;
proveAccountsDriveMerkleRoot
function proveAccountsDriveMerkleRoot(
bytes32 accountsDriveMerkleRoot,
bytes32[] calldata proof
) external override onlyForeclosed;
withdraw
function withdraw(bytes calldata account, AccountValidityProof calldata proof)
external
override
onlyForeclosed;
migrateToOutputsMerkleRootValidator
Migrate the application to a new outputs Merkle root validator.
Can only be called by the application owner.
May raise OwnableUnauthorizedAccount or Foreclosed.
function migrateToOutputsMerkleRootValidator(IOutputsMerkleRootValidator newOutputsMerkleRootValidator)
external
override
onlyOwner
notForeclosed
onDeploymentBlock;
Parameters
| Name | Type | Description |
|---|---|---|
newOutputsMerkleRootValidator | IOutputsMerkleRootValidator | The new outputs Merkle root validator |
foreclose
function foreclose() external override onlyGuardian notForeclosed;
wasOutputExecuted
Check whether an output has been executed.
function wasOutputExecuted(uint256 outputIndex)
external
view
override
returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
outputIndex | uint256 | The index of output |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether the output has been executed before or is currently being executed (in the current transaction) |
wasRefundForInputIssued
function wasRefundForInputIssued(uint256 inputIndex)
external
view
override
returns (bool);
wereAccountFundsWithdrawn
function wereAccountFundsWithdrawn(uint256 accountIndex)
external
view
returns (bool);
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
| 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
Validate an output hash.
May raise InvalidOutputHashesSiblingsArrayLength
or InvalidOutputsMerkleRoot.
function validateOutputHash(bytes32 outputHash, OutputValidityProof calldata proof)
public
view
override;
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 |
validateInput
function validateInput(uint256 inputIndex, bytes calldata input)
public
view
override
returns (uint256 blockNumber, address inputSender, bytes memory inputPayload);
validateInputHash
function validateInputHash(uint256 inputIndex, bytes32 inputHash)
public
view
override;
validateAccount
function validateAccount(bytes calldata account, AccountValidityProof calldata proof)
public
view
override;
validateAccountMerkleRoot
function validateAccountMerkleRoot(
bytes32 accountMerkleRoot,
AccountValidityProof calldata proof
) public view override;
getTemplateHash
Get the application's template hash.
function getTemplateHash() public view override returns (bytes32);
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes32 | The application's template hash |
getOutputsMerkleRootValidator
Get the current outputs Merkle root validator.
function getOutputsMerkleRootValidator()
public
view
override
returns (IOutputsMerkleRootValidator);
Returns
| Name | Type | Description |
|---|---|---|
<none> | IOutputsMerkleRootValidator | The current outputs Merkle root validator |
getInputBox
function getInputBox() public view override returns (IInputBox);
getDeploymentBlockNumber
Get number of block in which contract was deployed
function getDeploymentBlockNumber() external view override returns (uint256);
getNumberOfExecutedOutputs
Get number of outputs executed by the application.
function getNumberOfExecutedOutputs() external view override returns (uint256);
getNumberOfIssuedRefunds
function getNumberOfIssuedRefunds() external view override returns (uint256);
getNumberOfWithdrawals
function getNumberOfWithdrawals() external view override returns (uint256);
getLog2LeavesPerAccount
function getLog2LeavesPerAccount() public view override returns (uint8);
getLog2MaxNumOfAccounts
function getLog2MaxNumOfAccounts() public view override returns (uint8);
getAccountsDriveStartIndex
function getAccountsDriveStartIndex() public view override returns (uint64);
getGuardian
function getGuardian() public view override returns (address);
getRefundOutputBuilder
function getRefundOutputBuilder()
public
view
override
returns (IRefundOutputBuilder);
getWithdrawalOutputBuilder
function getWithdrawalOutputBuilder()
public
view
override
returns (IWithdrawalOutputBuilder);
isForeclosed
function isForeclosed() public view override returns (bool);
getWithdrawalConfig
function getWithdrawalConfig()
external
view
override
returns (WithdrawalConfig memory withdrawalConfig);
getAccountsDriveMerkleRoot
function getAccountsDriveMerkleRoot()
external
view
override
returns (bool wasAccountsDriveMerkleRootProved, bytes32 accountsDriveMerkleRoot);
owner
Returns the address of the current owner.
function owner() public view override(IOwnable, Ownable) returns (address);
renounceOwnership
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.
function renounceOwnership() public override(IOwnable, Ownable);
transferOwnership
Transfers ownership of the contract to a new account (newOwner).
Can only be called by the current owner.
function transferOwnership(address newOwner) public override(IOwnable, Ownable);
onlyGuardian
modifier onlyGuardian() ;
notForeclosed
modifier notForeclosed() ;
onlyForeclosed
modifier onlyForeclosed() ;
onDeploymentBlock
modifier onDeploymentBlock() ;
_getLog2AccountsDriveSize
Get the log (base 2) of the number of bytes in the machine memory that are reserved for the accounts drive.
function _getLog2AccountsDriveSize() internal view returns (uint8);
_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
| Name | Type | Description |
|---|---|---|
outputsMerkleRoot | bytes32 | The output Merkle root |
_getLastFinalizedMachineMerkleRoot
Get the last finalized machine Merkle root, according to the current outputs Merkle root validator.
If the outputs Merkle root validator returns a zeroed bytes32 value, signaling that no machine Merkle root has been finalized yet, we instead use the immutable template hash value set at construction time.
function _getLastFinalizedMachineMerkleRoot()
internal
view
returns (bytes32 lastFinalizedMachineMerkleRoot);
Returns
| Name | Type | Description |
|---|---|---|
lastFinalizedMachineMerkleRoot | bytes32 | The last finalized machine Merkle root |
_wasInputFinalized
Check if an input was finalized, according to the current outputs Merkle root validator.
function _wasInputFinalized(uint256 inputIndex, uint256 blockNumber)
internal
view
returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
inputIndex | uint256 | The index of the input in the application's input box |
blockNumber | uint256 | The number of the base-layer block in which the input was added |
_buildRefundOutput
Build a refund output from an input, using the refund output builder contract.
function _buildRefundOutput(address sender, bytes memory payload)
internal
view
returns (bytes memory output);
Parameters
| Name | Type | Description |
|---|---|---|
sender | address | The input sender |
payload | bytes | The input payload |
Returns
| Name | Type | Description |
|---|---|---|
output | bytes | The refund output |
_buildWithdrawalOutput
Build a withdrawal output from an account, using the withdrawal output builder contract.
function _buildWithdrawalOutput(bytes calldata account)
internal
view
returns (bytes memory output);
Parameters
| Name | Type | Description |
|---|---|---|
account | bytes | The account |
Returns
| Name | Type | Description |
|---|---|---|
output | bytes | The withdrawal output |
_executeOutput
Executes an output
function _executeOutput(bytes memory output) internal;
Parameters
| Name | Type | Description |
|---|---|---|
output | bytes | The output |
_executeVoucher
Executes a voucher
function _executeVoucher(bytes memory arguments) internal;
Parameters
| Name | Type | Description |
|---|---|---|
arguments | bytes | ABI-encoded arguments |
_executeDelegateCallVoucher
Executes a delegatecall voucher
function _executeDelegateCallVoucher(bytes memory arguments) internal;
Parameters
| Name | Type | Description |
|---|---|---|
arguments | bytes | ABI-encoded arguments |
_ensureMsgSenderIsGuardian
Ensures the message sender is the guardian.
function _ensureMsgSenderIsGuardian() internal view;
_ensureAppIsNotForeclosed
Ensures the application is not foreclosed.
function _ensureAppIsNotForeclosed() internal view;
_ensureAppIsForeclosed
Ensures the application is foreclosed.
function _ensureAppIsForeclosed() internal view;
_ensureOnDeploymentBlock
Ensures the current block is the deployment block.
function _ensureOnDeploymentBlock() internal view;