BatchDecoder
Author: Matter Labs
Utility library for decoding and validating batch data.
This library decodes commit, proof, and execution batch data and verifies batch number bounds. It reverts with custom errors when the data is invalid or unsupported encoding is used.
Note: security-contact: security@matterlabs.dev
State Variables
SUPPORTED_ENCODING_VERSION
The currently supported encoding version.
uint8 internal constant SUPPORTED_ENCODING_VERSION = 1;
Functions
_decodeCommitData
Decodes commit data from a calldata bytes into the last committed batch data and an array of new batch data.
function _decodeCommitData(bytes calldata _commitData)
private
pure
returns (
IExecutor.StoredBatchInfo memory lastCommittedBatchData,
IExecutor.CommitBatchInfo[] memory newBatchesData
);
Parameters
Name | Type | Description |
---|---|---|
_commitData | bytes | The calldata byte array containing the data for committing batches. |
Returns
Name | Type | Description |
---|---|---|
lastCommittedBatchData | IExecutor.StoredBatchInfo | The data for the batch before newly committed batches. |
newBatchesData | IExecutor.CommitBatchInfo[] | An array containing the newly committed batches. |
decodeAndCheckPrecommitData
Decodes and validates precommit data for a batch, ensuring the encoding version is supported.
The first byte of _precommitData
is interpreted as the encoding version and must equal SUPPORTED_ENCODING_VERSION
.
If it does, the remainder of the data is decoded into an IExecutor.PrecommitInfo
struct. Otherwise, this call reverts.
function decodeAndCheckPrecommitData(bytes calldata _precommitData)
internal
pure
returns (IExecutor.PrecommitInfo memory precommitInfo);
Parameters
Name | Type | Description |
---|---|---|
_precommitData | bytes | ABI-encoded bytes where the first byte is the encoding version, followed by the encoded PrecommitInfo . |
Returns
Name | Type | Description |
---|---|---|
precommitInfo | IExecutor.PrecommitInfo | The decoded PrecommitInfo containing transaction status commitments. |
decodeAndCheckCommitData
Decodes the commit data and checks that the provided batch bounds are correct.
Note that it only checks that the last and the first batches in the array correspond to the provided bounds. The fact that the batches inside the array are provided in the correct order should be checked by the caller.
function decodeAndCheckCommitData(
bytes calldata _commitData,
uint256 _processBatchFrom,
uint256 _processBatchTo
)
internal
pure
returns (
IExecutor.StoredBatchInfo memory lastCommittedBatchData,
IExecutor.CommitBatchInfo[] memory newBatchesData
);
Parameters
Name | Type | Description |
---|---|---|
_commitData | bytes | The calldata byte array containing the data for committing batches. |
_processBatchFrom | uint256 | The expected batch number of the first commit batch in the array. |
_processBatchTo | uint256 | The expected batch number of the last commit batch in the array. |
Returns
Name | Type | Description |
---|---|---|
lastCommittedBatchData | IExecutor.StoredBatchInfo | The data for the batch before newly committed batches. |
newBatchesData | IExecutor.CommitBatchInfo[] | An array containing the newly committed batches. |
_decodeProofData
Decodes proof data from a calldata byte array into the previous batch, an array of proved batches, and a proof array.
function _decodeProofData(bytes calldata _proofData)
private
pure
returns (
IExecutor.StoredBatchInfo memory prevBatch,
IExecutor.StoredBatchInfo[] memory provedBatches,
uint256[] memory proof
);
Parameters
Name | Type | Description |
---|---|---|
_proofData | bytes | The calldata byte array containing the data for proving batches. |
Returns
Name | Type | Description |
---|---|---|
prevBatch | IExecutor.StoredBatchInfo | The batch information before the batches to be verified. |
provedBatches | IExecutor.StoredBatchInfo[] | An array containing the the batches to be verified. |
proof | uint256[] | An array containing the proof for the verifier. |
decodeAndCheckProofData
Decodes the commit data and checks that the provided batch bounds are correct.
Note that it only checks that the last and the first batches in the array correspond to the provided bounds. The fact that the batches inside the array are provided in the correct order should be checked by the caller.
function decodeAndCheckProofData(
bytes calldata _proofData,
uint256 _processBatchFrom,
uint256 _processBatchTo
)
internal
pure
returns (
IExecutor.StoredBatchInfo memory prevBatch,
IExecutor.StoredBatchInfo[] memory provedBatches,
uint256[] memory proof
);
Parameters
Name | Type | Description |
---|---|---|
_proofData | bytes | The commit data to decode. |
_processBatchFrom | uint256 | The expected batch number of the first batch in the array. |
_processBatchTo | uint256 | The expected batch number of the last batch in the array. |
Returns
Name | Type | Description |
---|---|---|
prevBatch | IExecutor.StoredBatchInfo | The batch information before the batches to be verified. |
provedBatches | IExecutor.StoredBatchInfo[] | An array containing the the batches to be verified. |
proof | uint256[] | An array containing the proof for the verifier. |
_decodeExecuteData
Decodes execution data from a calldata byte array into an array of stored batch information.
function _decodeExecuteData(bytes calldata _executeData)
private
pure
returns (
IExecutor.StoredBatchInfo[] memory executeData,
PriorityOpsBatchInfo[] memory priorityOpsData,
InteropRoot[][] memory dependencyRoots
);
Parameters
Name | Type | Description |
---|---|---|
_executeData | bytes | The calldata byte array containing the execution data to decode. |
Returns
Name | Type | Description |
---|---|---|
executeData | IExecutor.StoredBatchInfo[] | An array containing the stored batch information for execution. |
priorityOpsData | PriorityOpsBatchInfo[] | Merkle proofs of the priority operations for each batch. |
dependencyRoots | InteropRoot[][] |
decodeAndCheckExecuteData
Decodes the execute data and checks that the provided batch bounds are correct.
Note that it only checks that the last and the first batches in the array correspond to the provided bounds. The fact that the batches inside the array are provided in the correct order should be checked by the caller.
function decodeAndCheckExecuteData(
bytes calldata _executeData,
uint256 _processBatchFrom,
uint256 _processBatchTo
)
internal
pure
returns (
IExecutor.StoredBatchInfo[] memory executeData,
PriorityOpsBatchInfo[] memory priorityOpsData,
InteropRoot[][] memory dependencyRoots
);
Parameters
Name | Type | Description |
---|---|---|
_executeData | bytes | The calldata byte array containing the execution data to decode. |
_processBatchFrom | uint256 | The expected batch number of the first batch in the array. |
_processBatchTo | uint256 | The expected batch number of the last batch in the array. |
Returns
Name | Type | Description |
---|---|---|
executeData | IExecutor.StoredBatchInfo[] | An array containing the stored batch information for execution. |
priorityOpsData | PriorityOpsBatchInfo[] | Merkle proofs of the priority operations for each batch. |
dependencyRoots | InteropRoot[][] |