Skip to content

[Fjord] Add FastLZ compression into L1CostFunc#202

Closed
mdehoog wants to merge 6 commits intoethereum-optimism:optimismfrom
mdehoog:flz-l1-cost-func
Closed

[Fjord] Add FastLZ compression into L1CostFunc#202
mdehoog wants to merge 6 commits intoethereum-optimism:optimismfrom
mdehoog:flz-l1-cost-func

Conversation

@mdehoog
Copy link
Contributor

@mdehoog mdehoog commented Dec 15, 2023

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
Copy link
Contributor

roberto-bayardo commented Dec 15, 2023

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: #203

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

@mdehoog mdehoog force-pushed the flz-l1-cost-func branch 4 times, most recently from ec1344a to 1496312 Compare December 16, 2023 05:29
@mdehoog mdehoog force-pushed the flz-l1-cost-func branch 2 times, most recently from d49f0cc to a0abed5 Compare January 3, 2024 17:59
@mdehoog mdehoog force-pushed the flz-l1-cost-func branch 4 times, most recently from ed2b7b5 to 2119850 Compare January 17, 2024 18:23
@mdehoog mdehoog changed the title Add FastLZ compression into L1CostFunc [Fjord] Add FastLZ compression into L1CostFunc Jan 17, 2024
@mdehoog
Copy link
Contributor Author

mdehoog commented Feb 21, 2024

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


// FlzCompressLen returns the length of the data after compression through FastLZ, based on
// https://github.com/Vectorized/solady/blob/5315d937d79b335c668896d7533ac603adac5315/js/solady.js
func FlzCompressLen(ib []byte) uint32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a fuzz test to this? The version in the compression analysis script panics with short inputs for example.

@roberto-bayardo
Copy link
Contributor

This one looks obsoleted by #249... can we close it?
cc: @danyalprout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants