Skip to content
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

contracts-bedrock: ecotone gas config support #10226

Merged
merged 29 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,6 @@ func (d *DeployConfig) Check() error {
if !d.SequencerFeeVaultWithdrawalNetwork.Valid() {
return fmt.Errorf("%w: SequencerFeeVaultWithdrawalNetwork can only be 0 (L1) or 1 (L2)", ErrInvalidDeployConfig)
}
if d.GasPriceOracleOverhead == 0 {
log.Warn("GasPriceOracleOverhead is 0")
}
if d.GasPriceOracleScalar == 0 {
log.Warn("GasPriceOracleScalar is 0")
}
if d.GasPriceOracleBaseFeeScalar == 0 {
log.Warn("GasPriceOracleBaseFeeScalar is 0")
}
Expand Down Expand Up @@ -606,7 +600,8 @@ func (d *DeployConfig) InteropTime(genesisTime uint64) *uint64 {
return &v
}

// RollupConfig converts a DeployConfig to a rollup.Config
// RollupConfig converts a DeployConfig to a rollup.Config. If Ecotone is active at genesis, the
// Overhead value is considered a noop.
func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHash common.Hash, l2GenesisBlockNumber uint64) (*rollup.Config, error) {
if d.OptimismPortalProxy == (common.Address{}) {
return nil, errors.New("OptimismPortalProxy cannot be address(0)")
Expand Down
6 changes: 0 additions & 6 deletions op-chain-ops/upgrades/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,6 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi
}

if config != nil {
if gasPriceOracleOverhead.Uint64() != config.GasPriceOracleOverhead {
return fmt.Errorf("GasPriceOracleOverhead address doesn't match config")
}
if gasPriceOracleScalar.Uint64() != config.GasPriceOracleScalar {
return fmt.Errorf("GasPriceOracleScalar address doesn't match config")
}
if batcherHash != common.BytesToHash(config.BatchSenderAddress.Bytes()) {
return fmt.Errorf("BatchSenderAddress address doesn't match config")
}
Expand Down
5 changes: 3 additions & 2 deletions op-e2e/actions/ecotone_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
scalar, err := gasPriceOracle.Scalar(nil)
require.NoError(t, err)
require.True(t, scalar.Cmp(big.NewInt(0)) > 0, "scalar must start non-zero")
require.True(t, scalar.Cmp(new(big.Int).SetUint64(dp.DeployConfig.GasPriceOracleScalar)) == 0, "must match deploy config")
feeScalar := dp.DeployConfig.FeeScalar()
require.Equal(t, scalar, new(big.Int).SetBytes(feeScalar[:]), "must match deploy config")

// Get current implementations addresses (by slot) for L1Block + GasPriceOracle
initialGasPriceOracleAddress, err := ethCl.StorageAt(context.Background(), predeploys.GasPriceOracleAddr, genesis.ImplementationSlot, nil)
Expand Down Expand Up @@ -193,7 +194,7 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
// test if the migrated scalar matches the deploy config
basefeeScalar, err := gasPriceOracle.BaseFeeScalar(nil)
require.NoError(t, err)
require.True(t, uint64(basefeeScalar) == dp.DeployConfig.GasPriceOracleScalar, "must match deploy config")
require.Equal(t, uint64(basefeeScalar), dp.DeployConfig.GasPriceOracleScalar, "must match deploy config")

cost, err = gasPriceOracle.GetL1Fee(nil, []byte{0, 1, 2, 3, 4})
require.NoError(t, err)
Expand Down
183 changes: 127 additions & 56 deletions op-e2e/bindings/systemconfig.go

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions op-e2e/custom_gas_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"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/ethclient"
"github.com/stretchr/testify/require"
Expand All @@ -23,6 +24,12 @@ func TestCustomGasToken(t *testing.T) {
InitParallel(t, SkipOnFPAC) // Custom Gas Token feature is not yet compatible with FPAC

cfg := DefaultSystemConfig(t)
offset := hexutil.Uint64(0)
cfg.DeployConfig.L2GenesisRegolithTimeOffset = &offset
cfg.DeployConfig.L1CancunTimeOffset = &offset
cfg.DeployConfig.L2GenesisCanyonTimeOffset = &offset
cfg.DeployConfig.L2GenesisDeltaTimeOffset = &offset
cfg.DeployConfig.L2GenesisEcotoneTimeOffset = &offset

sys, err := cfg.Start(t)
require.NoError(t, err, "Error starting up system")
Expand Down Expand Up @@ -324,9 +331,9 @@ func setCustomGasToken(t *testing.T, cfg SystemConfig, sys *System, cgtAddress c
// Get existing parameters from SystemConfigProxy contract
owner, err := systemConfig.Owner(&bind.CallOpts{})
require.NoError(t, err)
overhead, err := systemConfig.Overhead(&bind.CallOpts{})
basefeeScalar, err := systemConfig.BasefeeScalar(&bind.CallOpts{})
require.NoError(t, err)
scalar, err := systemConfig.Scalar(&bind.CallOpts{})
blobbasefeeScalar, err := systemConfig.BlobbasefeeScalar(&bind.CallOpts{})
require.NoError(t, err)
batcherHash, err := systemConfig.BatcherHash(&bind.CallOpts{})
require.NoError(t, err)
Expand Down Expand Up @@ -406,8 +413,8 @@ func setCustomGasToken(t *testing.T, cfg SystemConfig, sys *System, cgtAddress c

// Reinitialise with existing initializer values but with custom gas token set
tx, err = systemConfig.Initialize(deployerOpts, owner,
overhead,
scalar,
basefeeScalar,
blobbasefeeScalar,
batcherHash,
gasLimit,
unsafeBlockSigner,
Expand Down
3 changes: 2 additions & 1 deletion op-e2e/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,8 @@ func testFees(t *testing.T, cfg SystemConfig) {

scalar, err := gpoContract.Scalar(&bind.CallOpts{})
require.Nil(t, err, "reading gpo scalar")
require.Equal(t, scalar.Uint64(), cfg.DeployConfig.GasPriceOracleScalar, "wrong gpo scalar")
feeScalar := cfg.DeployConfig.FeeScalar()
require.Equal(t, scalar, new(big.Int).SetBytes(feeScalar[:]), "wrong gpo scalar")
tynes marked this conversation as resolved.
Show resolved Hide resolved
} else {
_, err := gpoContract.Overhead(&bind.CallOpts{})
require.ErrorContains(t, err, "deprecated")
Expand Down
5 changes: 3 additions & 2 deletions op-e2e/system_tob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func TestGasPriceOracleFeeUpdates(t *testing.T) {
InitParallel(t)
// Define our values to set in the GasPriceOracle (we set them high to see if it can lock L2 or stop bindings
// from updating the prices once again.
overheadValue := abi.MaxUint256
scalarValue := abi.MaxUint256
overheadValue := new(big.Int).Set(abi.MaxUint256)
// Ensure the most significant byte is 0x00
scalarValue := new(big.Int).Rsh(new(big.Int).Set(abi.MaxUint256), 8)
var cancel context.CancelFunc

// Create our system configuration for L1/L2 and start it
Expand Down
4 changes: 0 additions & 4 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var (
ErrGenesisHashesSame = errors.New("achievement get! rollup inception: L1 and L2 genesis cannot be the same")
ErrMissingGenesisL2Time = errors.New("missing L2 genesis time")
ErrMissingBatcherAddr = errors.New("missing genesis system config batcher address")
ErrMissingOverhead = errors.New("missing genesis system config overhead")
ErrMissingScalar = errors.New("missing genesis system config scalar")
ErrMissingGasLimit = errors.New("missing genesis system config gas limit")
ErrMissingBatchInboxAddress = errors.New("missing batch inbox address")
Expand Down Expand Up @@ -278,9 +277,6 @@ func (cfg *Config) Check() error {
if cfg.Genesis.SystemConfig.BatcherAddr == (common.Address{}) {
return ErrMissingBatcherAddr
}
if cfg.Genesis.SystemConfig.Overhead == (eth.Bytes32{}) {
return ErrMissingOverhead
}
if cfg.Genesis.SystemConfig.Scalar == (eth.Bytes32{}) {
return ErrMissingScalar
}
Expand Down
5 changes: 0 additions & 5 deletions op-node/rollup/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,6 @@ func TestConfig_Check(t *testing.T) {
modifier: func(cfg *Config) { cfg.Genesis.SystemConfig.BatcherAddr = common.Address{} },
expectedErr: ErrMissingBatcherAddr,
},
{
name: "NoOverhead",
modifier: func(cfg *Config) { cfg.Genesis.SystemConfig.Overhead = eth.Bytes32{} },
expectedErr: ErrMissingOverhead,
},
{
name: "NoScalar",
modifier: func(cfg *Config) { cfg.Genesis.SystemConfig.Scalar = eth.Bytes32{} },
Expand Down
16 changes: 8 additions & 8 deletions packages/contracts-bedrock/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369357)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967497)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 561969)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4074012)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 466924)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3512606)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369380)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967520)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 561992)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4074035)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 466947)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3512629)
GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (gas: 72629)
GasBenchMark_L2OutputOracle:test_proposeL2Output_benchmark() (gas: 92973)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark() (gas: 68410)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark_1() (gas: 68880)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark() (gas: 68433)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark_1() (gas: 68903)
GasBenchMark_OptimismPortal:test_proveWithdrawalTransaction_benchmark() (gas: 155618)
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"l2GenesisBlockBaseFeePerGas": "0x1",
"gasPriceOracleOverhead": 2100,
"gasPriceOracleScalar": 1000000,
tynes marked this conversation as resolved.
Show resolved Hide resolved
"gasPriceOracleBaseFeeScalar": 1368,
"gasPriceOracleBlobBaseFeeScalar": 810949,
"enableGovernance": true,
"governanceTokenSymbol": "OP",
"governanceTokenName": "Optimism",
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts-bedrock/deploy-config/hardhat.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"l2OutputOracleSubmissionInterval": 6,
"l2OutputOracleStartingTimestamp": 1,
"l2OutputOracleStartingBlockNumber": 1,
"gasPriceOracleOverhead": 2100,
"gasPriceOracleScalar": 1000000,
"gasPriceOracleBaseFeeScalar": 1368,
"gasPriceOracleBlobBaseFeeScalar": 810949,
"l2OutputOracleProposer": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
"governanceTokenOwner": "0x858F0751ef8B4067f0d2668C076BDB50a8549fbF",
"l2GenesisBlockGasLimit": "0x17D7840",
"l2GenesisBlockBaseFeePerGas": "0x3b9aca00",
"gasPriceOracleOverhead": 2100,
"gasPriceOracleScalar": 1000000,
"eip1559Denominator": 50,
"eip1559Elasticity": 10,
"systemConfigStartBlock": 8364212,
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts-bedrock/deploy-config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
"governanceTokenOwner": "0x5C4e7Ba1E219E47948e6e3F55019A647bA501005",
"l2GenesisBlockGasLimit": "0x1c9c380",
"l2GenesisBlockBaseFeePerGas": "0x3b9aca00",
"gasPriceOracleOverhead": 0,
"gasPriceOracleScalar": 0,
"gasPriceOracleBaseFeeScalar": 1368,
"gasPriceOracleBlobBaseFeeScalar": 810949,
"eip1559Denominator": 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
"l1ERC721BridgeProxy": "0x0000000000000000000000000000000000000000",
"systemConfigProxy": "0x0000000000000000000000000000000000000000",
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
"gasPriceOracleOverhead": 188,
"gasPriceOracleScalar": 684000,
"enableGovernance": true,
"governanceTokenSymbol": "OP",
"governanceTokenName": "Optimism",
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts-bedrock/deploy-config/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
"baseFeeVaultWithdrawalNetwork": 0,
"l1FeeVaultWithdrawalNetwork": 0,
"sequencerFeeVaultWithdrawalNetwork": 0,
"gasPriceOracleOverhead": 188,
"gasPriceOracleScalar": 684000,
"enableGovernance": true,
"governanceTokenSymbol": "OP",
"governanceTokenName": "Optimism",
Expand Down
9 changes: 6 additions & 3 deletions packages/contracts-bedrock/scripts/ChainAssertions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ library ChainAssertions {

if (_isProxy) {
require(config.owner() == _cfg.finalSystemOwner());
require(config.overhead() == _cfg.gasPriceOracleOverhead());
require(config.scalar() == _cfg.gasPriceOracleScalar());
require(config.basefeeScalar() == _cfg.basefeeScalar());
tynes marked this conversation as resolved.
Show resolved Hide resolved
require(config.blobbasefeeScalar() == _cfg.blobbasefeeScalar());
require(config.batcherHash() == bytes32(uint256(uint160(_cfg.batchSenderAddress()))));
require(config.gasLimit() == uint64(_cfg.l2GenesisBlockGasLimit()));
require(config.unsafeBlockSigner() == _cfg.p2pSequencerAddress());
require(config.scalar() >> 248 == 1);
tynes marked this conversation as resolved.
Show resolved Hide resolved
// Check _config
ResourceMetering.ResourceConfig memory rconfig = Constants.DEFAULT_RESOURCE_CONFIG();
require(resourceConfig.maxResourceLimit == rconfig.maxResourceLimit);
Expand All @@ -98,7 +99,9 @@ library ChainAssertions {
} else {
require(config.owner() == address(0xdead));
require(config.overhead() == 0);
require(config.scalar() == 0);
require(config.scalar() == uint256(0x01) << 248); // version 1
require(config.basefeeScalar() == 0);
require(config.blobbasefeeScalar() == 0);
require(config.batcherHash() == bytes32(0));
require(config.gasLimit() == 1);
require(config.unsafeBlockSigner() == address(0));
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,8 @@ contract Deploy is Deployer {
SystemConfig.initialize,
(
cfg.finalSystemOwner(),
cfg.gasPriceOracleOverhead(),
cfg.gasPriceOracleScalar(),
cfg.basefeeScalar(),
cfg.blobbasefeeScalar(),
batcherHash,
uint64(cfg.l2GenesisBlockGasLimit()),
cfg.p2pSequencerAddress(),
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts-bedrock/scripts/DeployConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ contract DeployConfig is Script {
string public governanceTokenSymbol;
address public governanceTokenOwner;
uint256 public l2GenesisBlockGasLimit;
uint256 public gasPriceOracleOverhead;
uint256 public gasPriceOracleScalar;
uint32 public basefeeScalar;
uint32 public blobbasefeeScalar;
bool public enableGovernance;
uint256 public eip1559Denominator;
uint256 public eip1559Elasticity;
Expand Down Expand Up @@ -119,8 +119,9 @@ contract DeployConfig is Script {
governanceTokenSymbol = stdJson.readString(_json, "$.governanceTokenSymbol");
governanceTokenOwner = stdJson.readAddress(_json, "$.governanceTokenOwner");
l2GenesisBlockGasLimit = stdJson.readUint(_json, "$.l2GenesisBlockGasLimit");
gasPriceOracleOverhead = stdJson.readUint(_json, "$.gasPriceOracleOverhead");
gasPriceOracleScalar = stdJson.readUint(_json, "$.gasPriceOracleScalar");
basefeeScalar = uint32(_readOr(_json, "$.gasPriceOracleBaseFeeScalar", 1368));
blobbasefeeScalar = uint32(_readOr(_json, "$.gasPriceOracleBlobBaseFeeScalar", 810949));

enableGovernance = stdJson.readBool(_json, "$.enableGovernance");
eip1559Denominator = stdJson.readUint(_json, "$.eip1559Denominator");
eip1559Elasticity = stdJson.readUint(_json, "$.eip1559Elasticity");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ethereum-optimism/optimism/cannon/mipsevm"
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -35,6 +36,8 @@ var (
{Type: fixedBytes},
}

uint32Type, _ = abi.NewType("uint32", "", nil)

// Decoded nonce tuple (nonce, version)
decodedNonce, _ = abi.NewType("tuple", "DecodedNonce", []abi.ArgumentMarshaling{
{Name: "nonce", Type: "uint256"},
Expand All @@ -44,6 +47,12 @@ var (
{Name: "encodedNonce", Type: decodedNonce},
}

// Decoded ecotone scalars (uint32, uint32)
decodedScalars = abi.Arguments{
{Name: "basefeeScalar", Type: uint32Type},
{Name: "blobbasefeeScalar", Type: uint32Type},
}

// WithdrawalHash slot tuple (bytes32, bytes32)
withdrawalSlot, _ = abi.NewType("tuple", "SlotHash", []abi.ArgumentMarshaling{
{Name: "withdrawalHash", Type: "bytes32"},
Expand Down Expand Up @@ -361,6 +370,25 @@ func DiffTestUtils() {
packed, err := cannonMemoryProofArgs.Pack(&output)
checkErr(err, "Error encoding output")
fmt.Print(hexutil.Encode(packed[32:]))
case "encodeScalarEcotone":
basefeeScalar, err := strconv.ParseUint(args[1], 10, 32)
checkErr(err, "Error decocding basefeeScalar")
blobbasefeeScalar, err := strconv.ParseUint(args[2], 10, 32)
checkErr(err, "Error decocding blobbasefeeScalar")

encoded := eth.EncodeScalar(eth.EcotoneScalars{
BaseFeeScalar: uint32(basefeeScalar),
BlobBaseFeeScalar: uint32(blobbasefeeScalar),
})
fmt.Print(hexutil.Encode(encoded[:]))
case "decodeScalarEcotone":
scalar := common.HexToHash(args[1])
scalars, err := eth.DecodeScalar([32]byte(scalar[:]))
checkErr(err, "Error decoding scalar")

packed, err := decodedScalars.Pack(scalars.BaseFeeScalar, scalars.BlobBaseFeeScalar)
checkErr(err, "Error encoding output")
fmt.Print(hexutil.Encode(packed))
default:
panic(fmt.Errorf("Unknown command: %s", args[0]))
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"sourceCodeHash": "0xd6a894e371c2c7182b5960c507491f81c3775dda0efedd29475f7c30ca07b004"
},
"src/L1/SystemConfig.sol": {
"initCodeHash": "0xe937c5747e42d6701ff3fbb10471302288fa765fb40cbd9822e22547a42dfa25",
"sourceCodeHash": "0x9fb21393eb206f94bdf7e034c667535c415b7de93a1355058626d1c9e8abbff5"
"initCodeHash": "0x49f30f938da30fae6104bc9315bd749a1bd43a45cc63499d9b085408a08be401",
"sourceCodeHash": "0x2019254cb5a27a45c3de64397164c8c7b4a4d5f814f410a481b3c85c7a0b1916"
},
"src/L2/BaseFeeVault.sol": {
"initCodeHash": "0x2744d34573be83206d1b75d049d18a7bb37f9058e68c0803e5008c46b0dc2474",
Expand Down