BatchDecoder

Git Source

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

NameTypeDescription
_commitDatabytesThe calldata byte array containing the data for committing batches.

Returns

NameTypeDescription
lastCommittedBatchDataIExecutor.StoredBatchInfoThe data for the batch before newly committed batches.
newBatchesDataIExecutor.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

NameTypeDescription
_precommitDatabytesABI-encoded bytes where the first byte is the encoding version, followed by the encoded PrecommitInfo.

Returns

NameTypeDescription
precommitInfoIExecutor.PrecommitInfoThe 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

NameTypeDescription
_commitDatabytesThe calldata byte array containing the data for committing batches.
_processBatchFromuint256The expected batch number of the first commit batch in the array.
_processBatchTouint256The expected batch number of the last commit batch in the array.

Returns

NameTypeDescription
lastCommittedBatchDataIExecutor.StoredBatchInfoThe data for the batch before newly committed batches.
newBatchesDataIExecutor.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

NameTypeDescription
_proofDatabytesThe calldata byte array containing the data for proving batches.

Returns

NameTypeDescription
prevBatchIExecutor.StoredBatchInfoThe batch information before the batches to be verified.
provedBatchesIExecutor.StoredBatchInfo[]An array containing the the batches to be verified.
proofuint256[]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

NameTypeDescription
_proofDatabytesThe commit data to decode.
_processBatchFromuint256The expected batch number of the first batch in the array.
_processBatchTouint256The expected batch number of the last batch in the array.

Returns

NameTypeDescription
prevBatchIExecutor.StoredBatchInfoThe batch information before the batches to be verified.
provedBatchesIExecutor.StoredBatchInfo[]An array containing the the batches to be verified.
proofuint256[]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

NameTypeDescription
_executeDatabytesThe calldata byte array containing the execution data to decode.

Returns

NameTypeDescription
executeDataIExecutor.StoredBatchInfo[]An array containing the stored batch information for execution.
priorityOpsDataPriorityOpsBatchInfo[]Merkle proofs of the priority operations for each batch.
dependencyRootsInteropRoot[][]

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

NameTypeDescription
_executeDatabytesThe calldata byte array containing the execution data to decode.
_processBatchFromuint256The expected batch number of the first batch in the array.
_processBatchTouint256The expected batch number of the last batch in the array.

Returns

NameTypeDescription
executeDataIExecutor.StoredBatchInfo[]An array containing the stored batch information for execution.
priorityOpsDataPriorityOpsBatchInfo[]Merkle proofs of the priority operations for each batch.
dependencyRootsInteropRoot[][]