ethereum-optimism / op-geth

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

[Fjord] Add FastLZ compression into L1CostFunc #202

Closed mdehoog closed 4 months ago

mdehoog commented 6 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: ethereum-optimism/optimism#8635.

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.

roberto-bayardo commented 6 months ago

Something annoying about the L1CostFunc impl is a lot of the cost logic ends up duplicated in receipts.go, so you kind of have to re-implement stuff there.

I tried to improve the abstractions a bit in this PR in preparation for 4844: https://github.com/ethereum-optimism/op-geth/pull/203

I think it will make this change a bit cleaner if/when merged.

mdehoog commented 4 months ago

Closing in favor of #249, which uses a shared base branch.

roberto-bayardo commented 2 months ago

This one looks obsoleted by https://github.com/ethereum-optimism/op-geth/pull/249... can we close it? cc: @danyalprout