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

add new UpdateType & fields to L1 system config required for the Ecotone upgrade #8723

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions op-bindings/bindings/systemconfig.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions op-bindings/bindings/systemconfig_more.go

Large diffs are not rendered by default.

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: 352278)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950440)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 540648)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4052841)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 442007)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3487756)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352300)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950462)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 540670)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4052863)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 441857)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3487778)
GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (gas: 55367)
GasBenchMark_L2OutputOracle:test_proposeL2Output_benchmark() (gas: 86629)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark() (gas: 68450)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark_1() (gas: 68899)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark() (gas: 68300)
GasBenchMark_OptimismPortal:test_depositTransaction_benchmark_1() (gas: 68921)
GasBenchMark_OptimismPortal:test_proveWithdrawalTransaction_benchmark() (gas: 153501)
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"sourceCodeHash": "0xfe22a85a76e6dca67a24202742374a23135354f3ce135f58ad8c06adf56a1d1c"
},
"src/L1/SystemConfig.sol": {
"initCodeHash": "0x7662ba203d662cf433b3e44b85fdd6f4d5b39d77eb88156200d15b6bc8f15bc4",
"sourceCodeHash": "0x04ce779f3bf7463af5e633f76f2c712e73a8ade75c9ef3624ae59a761d279156"
"initCodeHash": "0x6362c8b56b6fa5efdb5121f8f697b33e31caeba5d0565749c1cd5656aa43d540",
"sourceCodeHash": "0x88a5843cf763b01401e9eaaa4edcb8c3e60933580fa3fbc0f7e40959498e9783"
},
"src/L2/BaseFeeVault.sol": {
"initCodeHash": "0x2744d34573be83206d1b75d049d18a7bb37f9058e68c0803e5008c46b0dc2474",
Expand Down
44 changes: 44 additions & 0 deletions packages/contracts-bedrock/snapshots/abi/SystemConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "basefeeScalar",
"outputs": [
{
"internalType": "uint32",
"name": "",
"type": "uint32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "batcherHash",
Expand All @@ -111,6 +124,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "blobBasefeeScalar",
"outputs": [
{
"internalType": "uint32",
"name": "",
"type": "uint32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "gasLimit",
Expand Down Expand Up @@ -334,6 +360,24 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint32",
"name": "_basefeeScalar",
"type": "uint32"
},
{
"internalType": "uint32",
"name": "_blobBasefeeScalar",
"type": "uint32"
}
],
"name": "setGasConfigEcotone",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@
"slot": "104",
"type": "uint64"
},
{
"bytes": "4",
"label": "basefeeScalar",
"offset": 8,
"slot": "104",
"type": "uint32"
},
{
"bytes": "4",
"label": "blobBasefeeScalar",
"offset": 12,
"slot": "104",
"type": "uint32"
},
{
"bytes": "32",
"label": "_resourceConfig",
Expand Down
33 changes: 30 additions & 3 deletions packages/contracts-bedrock/src/L1/SystemConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
/// @custom:value GAS_CONFIG Represents an update to txn fee config on L2.
/// @custom:value GAS_LIMIT Represents an update to gas limit on L2.
/// @custom:value UNSAFE_BLOCK_SIGNER Represents an update to the signer key for unsafe
/// @custom:value GAS_CONFIG_ECOTONE Represents an update to txn fee config on L2 after Ecotone upgrade.
/// block distrubution.
enum UpdateType {
BATCHER,
GAS_CONFIG,
GAS_LIMIT,
UNSAFE_BLOCK_SIGNER
UNSAFE_BLOCK_SIGNER,
GAS_CONFIG_ECOTONE
}

/// @notice Version identifier, used for upgrades.
Expand Down Expand Up @@ -52,6 +54,12 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
/// @notice L2 block gas limit.
uint64 public gasLimit;

/// @notice The scalar value applied to the L1 base fee portion of the blob-capable L1 cost func
uint32 public basefeeScalar;

/// @notice The scalar value applied to the L1 blob base fee portion of the blob-capable L1 cost func
uint32 public blobBasefeeScalar;

/// @notice The configuration for the deposit fee market.
/// Used by the OptimismPortal to meter the cost of buying L2 gas on L1.
/// Set as internal with a getter so that the struct is returned instead of a tuple.
Expand All @@ -64,8 +72,8 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
event ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data);

/// @notice Semantic version.
/// @custom:semver 1.11.0
string public constant version = "1.11.0";
/// @custom:semver 1.12.0
string public constant version = "1.12.0";

/// @notice Constructs the SystemConfig contract. Cannot set
/// the owner to `address(0)` due to the Ownable contract's
Expand Down Expand Up @@ -124,6 +132,7 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
// These are set in ascending order of their UpdateTypes.
_setBatcherHash(_batcherHash);
_setGasConfig({ _overhead: _overhead, _scalar: _scalar });
_setGasConfigEcotone({ _basefeeScalar: uint32(_scalar), _blobBasefeeScalar: 0 });
tynes marked this conversation as resolved.
Show resolved Hide resolved
_setGasLimit(_gasLimit);
_setUnsafeBlockSigner(_unsafeBlockSigner);
_setResourceConfig(_config);
Expand Down Expand Up @@ -197,6 +206,24 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG, data);
}

/// @notice Updates gas config as of the Ecotone upgrade. Can only be called by the owner.
/// @param _basefeeScalar New basefeeScalar value.
/// @param _blobBasefeeScalar New blobBasefeeScalar value.
function setGasConfigEcotone(uint32 _basefeeScalar, uint32 _blobBasefeeScalar) external onlyOwner {
_setGasConfigEcotone(_basefeeScalar, _blobBasefeeScalar);
}

/// @notice Internal function for updating the fee scalars as of the Ecotone upgrade.
/// @param _basefeeScalar New basefeeScalar value.
/// @param _blobBasefeeScalar New blobBasefeeScalar value.
function _setGasConfigEcotone(uint32 _basefeeScalar, uint32 _blobBasefeeScalar) internal {
basefeeScalar = _basefeeScalar;
blobBasefeeScalar = _blobBasefeeScalar;

bytes memory data = abi.encodePacked(_basefeeScalar, _blobBasefeeScalar);
emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG_ECOTONE, data);
}

/// @notice Updates the L2 gas limit. Can only be called by the owner.
/// @param _gasLimit New gas limit.
function setGasLimit(uint64 _gasLimit) external onlyOwner {
Expand Down
21 changes: 21 additions & 0 deletions packages/contracts-bedrock/test/L1/SystemConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ contract SystemConfig_Initialize_Test is SystemConfig_Init {
assertEq(systemConfig.batcherHash(), batcherHash);
assertEq(systemConfig.gasLimit(), gasLimit);
assertEq(systemConfig.unsafeBlockSigner(), unsafeBlockSigner);
assertEq(systemConfig.basefeeScalar(), scalar);
assertEq(systemConfig.blobBasefeeScalar(), 0);
// Depends on `initialize` being called with defaults
ResourceMetering.ResourceConfig memory rcfg = Constants.DEFAULT_RESOURCE_CONFIG();
ResourceMetering.ResourceConfig memory actual = systemConfig.resourceConfig();
Expand Down Expand Up @@ -109,6 +111,12 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
systemConfig.setGasConfig(0, 0);
}

/// @dev Tests that `setGasConfigEcotone` reverts if the caller is not the owner.
function test_setGasConfigEcotone_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
systemConfig.setGasConfigEcotone(0, 0);
}

/// @dev Tests that `setGasLimit` reverts if the caller is not the owner.
function test_setGasLimit_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
Expand Down Expand Up @@ -216,6 +224,19 @@ contract SystemConfig_Setters_Test is SystemConfig_Init {
assertEq(systemConfig.scalar(), newScalar);
}

/// @dev Tests that `setGasConfigEcotone` updates the gas limit successfully.
function testFuzz_setGasConfigEcotone_succeeds(uint32 basefeeScalar, uint32 blobBasefeeScalar) external {
vm.expectEmit(address(systemConfig));
emit ConfigUpdate(
0, SystemConfig.UpdateType.GAS_CONFIG_ECOTONE, abi.encodePacked(basefeeScalar, blobBasefeeScalar)
);

vm.prank(systemConfig.owner());
systemConfig.setGasConfigEcotone(basefeeScalar, blobBasefeeScalar);
assertEq(systemConfig.basefeeScalar(), basefeeScalar);
assertEq(systemConfig.blobBasefeeScalar(), blobBasefeeScalar);
}

/// @dev Tests that `setGasLimit` updates the gas limit successfully.
function testFuzz_setGasLimit_succeeds(uint64 newGasLimit) external {
uint64 minimumGasLimit = systemConfig.minimumGasLimit();
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts-bedrock/test/Specs.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ contract Specification_Test is CommonTest {
_addSpec({ _name: "SystemConfig", _sel: _getSel("VERSION()") });
_addSpec({ _name: "SystemConfig", _sel: _getSel("batcherHash()") });
_addSpec({ _name: "SystemConfig", _sel: _getSel("gasLimit()") });
_addSpec({ _name: "SystemConfig", _sel: _getSel("basefeeScalar()") });
_addSpec({ _name: "SystemConfig", _sel: _getSel("blobBasefeeScalar()") });
tynes marked this conversation as resolved.
Show resolved Hide resolved
_addSpec({ _name: "SystemConfig", _sel: SystemConfig.initialize.selector });
_addSpec({ _name: "SystemConfig", _sel: SystemConfig.minimumGasLimit.selector });
_addSpec({ _name: "SystemConfig", _sel: _getSel("overhead()") });
Expand All @@ -267,6 +269,11 @@ contract Specification_Test is CommonTest {
_addSpec({ _name: "SystemConfig", _sel: _getSel("scalar()") });
_addSpec({ _name: "SystemConfig", _sel: SystemConfig.setBatcherHash.selector, _auth: Role.SYSTEMCONFIGOWNER });
_addSpec({ _name: "SystemConfig", _sel: SystemConfig.setGasConfig.selector, _auth: Role.SYSTEMCONFIGOWNER });
_addSpec({
_name: "SystemConfig",
_sel: SystemConfig.setGasConfigEcotone.selector,
_auth: Role.SYSTEMCONFIGOWNER
});
_addSpec({ _name: "SystemConfig", _sel: SystemConfig.setGasLimit.selector, _auth: Role.SYSTEMCONFIGOWNER });
_addSpec({ _name: "SystemConfig", _sel: SystemConfig.setResourceConfig.selector, _auth: Role.SYSTEMCONFIGOWNER });
_addSpec({
Expand Down