ethereum-optimism / op-geth

GNU Lesser General Public License v3.0
255 stars 653 forks source link

Fjord: Add FastLZ compression into L1CostFunc #249

Closed mdehoog closed 1 month ago

mdehoog commented 4 months ago

Description We found that the FastLZ algorithm is a pretty good estimate for the actual results we'd see from zlib compressing the batches we write to L1 (albeit with a different scalar as the compression ratios aren't quite as good). See https://github.com/roberto-bayardo/compression-analysis and this sheet.

This PR introduces a flzCompress call into the DataGas part of the L1CostFunc. Companion optimism PR is here: https://github.com/ethereum-optimism/optimism/pull/9618

Tests

TODO

Additional context

The current naive L1Cost approach:

l1fee = ((0s in calldata) * 4 + (1s in calldata) * 16 + 188) * l1BaseFee * 0.684

works pretty well on average, but penalizes very compressible txs (e.g.), and undercharges incompressible txs (e.g.). This change makes the L1CostFunc much fairer compared to real-world L1 costs.