L2 Execution Engine

Table of Contents

Fees

L1-Cost fees (L1 Fee Vault)

Fjord L1-Cost fee changes (FastLZ estimator)

Fjord updates the L1 cost calculation function to use a FastLZ-based compression estimator. The L1 cost is computed as:

l1FeeScaled = baseFeeScalar*l1BaseFee*16 + blobFeeScalar*l1BlobBaseFee
estimatedSize = max(minTransactionSize, intercept + fastlzCoef*fastlzSize)
l1Cost = estimatedSize * l1FeeScaled / 1e12

The final l1Cost computation is an unlimited precision unsigned integer computation, with the result in Wei and having uint256 range. The values in this computation, are as follows:

Input argTypeDescriptionValue
l1BaseFeeuint256L1 base fee of the latest L1 origin registered in the L2 chainvaries, L1 fee
l1BlobBaseFeeuint256Blob gas price of the latest L1 origin registered in the L2 chainvaries, L1 fee
fastlzSizeuint256Size of the FastLZ-compressed RLP-encoded signed txvaries, per transaction
baseFeeScalaruint32L1 base fee scalar, scaled by 1e6varies, L2 configuration
blobFeeScalaruint32L1 blob fee scalar, scaled by 1e6varies, L2 configuration
interceptint32Intercept constant, scaled by 1e6 (can be negative)-42_585_600
fastlzCoefuint32FastLZ coefficient, scaled by 1e6836_500
minTransactionSizeuint32A lower bound on transaction size, in bytes100

Previously, baseFeeScalar and blobFeeScalar were used to encode the compression ratio, due to the inaccuracy of the L1 cost function. However, the new cost function takes into account the compression ratio, so these scalars should be adjusted to account for any previous compression ratio they encoded.

FastLZ Implementation

All compression algorithms must be implemented equivalently to the fastlz_compress function in fastlz.c at the following commit.

L1-Cost linear regression details

The intercept and fastlzCoef constants are calculated by linear regression using a dataset of previous L2 transactions. The dataset is generated by iterating over all transactions in a given time range, and performing the following actions. For each transaction:

  1. Compress the payload using FastLZ. Record the size of the compressed payload as fastlzSize.
  2. Emulate the change in batch size adding the transaction to a batch, compressed with Brotli 10. Record the change in batch size as bestEstimateSize.

Once this dataset is generated, a linear regression can be calculated using the bestEstimateSize as the dependent variable and fastlzSize as the independent variable.

We generated a dataset from two weeks of post-Ecotone transactions on Optimism Mainnet, as we found that was the most representative of performance across multiple chains and time periods. More details on the linear regression and datasets used can be found in this repository.

L1 Gas Usage Estimation

The L1GasUsed property on the transaction receipt is updated to take into account the improvement in compression estimation accuracy. The value will be calculated by multiplying the estimatedSize of the transaction from the above L1 cost formula by 16. The value of 16 assumes most of the bytes in the compressed data are non-zero.

The L1GasUsed property is deprecated due to it not capturing the L1 blob gas used by a transaction, and will be removed in a future network upgrade. Users can continue to use the L1Fee field to retrieve the L1 fee for a given transaction.