Commit 2d237fe8 authored by Maurelian's avatar Maurelian

feat(ctb): Reduce diff in SystemConfig

parent 03d8e304
...@@ -325,8 +325,6 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi ...@@ -325,8 +325,6 @@ func SystemConfig(batch *safe.Batch, implementations superchain.ImplementationLi
gasPriceOracleScalar = new(big.Int).SetUint64(config.GasPriceOracleScalar) gasPriceOracleScalar = new(big.Int).SetUint64(config.GasPriceOracleScalar)
batcherHash = common.BytesToHash(config.BatchSenderAddress.Bytes()) batcherHash = common.BytesToHash(config.BatchSenderAddress.Bytes())
l2GenesisBlockGasLimit = uint64(config.L2GenesisBlockGasLimit) l2GenesisBlockGasLimit = uint64(config.L2GenesisBlockGasLimit)
startBlock = new(big.Int).SetUint64(config.SystemConfigStartBlock)
batchInboxAddress = config.BatchInboxAddress
p2pSequencerAddress = config.P2PSequencerAddress p2pSequencerAddress = config.P2PSequencerAddress
finalSystemOwner = config.FinalSystemOwner finalSystemOwner = config.FinalSystemOwner
} else { } else {
......
...@@ -33,8 +33,11 @@ func setupL2OutputOracle() (common.Address, *bind.TransactOpts, *backends.Simula ...@@ -33,8 +33,11 @@ func setupL2OutputOracle() (common.Address, *bind.TransactOpts, *backends.Simula
backend, backend,
big.NewInt(10), big.NewInt(10),
big.NewInt(2), big.NewInt(2),
big.NewInt(100), big.NewInt(0),
) big.NewInt(0),
from,
common.Address{0xdd},
big.NewInt(100))
if err != nil { if err != nil {
return common.Address{}, nil, nil, nil, err return common.Address{}, nil, nil, nil, err
} }
......
...@@ -32,6 +32,10 @@ contract SystemConfig is OwnableUpgradeable, ISemver { ...@@ -32,6 +32,10 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
/// Storing it at this deterministic storage slot allows for decoupling the storage /// Storing it at this deterministic storage slot allows for decoupling the storage
/// layout from the way that `solc` lays out storage. The `op-node` uses a storage /// layout from the way that `solc` lays out storage. The `op-node` uses a storage
/// proof to fetch this value. /// proof to fetch this value.
/// @dev NOTE: this value will be migrated to another storage slot in a future version.
/// User input should not be placed in storage in this contract until this migration
/// happens. It is unlikely that keccak second preimage resistance will be broken,
/// but it is better to be safe than sorry.
bytes32 public constant UNSAFE_BLOCK_SIGNER_SLOT = keccak256("systemconfig.unsafeblocksigner"); bytes32 public constant UNSAFE_BLOCK_SIGNER_SLOT = keccak256("systemconfig.unsafeblocksigner");
/// @notice Fixed L2 gas overhead. Used as part of the L2 fee calculation. /// @notice Fixed L2 gas overhead. Used as part of the L2 fee calculation.
...@@ -63,7 +67,9 @@ contract SystemConfig is OwnableUpgradeable, ISemver { ...@@ -63,7 +67,9 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
/// @custom:semver 1.11.0 /// @custom:semver 1.11.0
string public constant version = "1.11.0"; string public constant version = "1.11.0";
/// @notice Constructs the SystemConfig contract. /// @notice Constructs the SystemConfig contract. Cannot set
/// the owner to `address(0)` due to the Ownable contract's
/// implementation, so set it to `address(0xdEaD)`
/// @param _owner Initial owner of the contract. /// @param _owner Initial owner of the contract.
/// @param _overhead Initial overhead value. /// @param _overhead Initial overhead value.
/// @param _scalar Initial scalar value. /// @param _scalar Initial scalar value.
...@@ -114,10 +120,11 @@ contract SystemConfig is OwnableUpgradeable, ISemver { ...@@ -114,10 +120,11 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
{ {
__Ownable_init(); __Ownable_init();
transferOwnership(_owner); transferOwnership(_owner);
overhead = _overhead;
scalar = _scalar; // These are set in ascending order of their UpdateTypes.
batcherHash = _batcherHash; _setBatcherHash(_batcherHash);
gasLimit = _gasLimit; _setGasConfig({ _overhead: _overhead, _scalar: _scalar });
_setGasLimit(_gasLimit);
_setUnsafeBlockSigner(_unsafeBlockSigner); _setUnsafeBlockSigner(_unsafeBlockSigner);
_setResourceConfig(_config); _setResourceConfig(_config);
require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low"); require(_gasLimit >= minimumGasLimit(), "SystemConfig: gas limit too low");
...@@ -136,37 +143,53 @@ contract SystemConfig is OwnableUpgradeable, ISemver { ...@@ -136,37 +143,53 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
/// @notice High level getter for the unsafe block signer address. /// @notice High level getter for the unsafe block signer address.
/// Unsafe blocks can be propagated across the p2p network if they are signed by the /// Unsafe blocks can be propagated across the p2p network if they are signed by the
/// key corresponding to this address. /// key corresponding to this address.
/// @return unsafeBlockSigner_ Address of the unsafe block signer. /// @return addr_ Address of the unsafe block signer.
// solhint-disable-next-line ordering // solhint-disable-next-line ordering
function unsafeBlockSigner() external view returns (address unsafeBlockSigner_) { function unsafeBlockSigner() public view returns (address addr_) {
bytes32 slot = UNSAFE_BLOCK_SIGNER_SLOT; addr_ = Storage.getAddress(UNSAFE_BLOCK_SIGNER_SLOT);
assembly {
unsafeBlockSigner_ := sload(slot)
}
} }
/// @notice Updates the unsafe block signer address. /// @notice Updates the unsafe block signer address. Can only be called by the owner.
/// @param _unsafeBlockSigner New unsafe block signer address. /// @param _unsafeBlockSigner New unsafe block signer address.
function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner { function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner {
_setUnsafeBlockSigner(_unsafeBlockSigner); _setUnsafeBlockSigner(_unsafeBlockSigner);
}
/// @notice Updates the unsafe block signer address.
/// @param _unsafeBlockSigner New unsafe block signer address.
function _setUnsafeBlockSigner(address _unsafeBlockSigner) internal {
Storage.setAddress(UNSAFE_BLOCK_SIGNER_SLOT, _unsafeBlockSigner);
bytes memory data = abi.encode(_unsafeBlockSigner); bytes memory data = abi.encode(_unsafeBlockSigner);
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;
...@@ -174,9 +197,15 @@ contract SystemConfig is OwnableUpgradeable, ISemver { ...@@ -174,9 +197,15 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
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;
...@@ -184,17 +213,6 @@ contract SystemConfig is OwnableUpgradeable, ISemver { ...@@ -184,17 +213,6 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
emit ConfigUpdate(VERSION, UpdateType.GAS_LIMIT, data); emit ConfigUpdate(VERSION, UpdateType.GAS_LIMIT, data);
} }
/// @notice Low level setter for the unsafe block signer address.
/// This function exists to deduplicate code around storing the unsafeBlockSigner
/// address in storage.
/// @param _unsafeBlockSigner New unsafeBlockSigner value.
function _setUnsafeBlockSigner(address _unsafeBlockSigner) internal {
bytes32 slot = UNSAFE_BLOCK_SIGNER_SLOT;
assembly {
sstore(slot, _unsafeBlockSigner)
}
}
/// @notice A getter for the resource config. /// @notice A getter for the resource config.
/// Ensures that the struct is returned instead of a tuple. /// Ensures that the struct is returned instead of a tuple.
/// @return ResourceConfig /// @return ResourceConfig
......
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