diff --git a/op-e2e/actions/ecotone_fork_test.go b/op-e2e/actions/ecotone_fork_test.go index 61cc33088bf9f..cda4ece23feba 100644 --- a/op-e2e/actions/ecotone_fork_test.go +++ b/op-e2e/actions/ecotone_fork_test.go @@ -82,9 +82,16 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) { initialL1BlockAddress, err := ethCl.StorageAt(context.Background(), predeploys.L1BlockAddr, genesis.ImplementationSlot, nil) require.NoError(t, err) + e, err := gasPriceOracle.IsEcotone(nil) + require.False(t, e) + // Build to the ecotone block sequencer.ActBuildL2ToEcotone(t) + e, err = gasPriceOracle.IsEcotone(nil) + require.NoError(t, err) + require.True(t, e) + // get latest block latestBlock, err := ethCl.BlockByNumber(context.Background(), nil) require.NoError(t, err) diff --git a/op-e2e/actions/fjord_fork_test.go b/op-e2e/actions/fjord_fork_test.go index 88794f66241da..518aa9b61c567 100644 --- a/op-e2e/actions/fjord_fork_test.go +++ b/op-e2e/actions/fjord_fork_test.go @@ -23,20 +23,20 @@ import ( ) var ( - fjordGasPriceOracleCodeHash = common.HexToHash("0x9ceff82dc9f9bf592dc3954dde0ce8466864229caa8916fffc4005e2fde3d589") + fjordGasPriceOracleCodeHash = common.HexToHash("0xd932e30ee61cd4af3aa471df75293d2c4c3da7aac54ca3bfd5e0b65f4d7f5fa5") // https://basescan.org/tx/0x8debb2fe54200183fb8baa3c6dbd8e6ec2e4f7a4add87416cd60336b8326d16a txHex = "02f875822105819b8405709fb884057d460082e97f94273ca93a52b817294830ed7572aa591ccfa647fd80881249c58b0021fb3fc080a05bb08ccfd68f83392e446dac64d88a2d28e7072c06502dfabc4a77e77b5c7913a05878d53dd4ebba4f6367e572d524dffcabeec3abb1d8725ee3ac5dc32e1852e3" - costTxSizeCoef int64 = -88_664 - costFastlzCoef int64 = 1_031_462 - costIntercept int64 = -27_321_890 + costFastlzCoef int64 = 836_500 + costIntercept int64 = -42_585_600 ) func TestFjordNetworkUpgradeTransactions(gt *testing.T) { t := NewDefaultTesting(gt) dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams) genesisBlock := hexutil.Uint64(0) - fjordOffset := hexutil.Uint64(2) + ecotoneOffset := hexutil.Uint64(4) + fjordOffset := hexutil.Uint64(8) dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default @@ -44,9 +44,8 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) { dp.DeployConfig.L2GenesisRegolithTimeOffset = &genesisBlock dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock - dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisBlock + dp.DeployConfig.L2GenesisEcotoneTimeOffset = &ecotoneOffset dp.DeployConfig.L2GenesisFjordTimeOffset = &fjordOffset - require.NoError(t, dp.DeployConfig.Check(), "must have valid config") sd := e2eutils.Setup(t, dp, defaultAlloc) @@ -54,19 +53,24 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) { _, _, _, sequencer, engine, verifier, _, _ := setupReorgTestActors(t, dp, sd, log) ethCl := engine.EthClient() + // build a single block to move away from the genesis with 0-values in L1Block contract + sequencer.ActL2StartBlock(t) + sequencer.ActL2EndBlock(t) + // start op-nodes sequencer.ActL2PipelineFull(t) verifier.ActL2PipelineFull(t) - // Get current implementations addresses (by slot) for L1Block + GasPriceOracle - initialGasPriceOracleAddress, err := ethCl.StorageAt(context.Background(), predeploys.GasPriceOracleAddr, genesis.ImplementationSlot, nil) - require.NoError(t, err) - // Get gas price from oracle gasPriceOracle, err := bindings.NewGasPriceOracleCaller(predeploys.GasPriceOracleAddr, ethCl) require.NoError(t, err) - // Build to the Fjord block + sequencer.ActBuildL2ToEcotone(t) + + // 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 @@ -102,17 +106,21 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) { require.NoError(t, err) require.True(t, isFjord) - // Check GetL1Fee is updated + // Check GetL1GasUsed is updated txData, err := hex.DecodeString(txHex) require.NoError(t, err) - used, err := gasPriceOracle.GetL1Fee(&bind.CallOpts{}, txData) + l1GasUsed, err := gasPriceOracle.GetL1GasUsed(&bind.CallOpts{}, txData) require.NoError(t, err) - fastLzLength := types.FlzCompressLen(txData) + fastLzSize := types.FlzCompressLen(txData) + require.Equal(gt, l1GasUsed.Uint64(), uint64(fastLzSize+68)*16) - cost := fjordL1Cost(t, gasPriceOracle, int64(fastLzLength), int64(len(txData))) + // Check that GetL1Fee takes into account fast LZ + used, err := gasPriceOracle.GetL1Fee(&bind.CallOpts{}, txData) + require.NoError(t, err) + cost := fjordL1Cost(t, gasPriceOracle, int64(fastLzSize)) require.Equal(t, cost.Uint64(), used.Uint64()) // Check that L1FeeUppberBound works @@ -121,68 +129,22 @@ func TestFjordNetworkUpgradeTransactions(gt *testing.T) { flzUpperBound := len(txData) + len(txData)/255 + 16 - upperBoundCost := fjordL1Cost(t, gasPriceOracle, int64(flzUpperBound), int64(len(txData))) + upperBoundCost := fjordL1Cost(t, gasPriceOracle, int64(flzUpperBound)) require.Equal(t, upperBoundCost.Uint64(), upperBound.Uint64()) } -func FuzzFastLz(f *testing.F) { - f.Fuzz(func(gt *testing.T, data []byte) { - if len(data) <= 71 { - return - } - - t := NewDefaultTesting(gt) - dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams) - genesisBlock := hexutil.Uint64(0) - - 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 - dp.DeployConfig.L2GenesisRegolithTimeOffset = &genesisBlock - dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock - dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock - dp.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisBlock - dp.DeployConfig.L2GenesisFjordTimeOffset = &genesisBlock - - 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) - - // Build to the Fjord block - sequencer.ActBuildL2ToFjord(t) - - // Get gas price from oracle - gasPriceOracle, err := bindings.NewGasPriceOracleCaller(predeploys.GasPriceOracleAddr, ethCl) - require.NoError(t, err) - - used, err := gasPriceOracle.GetL1Fee(&bind.CallOpts{}, data) - require.NoError(t, err) - - fastLzLength := types.FlzCompressLen(data) - cost := fjordL1Cost(t, gasPriceOracle, int64(fastLzLength), int64(len(data))) - - require.Equal(t, cost.Uint64(), used.Uint64()) - }) -} - // The new cost function: // l1BaseFeeScaled = l1BaseFeeScalar * l1BaseFee * 16 // l1BlobFeeScaled = l1BlobFeeScalar * l1BlobBaseFee // l1FeeScaled = l1BaseFeeScaled + l1BlobFeeScaled -// ((intercept + fastlzCoef*fastlzLength + uncompressedTxCoef*uncompressedTxSize) * l1FeeScaled) / 1e12 +// ((intercept + fastlzCoef*max(fastlzLength, 71)) * l1FeeScaled) / 1e6 func fjordL1Cost( t require.TestingT, gasPriceOracle *bindings.GasPriceOracleCaller, - fastLzLength, - unsignedTxSize int64, + fastLzLength int64, ) *big.Int { + fastLzLength = max(fastLzLength, 71) + baseFeeScalar, err := gasPriceOracle.BaseFeeScalar(nil) require.NoError(t, err) l1BaseFee, err := gasPriceOracle.L1BaseFee(nil) @@ -198,7 +160,6 @@ func fjordL1Cost( cost := new(big.Int).Mul(new(big.Int).SetInt64(costFastlzCoef), new(big.Int).SetInt64(fastLzLength+68)) cost = new(big.Int).Add(cost, new(big.Int).SetInt64(costIntercept)) - cost = new(big.Int).Add(cost, new(big.Int).Mul(new(big.Int).SetInt64(costTxSizeCoef), new(big.Int).SetInt64(unsignedTxSize+68))) require.True(t, cost.Sign() >= 0) cost = new(big.Int).Mul(cost, feeScaled) diff --git a/op-node/rollup/derive/fjord_upgrade_transactions.go b/op-node/rollup/derive/fjord_upgrade_transactions.go index 530fed257bbb9..80056f6656570 100644 --- a/op-node/rollup/derive/fjord_upgrade_transactions.go +++ b/op-node/rollup/derive/fjord_upgrade_transactions.go @@ -15,7 +15,7 @@ var ( // Gas Price Oracle Parameters deployFjordGasPriceOracleSource = UpgradeDepositSource{Intent: "Fjord: Gas Price Oracle Deployment"} GasPriceOracleFjordDeployerAddress = common.HexToAddress("0x4210000000000000000000000000000000000002") - gasPriceOracleFjordDeploymentBytecode = common.FromHex("0x608060405234801561001057600080fd5b50611928806100206000396000f3fe608060405234801561001057600080fd5b50600436106101365760003560e01c80636ef25c3a116100b2578063de26c4a111610081578063f45e65d811610066578063f45e65d81461025b578063f820614014610263578063fe173b971461020d57600080fd5b8063de26c4a114610235578063f1c7a58b1461024857600080fd5b80636ef25c3a1461020d5780638e98b10614610213578063960e3a231461021b578063c59859181461022d57600080fd5b806349948e0e11610109578063519b4bd3116100ee578063519b4bd31461019f57806354fd4d50146101a757806368d5dca6146101f057600080fd5b806349948e0e1461016f5780634ef6e2241461018257600080fd5b80630c18c1621461013b57806322b90ab3146101565780632e0f262514610160578063313ce56714610168575b600080fd5b61014361026b565b6040519081526020015b60405180910390f35b61015e61038c565b005b610143600681565b6006610143565b61014361017d36600461132d565b6105af565b60005461018f9060ff1681565b604051901515815260200161014d565b6101436105ec565b6101e36040518060400160405280600581526020017f312e332e3000000000000000000000000000000000000000000000000000000081525081565b60405161014d91906113fc565b6101f861064d565b60405163ffffffff909116815260200161014d565b48610143565b61015e6106d2565b60005461018f90610100900460ff1681565b6101f86108d4565b61014361024336600461132d565b610935565b61014361025636600461146f565b6109e9565b610143610ad1565b610143610bc4565b6000805460ff1615610304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602860248201527f47617350726963654f7261636c653a206f76657268656164282920697320646560448201527f707265636174656400000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16638b239f736040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103879190611488565b905090565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663e591b2826040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061040f91906114a1565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104ef576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152604160248201527f47617350726963654f7261636c653a206f6e6c7920746865206465706f73697460448201527f6f72206163636f756e742063616e2073657420697345636f746f6e6520666c6160648201527f6700000000000000000000000000000000000000000000000000000000000000608482015260a4016102fb565b60005460ff1615610582576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f47617350726963654f7261636c653a2045636f746f6e6520616c72656164792060448201527f616374697665000000000000000000000000000000000000000000000000000060648201526084016102fb565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b60008054610100900460ff16156105cf576105c982610c25565b92915050565b60005460ff16156105e3576105c982610c4f565b6105c982610cf3565b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16635cf249696040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff166368d5dca66040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106ae573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061038791906114d7565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663e591b2826040518163ffffffff1660e01b8152600401602060405180830381865afa158015610731573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075591906114a1565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461080f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603f60248201527f47617350726963654f7261636c653a206f6e6c7920746865206465706f73697460448201527f6f72206163636f756e742063616e20736574206973466a6f726420666c61670060648201526084016102fb565b600054610100900460ff16156108a6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f47617350726963654f7261636c653a20466a6f726420616c726561647920616360448201527f746976650000000000000000000000000000000000000000000000000000000060648201526084016102fb565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16610100179055565b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663c59859186040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106ae573d6000803e3d6000fd5b60008061094183610e47565b60005490915060ff16156109555792915050565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16638b239f736040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d89190611488565b6109e2908261152c565b9392505050565b60008054610100900460ff16610a81576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603660248201527f47617350726963654f7261636c653a206765744c314665655570706572426f7560448201527f6e64206f6e6c7920737570706f72747320466a6f72640000000000000000000060648201526084016102fb565b6000610a8e60ff84611573565b610a9890846115db565b610aa39060106115db565b610aae9060446115db565b90506000610abd8460446115db565b9050610ac98282610ed7565b949350505050565b6000805460ff1615610b65576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f47617350726963654f7261636c653a207363616c61722829206973206465707260448201527f656361746564000000000000000000000000000000000000000000000000000060648201526084016102fb565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16639e8c49666040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663f82061406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b600080610c3183610fe1565b51610c3d90604461152c565b9050600083516044610abd919061152c565b600080610c5b83610e47565b90506000610c676105ec565b610c6f6108d4565b610c7a90601061164f565b63ffffffff16610c8a919061167b565b90506000610c96610bc4565b610c9e61064d565b63ffffffff16610cae919061167b565b90506000610cbc828461152c565b610cc6908561167b565b9050610cd46006600a6117d8565b610cdf90601061167b565b610ce990826117e4565b9695505050505050565b600080610cff83610e47565b9050600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16639e8c49666040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d869190611488565b610d8e6105ec565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16638b239f736040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ded573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e119190611488565b610e1b908561152c565b610e25919061167b565b610e2f919061167b565b9050610e3d6006600a6117d8565b610ac990826117e4565b80516000908190815b81811015610eca57848181518110610e6a57610e6a6117f8565b01602001517fff0000000000000000000000000000000000000000000000000000000000000016600003610eaa57610ea360048461152c565b9250610eb8565b610eb560108461152c565b92505b80610ec281611827565b915050610e50565b50610ac98261044061152c565b600080610ee2610bc4565b610eea61064d565b63ffffffff16610efa919061167b565b610f026105ec565b610f0a6108d4565b610f1590601061164f565b63ffffffff16610f25919061167b565b610f2f919061152c565b90506000610f5d847ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffea5a861185f565b610f6a86620fbd2661185f565b610f94907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe5f19de6115db565b610f9e91906115db565b90506000811215610fad575060005b610fb96006600261167b565b610fc490600a6117d8565b610fce838361167b565b610fd891906117e4565b95945050505050565b6060611170565b818153600101919050565b600082840393505b838110156109e25782810151828201511860001a1590930292600101610ffb565b825b60208210611068578251611033601f83610fe8565b52602092909201917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09091019060210161101e565b81156109e257825161107d6001840383610fe8565b520160010192915050565b60006001830392505b61010782106110c9576110bb8360ff166110b660fd6110b68760081c60e00189610fe8565b610fe8565b935061010682039150611091565b600782106110f6576110ef8360ff166110b6600785036110b68760081c60e00189610fe8565b90506109e2565b610ac98360ff166110b68560081c8560051b0187610fe8565b61116882820361114c61113c84600081518060001a8160011a60081b178160021a60101b17915050919050565b639e3779b90260131c611fff1690565b8060021b6040510182815160e01c1860e01b8151188152505050565b600101919050565b6180003860405139618000604051016020830180600d8551820103826002015b818110156112a3576000805b50508051604051600082901a600183901a60081b1760029290921a60101b91909117639e3779b9810260111c617ffc16909101805160e081811c878603811890911b909118909152840190818303908484106111f85750611233565b600184019350611fff821161122d578251600081901a600182901a60081b1760029190911a60101b17810361122d5750611233565b5061119c565b8383106112415750506112a3565b6001830392508583111561125f5761125c878788860361101c565b96505b611273600985016003850160038501610ff3565b9150611280878284611088565b965050611298846112938684860161110f565b61110f565b915050809350611190565b50506112b5838384885185010361101c565b925050506040519150618000820180820391508183526020830160005b838110156112ea5782810151828201526020016112d2565b506000920191825250602001604052919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60006020828403121561133f57600080fd5b813567ffffffffffffffff8082111561135757600080fd5b818401915084601f83011261136b57600080fd5b81358181111561137d5761137d6112fe565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156113c3576113c36112fe565b816040528281528760208487010111156113dc57600080fd5b826020860160208301376000928101602001929092525095945050505050565b600060208083528351808285015260005b818110156114295785810183015185820160400152820161140d565b8181111561143b576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60006020828403121561148157600080fd5b5035919050565b60006020828403121561149a57600080fd5b5051919050565b6000602082840312156114b357600080fd5b815173ffffffffffffffffffffffffffffffffffffffff811681146109e257600080fd5b6000602082840312156114e957600080fd5b815163ffffffff811681146109e257600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000821982111561153f5761153f6114fd565b500190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60008261158257611582611544565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83147f8000000000000000000000000000000000000000000000000000000000000000831416156115d6576115d66114fd565b500590565b6000808212827f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03841381151615611615576116156114fd565b827f8000000000000000000000000000000000000000000000000000000000000000038412811615611649576116496114fd565b50500190565b600063ffffffff80831681851681830481118215151615611672576116726114fd565b02949350505050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156116b3576116b36114fd565b500290565b600181815b8085111561171157817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156116f7576116f76114fd565b8085161561170457918102915b93841c93908002906116bd565b509250929050565b600082611728575060016105c9565b81611735575060006105c9565b816001811461174b576002811461175557611771565b60019150506105c9565b60ff841115611766576117666114fd565b50506001821b6105c9565b5060208310610133831016604e8410600b8410161715611794575081810a6105c9565b61179e83836116b8565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156117d0576117d06114fd565b029392505050565b60006109e28383611719565b6000826117f3576117f3611544565b500490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611858576118586114fd565b5060010190565b60007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000841360008413858304851182821616156118a0576118a06114fd565b7f800000000000000000000000000000000000000000000000000000000000000060008712868205881281841616156118db576118db6114fd565b600087129250878205871284841616156118f7576118f76114fd565b8785058712818416161561190d5761190d6114fd565b50505092909302939250505056fea164736f6c634300080f000a") + gasPriceOracleFjordDeploymentBytecode = common.FromHex("0x608060405234801561001057600080fd5b5061187d806100206000396000f3fe608060405234801561001057600080fd5b50600436106101365760003560e01c80636ef25c3a116100b2578063de26c4a111610081578063f45e65d811610066578063f45e65d81461025b578063f820614014610263578063fe173b971461020d57600080fd5b8063de26c4a114610235578063f1c7a58b1461024857600080fd5b80636ef25c3a1461020d5780638e98b10614610213578063960e3a231461021b578063c59859181461022d57600080fd5b806349948e0e11610109578063519b4bd3116100ee578063519b4bd31461019f57806354fd4d50146101a757806368d5dca6146101f057600080fd5b806349948e0e1461016f5780634ef6e2241461018257600080fd5b80630c18c1621461013b57806322b90ab3146101565780632e0f262514610160578063313ce56714610168575b600080fd5b61014361026b565b6040519081526020015b60405180910390f35b61015e61038c565b005b610143600681565b6006610143565b61014361017d3660046113ae565b6105af565b60005461018f9060ff1681565b604051901515815260200161014d565b610143610600565b6101e36040518060400160405280600581526020017f312e332e3000000000000000000000000000000000000000000000000000000081525081565b60405161014d919061147d565b6101f8610661565b60405163ffffffff909116815260200161014d565b48610143565b61015e6106e6565b60005461018f90610100900460ff1681565b6101f861097a565b6101436102433660046113ae565b6109db565b6101436102563660046114f0565b610ac9565b610143610b99565b610143610c8c565b6000805460ff1615610304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602860248201527f47617350726963654f7261636c653a206f76657268656164282920697320646560448201527f707265636174656400000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16638b239f736040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103879190611509565b905090565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663e591b2826040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061040f9190611522565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104ef576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152604160248201527f47617350726963654f7261636c653a206f6e6c7920746865206465706f73697460448201527f6f72206163636f756e742063616e2073657420697345636f746f6e6520666c6160648201527f6700000000000000000000000000000000000000000000000000000000000000608482015260a4016102fb565b60005460ff1615610582576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f47617350726963654f7261636c653a2045636f746f6e6520616c72656164792060448201527f616374697665000000000000000000000000000000000000000000000000000060648201526084016102fb565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b60008054610100900460ff16156105e3576105dd6105cc83610ced565b516105d8906044611587565b611012565b92915050565b60005460ff16156105f7576105dd826110e0565b6105dd82611184565b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16635cf249696040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff166368d5dca66040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106c2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610387919061159f565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663e591b2826040518163ffffffff1660e01b8152600401602060405180830381865afa158015610745573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107699190611522565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610823576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603f60248201527f47617350726963654f7261636c653a206f6e6c7920746865206465706f73697460448201527f6f72206163636f756e742063616e20736574206973466a6f726420666c61670060648201526084016102fb565b60005460ff166108b5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603960248201527f47617350726963654f7261636c653a20466a6f72642063616e206f6e6c79206260448201527f65206163746976617465642061667465722045636f746f6e650000000000000060648201526084016102fb565b600054610100900460ff161561094c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f47617350726963654f7261636c653a20466a6f726420616c726561647920616360448201527f746976650000000000000000000000000000000000000000000000000000000060648201526084016102fb565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16610100179055565b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663c59859186040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106c2573d6000803e3d6000fd5b60008054610100900460ff1615610a1657610a0b6109f883610ced565b51610a04906044611587565b60476112d8565b6105dd9060106115c5565b6000610a21836112ef565b60005490915060ff1615610a355792915050565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16638b239f736040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ab89190611509565b610ac29082611587565b9392505050565b60008054610100900460ff16610b61576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603660248201527f47617350726963654f7261636c653a206765744c314665655570706572426f7560448201527f6e64206f6e6c7920737570706f72747320466a6f72640000000000000000000060648201526084016102fb565b6000610b6e60ff84611602565b610b789084611587565b610b83906010611587565b610b8e906044611587565b9050610ac281611012565b6000805460ff1615610c2d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f47617350726963654f7261636c653a207363616c61722829206973206465707260448201527f656361746564000000000000000000000000000000000000000000000000000060648201526084016102fb565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16639e8c49666040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff1663f82061406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610363573d6000803e3d6000fd5b6060610e84565b818153600101919050565b600082840393505b83811015610ac25782810151828201511860001a1590930292600101610d07565b825b60208210610d74578251610d3f601f83610cf4565b52602092909201917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090910190602101610d2a565b8115610ac2578251610d896001840383610cf4565b520160010192915050565b60006001830392505b6101078210610dd557610dc78360ff16610dc260fd610dc28760081c60e00189610cf4565b610cf4565b935061010682039150610d9d565b60078210610e0257610dfb8360ff16610dc260078503610dc28760081c60e00189610cf4565b9050610ac2565b610e1b8360ff16610dc28560081c8560051b0187610cf4565b949350505050565b610e7c828203610e60610e5084600081518060001a8160011a60081b178160021a60101b17915050919050565b639e3779b90260131c611fff1690565b8060021b6040510182815160e01c1860e01b8151188152505050565b600101919050565b6180003860405139618000604051016020830180600d8551820103826002015b81811015610fb7576000805b50508051604051600082901a600183901a60081b1760029290921a60101b91909117639e3779b9810260111c617ffc16909101805160e081811c878603811890911b90911890915284019081830390848410610f0c5750610f47565b600184019350611fff8211610f41578251600081901a600182901a60081b1760029190911a60101b178103610f415750610f47565b50610eb0565b838310610f55575050610fb7565b60018303925085831115610f7357610f708787888603610d28565b96505b610f87600985016003850160038501610cff565b9150610f94878284610d94565b965050610fac84610fa786848601610e23565b610e23565b915050809350610ea4565b5050610fc98383848851850103610d28565b925050506040519150618000820180820391508183526020830160005b83811015610ffe578281015182820152602001610fe6565b506000920191825250602001604052919050565b600061101f8260476112d8565b9150600061102b610c8c565b611033610661565b63ffffffff1661104391906115c5565b61104b610600565b61105361097a565b61105e90601061163d565b63ffffffff1661106e91906115c5565b6110789190611587565b9050600061108984620cc3946115c5565b6110b3907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd763200611669565b90506110c1600660026115c5565b6110cc90600a6117fd565b6110d683836115c5565b610e1b9190611602565b6000806110ec836112ef565b905060006110f8610600565b61110061097a565b61110b90601061163d565b63ffffffff1661111b91906115c5565b90506000611127610c8c565b61112f610661565b63ffffffff1661113f91906115c5565b9050600061114d8284611587565b61115790856115c5565b90506111656006600a6117fd565b6111709060106115c5565b61117a9082611602565b9695505050505050565b600080611190836112ef565b9050600073420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16639e8c49666040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112179190611509565b61121f610600565b73420000000000000000000000000000000000001573ffffffffffffffffffffffffffffffffffffffff16638b239f736040518163ffffffff1660e01b8152600401602060405180830381865afa15801561127e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a29190611509565b6112ac9085611587565b6112b691906115c5565b6112c091906115c5565b90506112ce6006600a6117fd565b610e1b9082611602565b6000818310156112e85781610ac2565b5090919050565b80516000908190815b818110156113725784818151811061131257611312611809565b01602001517fff00000000000000000000000000000000000000000000000000000000000000166000036113525761134b600484611587565b9250611360565b61135d601084611587565b92505b8061136a81611838565b9150506112f8565b50610e1b82610440611587565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000602082840312156113c057600080fd5b813567ffffffffffffffff808211156113d857600080fd5b818401915084601f8301126113ec57600080fd5b8135818111156113fe576113fe61137f565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156114445761144461137f565b8160405282815287602084870101111561145d57600080fd5b826020860160208301376000928101602001929092525095945050505050565b600060208083528351808285015260005b818110156114aa5785810183015185820160400152820161148e565b818111156114bc576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60006020828403121561150257600080fd5b5035919050565b60006020828403121561151b57600080fd5b5051919050565b60006020828403121561153457600080fd5b815173ffffffffffffffffffffffffffffffffffffffff81168114610ac257600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000821982111561159a5761159a611558565b500190565b6000602082840312156115b157600080fd5b815163ffffffff81168114610ac257600080fd5b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156115fd576115fd611558565b500290565b600082611638577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600063ffffffff8083168185168183048111821515161561166057611660611558565b02949350505050565b6000808212827f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038413811516156116a3576116a3611558565b827f80000000000000000000000000000000000000000000000000000000000000000384128116156116d7576116d7611558565b50500190565b600181815b8085111561173657817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0482111561171c5761171c611558565b8085161561172957918102915b93841c93908002906116e2565b509250929050565b60008261174d575060016105dd565b8161175a575060006105dd565b8160018114611770576002811461177a57611796565b60019150506105dd565b60ff84111561178b5761178b611558565b50506001821b6105dd565b5060208310610133831016604e8410600b84101617156117b9575081810a6105dd565b6117c383836116dd565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156117f5576117f5611558565b029392505050565b6000610ac2838361173e565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361186957611869611558565b506001019056fea164736f6c634300080f000a") // Update GasPricePriceOracle Proxy Parameters updateFjordGasPriceOracleSource = UpgradeDepositSource{Intent: "Fjord: Gas Price Oracle Proxy Update"} @@ -71,7 +71,7 @@ func FjordNetworkUpgradeTransactions() ([]hexutil.Bytes, error) { To: &predeploys.GasPriceOracleAddr, Mint: big.NewInt(0), Value: big.NewInt(0), - Gas: 80_000, + Gas: 500_000, IsSystemTransaction: false, Data: enableFjordInput, }).MarshalBinary() diff --git a/packages/contracts-bedrock/src/L2/GasPriceOracle.sol b/packages/contracts-bedrock/src/L2/GasPriceOracle.sol index 6fdc3586368ef..d97dd8ce31c91 100644 --- a/packages/contracts-bedrock/src/L2/GasPriceOracle.sol +++ b/packages/contracts-bedrock/src/L2/GasPriceOracle.sol @@ -5,6 +5,7 @@ import { ISemver } from "src/universal/ISemver.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; import { L1Block } from "src/L2/L1Block.sol"; import { LibZip } from "@solady/utils/LibZip.sol"; +import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; /// @custom:proxied /// @custom:predeploy 0x420000000000000000000000000000000000000F @@ -37,7 +38,7 @@ contract GasPriceOracle is ISemver { // Hardcoded values for the Fjord upgrade calculation int32 private constant COST_INTERCEPT = -42_585_600; uint32 private constant COST_FASTLZ_COEF = 836_500; - uint32 private constant MIN_TRANSCTION_SIZE = 71; + uint32 private constant MIN_TRANSACTION_SIZE = 71; /// @notice Computes the L1 portion of the fee based on the size of the rlp encoded input /// transaction, the current L1 base fee, and the various dynamic parameters. @@ -45,7 +46,7 @@ contract GasPriceOracle is ISemver { /// @return L1 fee that should be paid for the tx function getL1Fee(bytes memory _data) external view returns (uint256) { if (isFjord) { - return _getL1FeeFjord(_data); + return _fjordL1Cost(LibZip.flzCompress(_data).length + 68); } if (isEcotone) { return _getL1FeeEcotone(_data); @@ -63,7 +64,7 @@ contract GasPriceOracle is ISemver { require(isFjord, "GasPriceOracle: getL1FeeUpperBound only supports Fjord"); // txSize / 255 + 16 is the pratical fastlz upper-bound covers %99.99 txs. - // Add 68 to both size values to account for unsigned tx: + // Add 68 to the size to account for unsigned tx: uint256 flzUpperBound = _unsignedTxSize + _unsignedTxSize / 255 + 16 + 68; return _fjordL1Cost(flzUpperBound); @@ -153,7 +154,13 @@ contract GasPriceOracle is ISemver { /// of padding to account for the fact that the input does not have a signature. /// @param _data Unsigned fully RLP-encoded transaction to get the L1 gas for. /// @return Amount of L1 gas used to publish the transaction. + /// @custom:deprecated This method does not accurately estimate the gas used for a transaction. + /// If you are calculating fees use getL1Fee or getL1FeeUpperBound. function getL1GasUsed(bytes memory _data) public view returns (uint256) { + if (isFjord) { + // Add 68 to the size to account for unsigned tx + return Math.max(LibZip.flzCompress(_data).length + 68, MIN_TRANSACTION_SIZE) * 16; + } uint256 l1GasUsed = _getCalldataGas(_data); if (isEcotone) { return l1GasUsed; @@ -182,16 +189,6 @@ contract GasPriceOracle is ISemver { return fee / (16 * 10 ** DECIMALS); } - /// @notice L1 portion of the fee after Fjord. - /// @param _data Unsigned fully RLP-encoded transaction to get the L1 fee for. - /// @return L1 fee that should be paid for the tx - function _getL1FeeFjord(bytes memory _data) internal view returns (uint256) { - // add 68 to the size to account for unsigned tx: - uint256 fastlzSize = LibZip.flzCompress(_data).length + 68; - - return _fjordL1Cost(fastlzSize); - } - /// @notice L1 gas estimation calculation. /// @param _data Unsigned fully RLP-encoded transaction to get the L1 gas for. /// @return Amount of L1 gas used to publish the transaction. @@ -209,17 +206,12 @@ contract GasPriceOracle is ISemver { } /// @notice Fjord L1 cost based on the compressed and original tx size. - /// @param _fastlzSize fastlz compressed tx size. + /// @param _estimatedSize fastlz compressed tx size. /// @return Fjord L1 fee that should be paid for the tx - function _fjordL1Cost(uint256 _fastlzSize) internal view returns (uint256) { + function _fjordL1Cost(uint256 _estimatedSize) internal view returns (uint256) { + _estimatedSize = Math.max(_estimatedSize, MIN_TRANSACTION_SIZE); uint256 feeScaled = baseFeeScalar() * 16 * l1BaseFee() + blobBaseFeeScalar() * blobBaseFee(); - - if (_fastlzSize < MIN_TRANSCTION_SIZE) { - _fastlzSize = MIN_TRANSCTION_SIZE; - } - - // Due to the minimum fastlz size check, it's not possible for cost to be a negative number - int256 cost = COST_INTERCEPT + int256(COST_FASTLZ_COEF * _fastlzSize); + int256 cost = COST_INTERCEPT + int256(COST_FASTLZ_COEF * _estimatedSize); return uint256(cost) * feeScaled / (10 ** (DECIMALS * 2)); } } diff --git a/packages/contracts-bedrock/test/L2/GasPriceOracle.t.sol b/packages/contracts-bedrock/test/L2/GasPriceOracle.t.sol index 9ee64bdff663e..1fbc37fb7c023 100644 --- a/packages/contracts-bedrock/test/L2/GasPriceOracle.t.sol +++ b/packages/contracts-bedrock/test/L2/GasPriceOracle.t.sol @@ -262,38 +262,38 @@ contract GasPriceOracleFjordActive_Test is GasPriceOracle_Test { } /// @dev Tests that `l1BaseFee` is set correctly. - function test_l1BaseFee_succeeds() external { + function test_l1BaseFee_succeeds() view external { assertEq(gasPriceOracle.l1BaseFee(), baseFee); } /// @dev Tests that `blobBaseFee` is set correctly. - function test_blobBaseFee_succeeds() external { + function test_blobBaseFee_succeeds() view external { assertEq(gasPriceOracle.blobBaseFee(), blobBaseFee); } /// @dev Tests that `baseFeeScalar` is set correctly. - function test_baseFeeScalar_succeeds() external { + function test_baseFeeScalar_succeeds() view external { assertEq(gasPriceOracle.baseFeeScalar(), baseFeeScalar); } /// @dev Tests that `blobBaseFeeScalar` is set correctly. - function test_blobBaseFeeScalar_succeeds() external { + function test_blobBaseFeeScalar_succeeds() view external { assertEq(gasPriceOracle.blobBaseFeeScalar(), blobBaseFeeScalar); } /// @dev Tests that `decimals` is set correctly. - function test_decimals_succeeds() external { + function test_decimals_succeeds() view external { assertEq(gasPriceOracle.decimals(), 6); assertEq(gasPriceOracle.DECIMALS(), 6); } /// @dev Tests that `getL1GasUsed` and `getL1Fee` return expected values - function test_getL1Fee_succeeds() external { - bytes memory data = hex"0000010203"; // fastlzSize: 74 + function test_getL1Fee_succeeds() view external { + bytes memory data = hex"0000010203"; // fastlzSize: 74, inc signature uint256 gas = gasPriceOracle.getL1GasUsed(data); - assertEq(gas, 1144); + assertEq(gas, 1184); // 74 * 16 uint256 price = gasPriceOracle.getL1Fee(data); - assertEq(price, 13231); + assertEq(price, 13231); // (-42_585_600 + 74 * 836_500) * (20 * 16 * 2 * 1e6 + 3 * 1e6 * 15) / 1e12 } }