Commit a4501d37 authored by Maurelian's avatar Maurelian Committed by GitHub

contracts-bedrock: Do not reset resource params when reinitializing (#8639)

The resource params should only be set when the Portal is freshly initialized.

A test was added which verifies that the params are not modified when reinitializing.
parent f8493acf
This diff is collapsed.
This diff is collapsed.
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
"sourceCodeHash": "0xb99ee58a672ed59f6bf529a618d4949f198bfda7c65664c9b2a2657070756c69" "sourceCodeHash": "0xb99ee58a672ed59f6bf529a618d4949f198bfda7c65664c9b2a2657070756c69"
}, },
"src/L1/OptimismPortal.sol": { "src/L1/OptimismPortal.sol": {
"initCodeHash": "0xd4e41857cb584fcb374f3636f9ea365c20972948d4c922b5388f416f4c9e8ef2", "initCodeHash": "0x627cdc470d54cd6eac977d9ec4ca463c96e8bd715582c4d1394ff2cd824c804f",
"sourceCodeHash": "0xadece71739b0a6b5427cbae5b53a2c7f7d4b5f978c028dbce2f536b1229f37f8" "sourceCodeHash": "0x2e738b965d2fab07f0af660a017071b1f23e0fe0d1ee543ed99da2687b7fd6b0"
}, },
"src/L1/ProtocolVersions.sol": { "src/L1/ProtocolVersions.sol": {
"initCodeHash": "0x72cd467e8bcf019c02675d72ab762e088bcc9cc0f1a4e9f587fa4589f7fdd1b8", "initCodeHash": "0x72cd467e8bcf019c02675d72ab762e088bcc9cc0f1a4e9f587fa4589f7fdd1b8",
......
...@@ -93,8 +93,8 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver { ...@@ -93,8 +93,8 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
} }
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 2.2.0 /// @custom:semver 2.3.0
string public constant version = "2.2.0"; string public constant version = "2.3.0";
/// @notice Constructs the OptimismPortal contract. /// @notice Constructs the OptimismPortal contract.
/// @param _l2Oracle Address of the L2OutputOracle contract. /// @param _l2Oracle Address of the L2OutputOracle contract.
......
...@@ -155,6 +155,8 @@ abstract contract ResourceMetering is Initializable { ...@@ -155,6 +155,8 @@ abstract contract ResourceMetering is Initializable {
/// child contract. /// child contract.
// solhint-disable-next-line func-name-mixedcase // solhint-disable-next-line func-name-mixedcase
function __ResourceMetering_init() internal onlyInitializing { function __ResourceMetering_init() internal onlyInitializing {
if (params.prevBlockNum == 0) {
params = ResourceParams({ prevBaseFee: 1 gwei, prevBoughtGas: 0, prevBlockNum: uint64(block.number) }); params = ResourceParams({ prevBaseFee: 1 gwei, prevBoughtGas: 0, prevBlockNum: uint64(block.number) });
} }
}
} }
...@@ -71,6 +71,20 @@ contract ResourceMetering_Test is Test { ...@@ -71,6 +71,20 @@ contract ResourceMetering_Test is Test {
assertEq(prevBlockNum, initialBlockNum); assertEq(prevBlockNum, initialBlockNum);
} }
/// @dev Tests that reinitializing the resource params are set correctly.
function test_meter_reinitializedResourceParams_succeeds() external {
(uint128 prevBaseFee, uint64 prevBoughtGas, uint64 prevBlockNum) = meter.params();
// Reset the initialized slot to enable reinitialization.
vm.store(address(meter), bytes32(uint256(0)), bytes32(uint256(0)));
meter.initialize();
(uint128 postBaseFee, uint64 postBoughtGas, uint64 postBlockNum) = meter.params();
assertEq(prevBaseFee, postBaseFee);
assertEq(prevBoughtGas, postBoughtGas);
assertEq(prevBlockNum, postBlockNum);
}
/// @dev Tests that updating the resource params to the same values works correctly. /// @dev Tests that updating the resource params to the same values works correctly.
function test_meter_updateParamsNoChange_succeeds() external { function test_meter_updateParamsNoChange_succeeds() external {
meter.use(0); // equivalent to just updating the base fee and block number meter.use(0); // equivalent to just updating the base fee and block number
......
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