github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/test/invariants/SystemConfig.t.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { Test } from "forge-std/Test.sol"; 5 import { SystemConfig } from "src/L1/SystemConfig.sol"; 6 import { Proxy } from "src/universal/Proxy.sol"; 7 import { Constants } from "src/libraries/Constants.sol"; 8 9 contract SystemConfig_GasLimitLowerBound_Invariant is Test { 10 SystemConfig public config; 11 12 function setUp() external { 13 Proxy proxy = new Proxy(msg.sender); 14 SystemConfig configImpl = new SystemConfig(); 15 16 vm.prank(msg.sender); 17 proxy.upgradeToAndCall( 18 address(configImpl), 19 abi.encodeCall( 20 configImpl.initialize, 21 ( 22 address(0xbeef), // owner 23 2100, // overhead 24 1000000, // scalar 25 bytes32(hex"abcd"), // batcher hash 26 30_000_000, // gas limit 27 address(1), // unsafe block signer 28 Constants.DEFAULT_RESOURCE_CONFIG(), 29 address(0), // _batchInbox 30 SystemConfig.Addresses({ // _addrs 31 l1CrossDomainMessenger: address(0), 32 l1ERC721Bridge: address(0), 33 l1StandardBridge: address(0), 34 l2OutputOracle: address(0), 35 optimismPortal: address(0), 36 optimismMintableERC20Factory: address(0) 37 }) 38 ) 39 ) 40 ); 41 42 config = SystemConfig(address(proxy)); 43 44 // Set the target contract to the `config` 45 targetContract(address(config)); 46 // Set the target sender to the `config`'s owner (0xbeef) 47 targetSender(address(0xbeef)); 48 // Set the target selector for `setGasLimit` 49 // `setGasLimit` is the only function we care about, as it is the only function 50 // that can modify the gas limit within the SystemConfig. 51 bytes4[] memory selectors = new bytes4[](1); 52 selectors[0] = config.setGasLimit.selector; 53 FuzzSelector memory selector = FuzzSelector({ addr: address(config), selectors: selectors }); 54 targetSelector(selector); 55 56 /// Allows the SystemConfig contract to be the target of the invariant test 57 /// when it is behind a proxy. Foundry calls this function under the hood to 58 /// know the ABI to use when calling the target contract. 59 string[] memory artifacts = new string[](1); 60 artifacts[0] = "SystemConfig"; 61 FuzzInterface memory target = FuzzInterface(address(config), artifacts); 62 targetInterface(target); 63 } 64 65 /// @custom:invariant The gas limit of the `SystemConfig` contract can never be lower 66 /// than the hard-coded lower bound. 67 function invariant_gasLimitLowerBound() external { 68 assertTrue(config.gasLimit() >= config.minimumGasLimit()); 69 } 70 }