TransactionValidator

Git Source

Author: Matter Labs

Note: security-contact: security@matterlabs.dev

Functions

validateL1ToL2Transaction

Used to validate key properties of an L1->L2 transaction

function validateL1ToL2Transaction(
  L2CanonicalTransaction memory _transaction,
  bytes memory _encoded,
  uint256 _priorityTxMaxGasLimit,
  uint256 _priorityTxMaxPubdata
) internal pure;

Parameters

NameTypeDescription
_transactionL2CanonicalTransactionThe transaction to validate
_encodedbytesThe abi encoded bytes of the transaction
_priorityTxMaxGasLimituint256The max gas limit, generally provided from Storage.sol
_priorityTxMaxPubdatauint256The maximal amount of pubdata that a single L1->L2 transaction can emit

validateUpgradeTransaction

Used to validate upgrade transactions

function validateUpgradeTransaction(L2CanonicalTransaction memory _transaction)
  internal
  pure;

Parameters

NameTypeDescription
_transactionL2CanonicalTransactionThe transaction to validate

getMinimalPriorityTransactionGasLimit

Calculates the approximate minimum gas limit required for executing a priority transaction.

function getMinimalPriorityTransactionGasLimit(
  uint256 _encodingLength,
  uint256 _numberOfFactoryDependencies,
  uint256 _l2GasPricePerPubdata
) internal pure returns (uint256);

Parameters

NameTypeDescription
_encodingLengthuint256The length of the priority transaction encoding in bytes.
_numberOfFactoryDependenciesuint256The number of new factory dependencies that will be added.
_l2GasPricePerPubdatauint256The L2 gas price for publishing the priority transaction on L2.

Returns

NameTypeDescription
<none>uint256The minimum gas limit required to execute the priority transaction. Note: The calculation includes the main cost of the priority transaction, however, in reality, the operator can spend a little more gas on overheads.

getTransactionBodyGasLimit

Based on the full L2 gas limit (that includes the batch overhead) and other properties of the transaction, returns the l2GasLimit for the body of the transaction (the actual execution).

function getTransactionBodyGasLimit(
  uint256 _totalGasLimit,
  uint256 _encodingLength
) internal pure returns (uint256 txBodyGasLimit);

Parameters

NameTypeDescription
_totalGasLimituint256The L2 gas limit that includes both the overhead for processing the batch and the L2 gas needed to process the transaction itself (i.e. the actual l2GasLimit that will be used for the transaction).
_encodingLengthuint256The length of the ABI-encoding of the transaction.

getOverheadForTransaction

Based on the total L2 gas limit and several other parameters of the transaction returns the part of the L2 gas that will be spent on the batch's overhead.

The details of how this function works can be checked in the documentation of the fee model of ZKsync. The appropriate comments are also present in the Rust implementation description of function get_maximal_allowed_overhead.

function getOverheadForTransaction(uint256 _encodingLength)
  internal
  pure
  returns (uint256 batchOverheadForTransaction);

Parameters

NameTypeDescription
_encodingLengthuint256The length of the binary encoding of the transaction in bytes