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

Deactivate BlochainParameters Contract on L2 #11008

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "../common/Initializable.sol";
import "../common/UsingPrecompiles.sol";

import "../../contracts-0.8/common/IsL2Check.sol";

/**
* @title Contract for storing blockchain parameters that can be set by governance.
soloseng marked this conversation as resolved.
Show resolved Hide resolved
*/
contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles, IsL2Check {
using SafeMath for uint256;

// obsolete
Expand Down Expand Up @@ -92,7 +94,7 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
* @notice Sets the uptime lookback window.
* @param window New window.
*/
function setUptimeLookbackWindow(uint256 window) public onlyOwner {
function setUptimeLookbackWindow(uint256 window) public onlyL1 onlyOwner {
require(window >= 3 && window <= 720, "UptimeLookbackWindow must be within safe range");
require(
window <= getEpochSize().sub(2),
Expand All @@ -119,7 +121,7 @@ contract BlockchainParameters is Ownable, Initializable, UsingPrecompiles {
/**
* @notice Gets the uptime lookback window.
*/
function _getUptimeLookbackWindow() internal view returns (uint256 lookbackWindow) {
function _getUptimeLookbackWindow() internal view onlyL1 returns (uint256 lookbackWindow) {
if (getEpochNumber() >= uptimeLookbackWindow.nextValueActivationEpoch) {
return uptimeLookbackWindow.nextValue;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { Constants } from "@test-sol/constants.sol";
import { Utils } from "@test-sol/utils.sol";

contract BlockchainParametersTest is Test, Constants, Utils {
// using the mainnet epoch size would not allow to test an edge case
uint256 constant EPOCH_SIZE = 100;
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
uint256 constant gasLimit = 7000000;
uint256 constant gasForNonGoldCurrencies = 50000;
address nonOwner;
address constant proxyAdminAddress = 0x4200000000000000000000000000000000000018;

BlockchainParameters blockchainParameters;

Expand All @@ -26,6 +25,9 @@ contract BlockchainParametersTest is Test, Constants, Utils {
ph.setEpochSize(EPOCH_SIZE);
blockchainParameters = new BlockchainParameters(true);
}
function _whenL2() public {
deployCodeTo("Registry.sol", abi.encode(false), proxyAdminAddress);
}
}

contract BlockchainParametersTest_initialize is BlockchainParametersTest {
Expand Down Expand Up @@ -108,6 +110,12 @@ contract BlockchainParametersTest_getUptimeLookbackWindow is BlockchainParameter
vm.expectRevert("UptimeLookbackWindow is not initialized");
blockchainParameters.getUptimeLookbackWindow();
}

function test_Reverts_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
blockchainParameters.getUptimeLookbackWindow();
}
}

contract BlockchainParametersTest_setUptimeLookbackWindow is BlockchainParametersTest {
Expand Down Expand Up @@ -139,7 +147,7 @@ contract BlockchainParametersTest_setUptimeLookbackWindow is BlockchainParameter
blockchainParameters.setUptimeLookbackWindow(newValue);
}

function test_Revert_ShouldFail_WhenUsingValueLowerThanSafeMinimum() public {
function test_Revert_WhenUsingValueLowerThanSafeMinimum() public {
vm.expectRevert("UptimeLookbackWindow must be within safe range");
blockchainParameters.setUptimeLookbackWindow(2);
}
Expand All @@ -149,9 +157,9 @@ contract BlockchainParametersTest_setUptimeLookbackWindow is BlockchainParameter
blockchainParameters.setUptimeLookbackWindow(721);
}

function test_Revert_WhenUsingValueGreaterThanEpochsizeminus2() public {
vm.expectRevert("UptimeLookbackWindow must be smaller or equal to epochSize - 2");
// 720 is harcoded as maximum in the code
blockchainParameters.setUptimeLookbackWindow(EPOCH_SIZE - 1);
function test_Reverts_WhenCalledOnL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
blockchainParameters.setUptimeLookbackWindow(100);
}
}
Loading