-
Notifications
You must be signed in to change notification settings - Fork 4k
Fjord: Add FastLZ compression into L1CostFunc #9618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sebastianst
merged 14 commits into
ethereum-optimism:develop
from
base:flz-l1-cost-func
May 16, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5372673
Add FastLZ for better L1Cost estimation
1fc83a5
fix all the tests
danyalprout 3a3a09d
fix: upate GPO network transactions to match spec
danyalprout e899ea6
Update GPO contracts
danyalprout 027b68c
update to 1d model / add tests
danyalprout 15bfbdb
update allocs and test framework to support new fjord contracts
danyalprout 41ca073
add fuzz testing
danyalprout cfbd6d5
increase minimum estimation to 100 / update circleci for e2e fuzz tests
danyalprout 4dc6eee
use linear regression for l1 gas used
danyalprout 4a53cc2
Add differential fastlz fuzzing between solady/cgo fastlz/geth fastlz
danyalprout 1116cc1
Review feedback
danyalprout 03f6bea
Bump geth
danyalprout dc2d474
fix: ensure we don't gc the data during fastlz compression
danyalprout fe398ca
Replace common.Hex2Bytes with common.FromHex
danyalprout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package actions | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/hex" | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-service/predeploys" | ||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/common/hexutil" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-bindings/bindings" | ||
| "github.com/ethereum-optimism/optimism/op-chain-ops/genesis" | ||
| "github.com/ethereum-optimism/optimism/op-e2e/e2eutils" | ||
| "github.com/ethereum-optimism/optimism/op-node/rollup/derive" | ||
| "github.com/ethereum-optimism/optimism/op-service/testlog" | ||
| ) | ||
|
|
||
| var ( | ||
| fjordGasPriceOracleCodeHash = common.HexToHash("0xa88fa50a2745b15e6794247614b5298483070661adacb8d32d716434ed24c6b2") | ||
| // https://basescan.org/tx/0x8debb2fe54200183fb8baa3c6dbd8e6ec2e4f7a4add87416cd60336b8326d16a | ||
| txHex = "02f875822105819b8405709fb884057d460082e97f94273ca93a52b817294830ed7572aa591ccfa647fd80881249c58b0021fb3fc080a05bb08ccfd68f83392e446dac64d88a2d28e7072c06502dfabc4a77e77b5c7913a05878d53dd4ebba4f6367e572d524dffcabeec3abb1d8725ee3ac5dc32e1852e3" | ||
| ) | ||
|
|
||
| func TestFjordNetworkUpgradeTransactions(gt *testing.T) { | ||
| t := NewDefaultTesting(gt) | ||
| dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams) | ||
| genesisBlock := hexutil.Uint64(0) | ||
| fjordOffset := hexutil.Uint64(2) | ||
|
|
||
| dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default | ||
|
|
||
| // Activate all forks at genesis, and schedule Fjord the block after | ||
|
sebastianst marked this conversation as resolved.
Outdated
|
||
| dp.DeployConfig.L2GenesisRegolithTimeOffset = &genesisBlock | ||
| dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock | ||
| dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock | ||
| dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisBlock | ||
| dp.DeployConfig.L2GenesisFjordTimeOffset = &fjordOffset | ||
| require.NoError(t, dp.DeployConfig.Check(), "must have valid config") | ||
|
|
||
| sd := e2eutils.Setup(t, dp, defaultAlloc) | ||
| log := testlog.Logger(t, log.LvlDebug) | ||
| _, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log) | ||
| ethCl := engine.EthClient() | ||
|
|
||
| // start op-nodes | ||
| sequencer.ActL2PipelineFull(t) | ||
| verifier.ActL2PipelineFull(t) | ||
|
|
||
| // Get gas price from oracle | ||
| gasPriceOracle, err := bindings.NewGasPriceOracleCaller(predeploys.GasPriceOracleAddr, ethCl) | ||
| require.NoError(t, err) | ||
|
|
||
| // Get current implementations addresses (by slot) for L1Block + GasPriceOracle | ||
| initialGasPriceOracleAddress, err := ethCl.StorageAt(context.Background(), predeploys.GasPriceOracleAddr, genesis.ImplementationSlot, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| sequencer.ActBuildL2ToFjord(t) | ||
|
|
||
| // get latest block | ||
| latestBlock, err := ethCl.BlockByNumber(context.Background(), nil) | ||
| require.NoError(t, err) | ||
| require.Equal(t, sequencer.L2Unsafe().Number, latestBlock.Number().Uint64()) | ||
|
|
||
| transactions := latestBlock.Transactions() | ||
| // L1Block: 1 set-L1-info + 1 deploys + 1 upgradeTo + 1 enable fjord on GPO | ||
| // See [derive.FjordNetworkUpgradeTransactions] | ||
| require.Equal(t, 4, len(transactions)) | ||
|
|
||
| // All transactions are successful | ||
| for i := 1; i < 4; i++ { | ||
| txn := transactions[i] | ||
| receipt, err := ethCl.TransactionReceipt(context.Background(), txn.Hash()) | ||
| require.NoError(t, err) | ||
| require.Equal(t, types.ReceiptStatusSuccessful, receipt.Status) | ||
| require.NotEmpty(t, txn.Data(), "upgrade tx must provide input data") | ||
| } | ||
|
|
||
| expectedGasPriceOracleAddress := crypto.CreateAddress(derive.GasPriceOracleFjordDeployerAddress, 0) | ||
|
|
||
| // Gas Price Oracle Proxy is updated | ||
| updatedGasPriceOracleAddress, err := ethCl.StorageAt(context.Background(), predeploys.GasPriceOracleAddr, genesis.ImplementationSlot, latestBlock.Number()) | ||
| require.NoError(t, err) | ||
| require.Equal(t, expectedGasPriceOracleAddress, common.BytesToAddress(updatedGasPriceOracleAddress)) | ||
| require.NotEqualf(t, initialGasPriceOracleAddress, updatedGasPriceOracleAddress, "Gas Price Oracle Proxy address should have changed") | ||
| verifyCodeHashMatches(t, ethCl, expectedGasPriceOracleAddress, fjordGasPriceOracleCodeHash) | ||
|
|
||
| // Check that Fjord was activated | ||
| isFjord, err := gasPriceOracle.IsFjord(nil) | ||
| require.NoError(t, err) | ||
| require.True(t, isFjord) | ||
|
|
||
| // Check GetL1GasUsed is updated | ||
| txData, err := hex.DecodeString(txHex) | ||
| require.NoError(t, err) | ||
|
|
||
| gpoL1GasUsed, err := gasPriceOracle.GetL1GasUsed(&bind.CallOpts{}, txData) | ||
| require.NoError(t, err) | ||
| require.Equal(gt, uint64(1_888), gpoL1GasUsed.Uint64()) | ||
|
|
||
| // Check that GetL1Fee takes into account fast LZ | ||
| gpoFee, err := gasPriceOracle.GetL1Fee(&bind.CallOpts{}, txData) | ||
| require.NoError(t, err) | ||
|
|
||
| gethFee := fjordL1Cost(t, gasPriceOracle, types.RollupCostData{ | ||
| FastLzSize: uint64(types.FlzCompressLen(txData) + 68), | ||
|
sebastianst marked this conversation as resolved.
Outdated
|
||
| }) | ||
| require.Equal(t, gethFee.Uint64(), gpoFee.Uint64()) | ||
|
|
||
| // Check that L1FeeUpperBound works | ||
| upperBound, err := gasPriceOracle.GetL1FeeUpperBound(&bind.CallOpts{}, big.NewInt(int64(len(txData)))) | ||
| require.NoError(t, err) | ||
|
|
||
| txLen := len(txData) + 68 | ||
| flzUpperBound := uint64(txLen + txLen/255 + 16) | ||
|
|
||
| upperBoundCost := fjordL1Cost(t, gasPriceOracle, types.RollupCostData{FastLzSize: flzUpperBound}) | ||
| require.Equal(t, upperBoundCost.Uint64(), upperBound.Uint64()) | ||
| } | ||
|
|
||
| func fjordL1Cost(t require.TestingT, gasPriceOracle *bindings.GasPriceOracleCaller, rollupCostData types.RollupCostData) *big.Int { | ||
| baseFeeScalar, err := gasPriceOracle.BaseFeeScalar(nil) | ||
| require.NoError(t, err) | ||
| l1BaseFee, err := gasPriceOracle.L1BaseFee(nil) | ||
| require.NoError(t, err) | ||
| blobBaseFeeScalar, err := gasPriceOracle.BlobBaseFeeScalar(nil) | ||
| require.NoError(t, err) | ||
| blobBaseFee, err := gasPriceOracle.BlobBaseFee(nil) | ||
| require.NoError(t, err) | ||
|
|
||
| costFunc := types.NewL1CostFuncFjord( | ||
| l1BaseFee, | ||
| blobBaseFee, | ||
| new(big.Int).SetUint64(uint64(baseFeeScalar)), | ||
| new(big.Int).SetUint64(uint64(blobBaseFeeScalar))) | ||
|
|
||
| fee, _ := costFunc(rollupCostData) | ||
| return fee | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.