# ZKRollup



> ZKRollup

This contract maintains essential data for zk rollup, including: 1. a list of pending messages, which will be relayed to layer 2; 2. the block tree generated by layer 2 and it&#39;s status.

*the message queue is not used yet, the offline relayer only use events in `L1ScrollMessenger`.*

## Methods

### appendMessage

```solidity
function appendMessage(address _sender, address _target, uint256 _value, uint256 _fee, uint256 _deadline, bytes _message, uint256 _gasLimit) external nonpayable returns (uint256)
```

Append a cross chain message to message queue.

*This function should only be called by L1ScrollMessenger for safety.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _sender | address | The address of message sender in layer 1. |
| _target | address | The address of message recipient in layer 2. |
| _value | uint256 | The amount of ether sent to recipient in layer 2. |
| _fee | uint256 | The amount of ether paid to relayer in layer 2. |
| _deadline | uint256 | The deadline of the message. |
| _message | bytes | The content of the message. |
| _gasLimit | uint256 | Unused, but included for potential forward compatibility considerations. |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

### batches

```solidity
function batches(bytes32) external view returns (bytes32 batchHash, bytes32 parentHash, uint64 batchIndex, bool verified)
```

Mapping from batch id to batch struct.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | bytes32 | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| batchHash | bytes32 | undefined |
| parentHash | bytes32 | undefined |
| batchIndex | uint64 | undefined |
| verified | bool | undefined |

### blocks

```solidity
function blocks(bytes32) external view returns (bytes32 parentHash, bytes32 transactionRoot, uint64 blockHeight, uint64 batchIndex)
```

Mapping from block hash to block struct.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | bytes32 | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| parentHash | bytes32 | undefined |
| transactionRoot | bytes32 | undefined |
| blockHeight | uint64 | undefined |
| batchIndex | uint64 | undefined |

### commitBatch

```solidity
function commitBatch(IZKRollup.Layer2Batch _batch) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _batch | IZKRollup.Layer2Batch | undefined |

### finalizeBatchWithProof

```solidity
function finalizeBatchWithProof(bytes32 _batchId, uint256[] _proof, uint256[] _instances) external nonpayable
```

finalize commited batch in layer 1

*will add more parameters if needed.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _batchId | bytes32 | The identification of the commited batch. |
| _proof | uint256[] | The corresponding proof of the commited batch. |
| _instances | uint256[] | Instance used to verify, generated from batch. |

### finalizedBatches

```solidity
function finalizedBatches(uint256) external view returns (bytes32)
```

Mapping from batch index to finalized batch id.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bytes32 | undefined |

### getMessageHashByIndex

```solidity
function getMessageHashByIndex(uint256 _index) external view returns (bytes32)
```

Return the message hash by index.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _index | uint256 | The index to query. |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bytes32 | undefined |

### getNextQueueIndex

```solidity
function getNextQueueIndex() external view returns (uint256)
```

Return the index of the first queue element not yet executed.




#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

### getQeueuLength

```solidity
function getQeueuLength() external view returns (uint256)
```

Return the total number of appended message.




#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

### importGenesisBlock

```solidity
function importGenesisBlock(IZKRollup.Layer2BlockHeader _genesis) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _genesis | IZKRollup.Layer2BlockHeader | undefined |

### initialize

```solidity
function initialize(uint256 _chainId) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _chainId | uint256 | undefined |

### lastFinalizedBatchID

```solidity
function lastFinalizedBatchID() external view returns (bytes32)
```

The latest finalized batch id.




#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bytes32 | undefined |

### layer2ChainId

```solidity
function layer2ChainId() external view returns (uint256)
```

The chain id of the corresponding layer 2 chain.




#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

### layer2GasLimit

```solidity
function layer2GasLimit(uint256) external view returns (uint256)
```

Return the layer 2 block gas limit.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined |

### messenger

```solidity
function messenger() external view returns (address)
```

The address of L1ScrollMessenger.




#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

### operator

```solidity
function operator() external view returns (address)
```

The address of operator.




#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

### owner

```solidity
function owner() external view returns (address)
```



*Returns the address of the current owner.*


#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |

### renounceOwnership

```solidity
function renounceOwnership() external nonpayable
```



*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*


### revertBatch

```solidity
function revertBatch(bytes32 _batchId) external nonpayable
```

revert a pending batch.

*one can only revert unfinalized batches.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _batchId | bytes32 | The identification of the batch. |

### transferOwnership

```solidity
function transferOwnership(address newOwner) external nonpayable
```



*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| newOwner | address | undefined |

### updateMessenger

```solidity
function updateMessenger(address _newMessenger) external nonpayable
```

Update the address of messenger.

*This function can only called by contract owner.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _newMessenger | address | The new messenger address to update. |

### updateOperator

```solidity
function updateOperator(address _newOperator) external nonpayable
```

Update the address of operator.

*This function can only called by contract owner.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _newOperator | address | The new operator address to update. |

### verifyMessageStateProof

```solidity
function verifyMessageStateProof(uint256 _batchIndex, uint256 _blockHeight) external view returns (bool)
```

Verify a state proof for message relay.

*add more fields.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _batchIndex | uint256 | undefined |
| _blockHeight | uint256 | undefined |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bool | undefined |



## Events

### CommitBatch

```solidity
event CommitBatch(bytes32 indexed _batchId, bytes32 _batchHash, uint256 _batchIndex, bytes32 _parentHash)
```

Emitted when a new batch is commited.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _batchId `indexed` | bytes32 | undefined |
| _batchHash  | bytes32 | undefined |
| _batchIndex  | uint256 | undefined |
| _parentHash  | bytes32 | undefined |

### FinalizeBatch

```solidity
event FinalizeBatch(bytes32 indexed _batchId, bytes32 _batchHash, uint256 _batchIndex, bytes32 _parentHash)
```

Emitted when a batch is finalized.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _batchId `indexed` | bytes32 | undefined |
| _batchHash  | bytes32 | undefined |
| _batchIndex  | uint256 | undefined |
| _parentHash  | bytes32 | undefined |

### OwnershipTransferred

```solidity
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| previousOwner `indexed` | address | undefined |
| newOwner `indexed` | address | undefined |

### RevertBatch

```solidity
event RevertBatch(bytes32 indexed _batchId)
```

Emitted when a batch is reverted.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _batchId `indexed` | bytes32 | undefined |

### UpdateMesssenger

```solidity
event UpdateMesssenger(address _oldMesssenger, address _newMesssenger)
```

Emitted when owner updates address of messenger



#### Parameters

| Name | Type | Description |
|---|---|---|
| _oldMesssenger  | address | The address of old messenger contract. |
| _newMesssenger  | address | The address of new messenger contract. |

### UpdateOperator

```solidity
event UpdateOperator(address _oldOperator, address _newOperator)
```

Emitted when owner updates address of operator



#### Parameters

| Name | Type | Description |
|---|---|---|
| _oldOperator  | address | The address of old operator. |
| _newOperator  | address | The address of new operator. |



