Commit 402b6caf authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: fixup

parent 2f284658
This diff is collapsed.
......@@ -239,14 +239,14 @@ contract SystemConfig is OwnableUpgradeable, Semver {
}
/**
* @notice
* @notice A getter for the resource config.
*/
function resourceConfig() external view returns (ResourceConfig memory) {
return _resourceConfig;
}
/**
* @notice
* @notice An external setter for the resource config.
*/
function setResourceConfig(ResourceConfig memory _config) external onlyOwner {
_setResourceConfig(_config);
......@@ -256,20 +256,31 @@ contract SystemConfig is OwnableUpgradeable, Semver {
}
/**
* @notice
* @notice An internal setter for the resource config. Ensures that the
* config is sane before storing it.
*/
function _setResourceConfig(ResourceConfig memory _config) internal {
require(_config.minimumBaseFee <= _config.maximumBaseFee);
require(_config.baseFeeMaxChangeDenominator > 0);
require(_config.maxResourceLimit + _config.systemTxMaxGas <= gasLimit);
require(
_config.minimumBaseFee <= _config.maximumBaseFee,
"SystemConfig: min base fee must be less than max base"
);
require(
_config.baseFeeMaxChangeDenominator > 0,
"SystemConfig: denominator cannot be 0"
);
require(
_config.maxResourceLimit + _config.systemTxMaxGas <= gasLimit,
"SystemConfig: gas limit too low"
);
_resourceConfig = _config;
}
/**
* @notice
* @notice Returns the minimum L2 gas limit that can be safely set for the system to
* operate.
*/
function minimumGasLimit() public view returns (uint256) {
return _resourceConfig.maxResourceLimit + _resourceConfig.systemTxMaxGas;
function minimumGasLimit() public view returns (uint64) {
return uint64(_resourceConfig.maxResourceLimit) + uint64(_resourceConfig.systemTxMaxGas);
}
}
......@@ -11,7 +11,7 @@ contract EchidnaFuzzOptimismPortal {
constructor() {
SystemConfig config = new SystemConfig({
_owner: address(0),
_owner: address(1),
_overhead: 0,
_scalar: 10000,
_batcherHash: bytes32(0),
......
......@@ -172,7 +172,7 @@ contract Portal_Initializer is L2OutputOracle_Initializer {
super.setUp();
systemConfig = new SystemConfig({
_owner: address(0),
_owner: address(1),
_overhead: 0,
_scalar: 10000,
_batcherHash: bytes32(0),
......
......@@ -14,24 +14,23 @@ contract SystemConfig_Init is CommonTest {
_overhead: 2100,
_scalar: 1000000,
_batcherHash: bytes32(hex"abcd"),
_gasLimit: 9_000_000,
_gasLimit: 30_000_000,
_unsafeBlockSigner: address(1)
});
}
}
contract SystemConfig_Initialize_TestFail is CommonTest {
contract SystemConfig_Initialize_TestFail is SystemConfig_Init {
function test_initialize_lowGasLimit_reverts() external {
vm.expectRevert("SystemConfig: gas limit too low");
uint64 minimumGasLimit = sysConf.minimumGasLimit();
// The minimum gas limit defined in SystemConfig:
uint64 MINIMUM_GAS_LIMIT = 8_000_000;
vm.expectRevert("SystemConfig: gas limit too low");
new SystemConfig({
_owner: alice,
_overhead: 0,
_scalar: 0,
_batcherHash: bytes32(hex""),
_gasLimit: MINIMUM_GAS_LIMIT - 1,
_gasLimit: minimumGasLimit - 1,
_unsafeBlockSigner: address(1)
});
}
......@@ -57,6 +56,63 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
vm.expectRevert("Ownable: caller is not the owner");
sysConf.setUnsafeBlockSigner(address(0x20));
}
function test_setResourceConfig_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
minimumBaseFee: 1 gwei,
systemTxMaxGas: 1_000_000,
maximumBaseFee: type(uint128).max
});
sysConf.setResourceConfig(config);
}
function test_setResourceConfig_badMinMax_reverts() external {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
systemTxMaxGas: 1_000_000,
minimumBaseFee: 2 gwei,
maximumBaseFee: 1 gwei
});
vm.prank(sysConf.owner());
vm.expectRevert("SystemConfig: min base fee must be less than max base");
sysConf.setResourceConfig(config);
}
function test_setResourceConfig_zeroDenominator_reverts() external {
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 0,
systemTxMaxGas: 1_000_000,
minimumBaseFee: 1 gwei,
maximumBaseFee: 2 gwei
});
vm.prank(sysConf.owner());
vm.expectRevert("SystemConfig: denominator cannot be 0");
sysConf.setResourceConfig(config);
}
function test_setResourceConfig_lowGasLimit_reverts() external {
uint64 gasLimit = sysConf.gasLimit();
SystemConfig.ResourceConfig memory config = SystemConfig.ResourceConfig({
maxResourceLimit: uint32(gasLimit),
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
systemTxMaxGas: uint32(gasLimit),
minimumBaseFee: 1 gwei,
maximumBaseFee: 2 gwei
});
vm.prank(sysConf.owner());
vm.expectRevert("SystemConfig: gas limit too low");
sysConf.setResourceConfig(config);
}
}
contract SystemConfig_Setters_Test is SystemConfig_Init {
......
......@@ -12,7 +12,7 @@ contract SystemConfig_GasLimitLowerBound_Invariant is Test {
_overhead: 2100,
_scalar: 1000000,
_batcherHash: bytes32(hex"abcd"),
_gasLimit: 8_000_000,
_gasLimit: 30_000_000,
_unsafeBlockSigner: address(1)
});
......
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