Commit f68d876c authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: system config fix

Be sure to emit an event in the initialize function
for the changes to the properties that the op-node cares
about. This will ensure that the op-node's view of the
system config is never corrupted. Without this change,
an accidental reinitialize where the values are changed
could result in this happening. Add events to prevent
this from happening. This is done by making internal functions
that are not `onlyOwner` and using those internal functions
in `initialize`.

Bump the version of the system config a minor version.
parent bd07e6e6
This diff is collapsed.
This diff is collapsed.
...@@ -643,10 +643,10 @@ SequencerFeeVault_Test:test_withdraw_toL1_succeeds() (gas: 171357) ...@@ -643,10 +643,10 @@ SequencerFeeVault_Test:test_withdraw_toL1_succeeds() (gas: 171357)
SetPrevBaseFee_Test:test_setPrevBaseFee_succeeds() (gas: 11549) SetPrevBaseFee_Test:test_setPrevBaseFee_succeeds() (gas: 11549)
StandardBridge_Stateless_Test:test_isCorrectTokenPair_succeeds() (gas: 49936) StandardBridge_Stateless_Test:test_isCorrectTokenPair_succeeds() (gas: 49936)
StandardBridge_Stateless_Test:test_isOptimismMintableERC20_succeeds() (gas: 33072) StandardBridge_Stateless_Test:test_isOptimismMintableERC20_succeeds() (gas: 33072)
SystemConfig_Initialize_Test:test_initialize_startBlockOverride_succeeds() (gas: 55905) SystemConfig_Initialize_Test:test_initialize_startBlockOverride_succeeds() (gas: 63050)
SystemConfig_Initialize_Test:test_initialize_values_succeeds() (gas: 64946) SystemConfig_Initialize_Test:test_initialize_values_succeeds() (gas: 64946)
SystemConfig_Initialize_TestFail:test_initialize_lowGasLimit_reverts() (gas: 94515) SystemConfig_Initialize_TestFail:test_initialize_lowGasLimit_reverts() (gas: 55653)
SystemConfig_Initialize_TestFail:test_initialize_startBlock_reverts() (gas: 64676) SystemConfig_Initialize_TestFail:test_initialize_startBlock_reverts() (gas: 75601)
SystemConfig_Setters_TestFail:test_setBatcherHash_notOwner_reverts() (gas: 15607) SystemConfig_Setters_TestFail:test_setBatcherHash_notOwner_reverts() (gas: 15607)
SystemConfig_Setters_TestFail:test_setGasConfig_notOwner_reverts() (gas: 15577) SystemConfig_Setters_TestFail:test_setGasConfig_notOwner_reverts() (gas: 15577)
SystemConfig_Setters_TestFail:test_setGasLimit_notOwner_reverts() (gas: 15676) SystemConfig_Setters_TestFail:test_setGasLimit_notOwner_reverts() (gas: 15676)
......
...@@ -98,11 +98,11 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -98,11 +98,11 @@ contract SystemConfig is OwnableUpgradeable, Semver {
/// @notice The block at which the op-node can start searching for logs from. /// @notice The block at which the op-node can start searching for logs from.
uint256 public startBlock; uint256 public startBlock;
/// @custom:semver 1.5.0 /// @custom:semver 1.6.0
/// @notice Constructs the SystemConfig contract. Cannot set /// @notice Constructs the SystemConfig contract. Cannot set
/// the owner to `address(0)` due to the Ownable contract's /// the owner to `address(0)` due to the Ownable contract's
/// implementation, so set it to `address(0xdEaD)` /// implementation, so set it to `address(0xdEaD)`
constructor() Semver(1, 5, 0) { constructor() Semver(1, 6, 0) {
initialize({ initialize({
_owner: address(0xdEaD), _owner: address(0xdEaD),
_overhead: 0, _overhead: 0,
...@@ -165,10 +165,13 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -165,10 +165,13 @@ contract SystemConfig is OwnableUpgradeable, Semver {
__Ownable_init(); __Ownable_init();
transferOwnership(_owner); transferOwnership(_owner);
overhead = _overhead; _setGasConfig({
scalar = _scalar; _overhead: _overhead,
batcherHash = _batcherHash; _scalar: _scalar
gasLimit = _gasLimit; });
_setBatcherHash(_batcherHash);
_setGasLimit(_gasLimit);
_setAddress(_unsafeBlockSigner, UNSAFE_BLOCK_SIGNER_SLOT); _setAddress(_unsafeBlockSigner, UNSAFE_BLOCK_SIGNER_SLOT);
_setAddress(_batchInbox, BATCH_INBOX_SLOT); _setAddress(_batchInbox, BATCH_INBOX_SLOT);
...@@ -291,19 +294,32 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -291,19 +294,32 @@ contract SystemConfig is OwnableUpgradeable, Semver {
emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_SIGNER, data); emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_SIGNER, data);
} }
/// @notice Updates the batcher hash. /// @notice Updates the batcher hash. Can only be called by the owner.
/// @param _batcherHash New batcher hash. /// @param _batcherHash New batcher hash.
function setBatcherHash(bytes32 _batcherHash) external onlyOwner { function setBatcherHash(bytes32 _batcherHash) external onlyOwner {
_setBatcherHash(_batcherHash);
}
/// @notice Internal function for updating the batcher hash.
/// @param _batcherHash New batcher hash.
function _setBatcherHash(bytes32 _batcherHash) internal {
batcherHash = _batcherHash; batcherHash = _batcherHash;
bytes memory data = abi.encode(_batcherHash); bytes memory data = abi.encode(_batcherHash);
emit ConfigUpdate(VERSION, UpdateType.BATCHER, data); emit ConfigUpdate(VERSION, UpdateType.BATCHER, data);
} }
/// @notice Updates gas config. /// @notice Updates gas config. Can only be called by the owner.
/// @param _overhead New overhead value. /// @param _overhead New overhead value.
/// @param _scalar New scalar value. /// @param _scalar New scalar value.
function setGasConfig(uint256 _overhead, uint256 _scalar) external onlyOwner { function setGasConfig(uint256 _overhead, uint256 _scalar) external onlyOwner {
_setGasConfig(_overhead, _scalar);
}
/// @notice Internal function for updating the gas config.
/// @param _overhead New overhead value.
/// @param _scalar New scalar value.
function _setGasConfig(uint256 _overhead, uint256 _scalar) internal {
overhead = _overhead; overhead = _overhead;
scalar = _scalar; scalar = _scalar;
...@@ -311,9 +327,15 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -311,9 +327,15 @@ contract SystemConfig is OwnableUpgradeable, Semver {
emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG, data); emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG, data);
} }
/// @notice Updates the L2 gas limit. /// @notice Updates the L2 gas limit. Can only be called by the owner.
/// @param _gasLimit New gas limit. /// @param _gasLimit New gas limit.
function setGasLimit(uint64 _gasLimit) external onlyOwner { function setGasLimit(uint64 _gasLimit) external onlyOwner {
_setGasLimit(_gasLimit);
}
/// @notice Internal function for updating the L2 gas limit.
/// @param _gasLimit New gas limit.
function _setGasLimit(uint64 _gasLimit) internal {
require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low"); require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low");
gasLimit = _gasLimit; gasLimit = _gasLimit;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment