-
Notifications
You must be signed in to change notification settings - Fork 236
feat(L1): make deposit resource minimum base fee deploy-configurable #401
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.15; | ||
|
|
||
| import { Test } from "lib/forge-std/src/Test.sol"; | ||
|
|
||
| import { DeployConfig } from "scripts/deploy/DeployConfig.s.sol"; | ||
|
|
||
| /// @title DeployConfig_ResourceConfigMinimumBaseFee_Test | ||
| /// @notice Covers DeployConfig JSON parsing for the optional resource minimum base fee. | ||
| contract DeployConfig_ResourceConfigMinimumBaseFee_Test is Test { | ||
| DeployConfig internal config; | ||
| string internal localConfigPath; | ||
| string internal overrideConfigPath; | ||
|
|
||
| function setUp() public { | ||
| config = new DeployConfig(); | ||
| localConfigPath = string.concat(vm.projectRoot(), "/deploy-config/local.json"); | ||
| overrideConfigPath = | ||
| string.concat(vm.projectRoot(), "/deployments/deploy-config-resource-minimum-override.json"); | ||
| vm.createDir(string.concat(vm.projectRoot(), "/deployments"), true); | ||
| } | ||
|
|
||
| function test_read_resourceConfigMinimumBaseFee_default_succeeds() public { | ||
| config.read(localConfigPath); | ||
| assertEq(config.resourceConfigMinimumBaseFee(), uint32(1 gwei)); | ||
| } | ||
|
|
||
| function test_read_resourceConfigMinimumBaseFee_override_succeeds() public { | ||
| string memory json = _withResourceConfigMinimumBaseFee(vm.readFile(localConfigPath), 10_000_000); | ||
| vm.writeFile(overrideConfigPath, json); | ||
|
|
||
| config.read(overrideConfigPath); | ||
| assertEq(config.resourceConfigMinimumBaseFee(), 10_000_000); | ||
|
|
||
| vm.removeFile(overrideConfigPath); | ||
| } | ||
|
|
||
| function _withResourceConfigMinimumBaseFee( | ||
| string memory _json, | ||
| uint256 _value | ||
| ) | ||
| internal | ||
| pure | ||
| returns (string memory json_) | ||
| { | ||
| require(_value == 10_000_000, "DeployConfig test: unsupported fixture value"); | ||
|
|
||
| bytes memory jsonBytes = bytes(_json); | ||
| uint256 end = jsonBytes.length; | ||
| while (end > 0 && (jsonBytes[end - 1] == "\n" || jsonBytes[end - 1] == "\r" || jsonBytes[end - 1] == " ")) { | ||
| end--; | ||
| } | ||
| require(end > 0 && jsonBytes[end - 1] == "}", "DeployConfig test: expected object"); | ||
|
|
||
| bytes memory suffix = bytes(',\n "resourceConfigMinimumBaseFee": 10000000\n}'); | ||
| json_ = new string(end - 1 + suffix.length); | ||
|
|
||
| bytes memory result = bytes(json_); | ||
| for (uint256 i; i < end - 1; ++i) { | ||
| result[i] = jsonBytes[i]; | ||
| } | ||
| for (uint256 i; i < suffix.length; ++i) { | ||
| result[end - 1 + i] = suffix[i]; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.15; | ||
|
|
||
| import { Test } from "lib/forge-std/src/Test.sol"; | ||
|
|
||
| import { SystemDeploy } from "scripts/deploy/SystemDeploy.s.sol"; | ||
| import { Types } from "scripts/libraries/Types.sol"; | ||
| import { Constants } from "src/libraries/Constants.sol"; | ||
| import { Hash, Proposal } from "src/libraries/bridge/Types.sol"; | ||
|
|
||
| import { IL1StandardBridge } from "interfaces/L1/IL1StandardBridge.sol"; | ||
| import { IOptimismPortal2 } from "interfaces/L1/IOptimismPortal2.sol"; | ||
| import { IResourceMetering } from "interfaces/L1/IResourceMetering.sol"; | ||
| import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol"; | ||
| import { ISP1Verifier } from "interfaces/L1/proofs/zk/ISP1Verifier.sol"; | ||
|
|
||
| /// @title ResourceConfigMinimumBaseFee_Test | ||
| /// @notice Tests deploy-time configuration of the deposit resource minimum base fee. | ||
| contract ResourceConfigMinimumBaseFee_Test is Test { | ||
| SystemDeploy internal systemDeploy; | ||
|
|
||
| address internal owner = address(this); | ||
| address internal guardian = makeAddr("guardian"); | ||
| address internal incidentResponder = makeAddr("incidentResponder"); | ||
| address internal batcher = makeAddr("batcher"); | ||
| address internal unsafeBlockSigner = makeAddr("unsafeBlockSigner"); | ||
| address internal proposer = makeAddr("proposer"); | ||
| address internal challenger = makeAddr("challenger"); | ||
|
|
||
| uint256 internal l2ChainId = 901; | ||
| uint32 internal constant L3_MINIMUM_BASE_FEE = 10_000_000; | ||
| /// @dev The Fusaka EIP-7825 transaction gas cap. Chains may not enable it and future forks may change it. | ||
| uint256 internal constant BASE_TX_GAS_CAP = 16_777_216; | ||
|
|
||
| function setUp() public { | ||
| systemDeploy = new SystemDeploy(); | ||
| } | ||
|
|
||
| function test_deploy_defaultResourceConfigMinimumBaseFee_succeeds() public { | ||
| SystemDeploy.DeployOutput memory output = systemDeploy.deploy(_deployInput(uint32(1 gwei))); | ||
|
|
||
| IResourceMetering.ResourceConfig memory config = output.opChain.systemConfigProxy.resourceConfig(); | ||
| assertEq(config.minimumBaseFee, uint32(1 gwei)); | ||
| assertEq(config.maximumBaseFee, Constants.DEFAULT_RESOURCE_CONFIG().maximumBaseFee); | ||
|
|
||
| (uint128 prevBaseFee,,) = IOptimismPortal2(payable(address(output.opChain.optimismPortalProxy))).params(); | ||
| assertEq(prevBaseFee, config.minimumBaseFee); | ||
| } | ||
|
|
||
| function test_deploy_overriddenResourceConfigMinimumBaseFee_succeeds() public { | ||
| SystemDeploy.DeployOutput memory output = systemDeploy.deploy(_deployInput(L3_MINIMUM_BASE_FEE)); | ||
|
|
||
| IResourceMetering.ResourceConfig memory config = output.opChain.systemConfigProxy.resourceConfig(); | ||
| assertEq(config.minimumBaseFee, L3_MINIMUM_BASE_FEE); | ||
| assertEq(config.maximumBaseFee, Constants.DEFAULT_RESOURCE_CONFIG().maximumBaseFee); | ||
|
|
||
| (uint128 prevBaseFee,,) = IOptimismPortal2(payable(address(output.opChain.optimismPortalProxy))).params(); | ||
| assertEq(prevBaseFee, L3_MINIMUM_BASE_FEE); | ||
| } | ||
|
|
||
| function test_depositETH_lowParentBaseFee_belowTxGasCap_succeeds() public { | ||
| SystemDeploy.DeployOutput memory output = systemDeploy.deploy(_deployInput(L3_MINIMUM_BASE_FEE)); | ||
|
|
||
| ISystemConfig systemConfig = output.opChain.systemConfigProxy; | ||
| IOptimismPortal2 optimismPortal = IOptimismPortal2(payable(address(output.opChain.optimismPortalProxy))); | ||
| IL1StandardBridge l1StandardBridge = IL1StandardBridge(payable(systemConfig.l1StandardBridge())); | ||
|
|
||
| vm.fee(L3_MINIMUM_BASE_FEE); | ||
|
|
||
| uint256 gasUsed = _depositETHAndMeasureGas(l1StandardBridge); | ||
| assertLt(gasUsed, BASE_TX_GAS_CAP); | ||
|
|
||
| (uint128 prevBaseFee, uint64 prevBoughtGas,) = optimismPortal.params(); | ||
| assertEq(prevBaseFee, L3_MINIMUM_BASE_FEE); | ||
| assertGt(prevBoughtGas, 0); | ||
| } | ||
|
|
||
| function test_depositETH_defaultMinimum_lowParentBaseFee_exceedsFusakaTxGasCap_succeeds() public { | ||
| SystemDeploy.DeployOutput memory output = systemDeploy.deploy(_deployInput(uint32(1 gwei))); | ||
| IL1StandardBridge l1StandardBridge = | ||
| IL1StandardBridge(payable(output.opChain.systemConfigProxy.l1StandardBridge())); | ||
|
|
||
| vm.fee(L3_MINIMUM_BASE_FEE); | ||
|
|
||
| uint256 gasUsed = _depositETHAndMeasureGas(l1StandardBridge); | ||
| assertGe(gasUsed, BASE_TX_GAS_CAP); | ||
| } | ||
|
|
||
| function _depositETHAndMeasureGas(IL1StandardBridge _l1StandardBridge) internal returns (uint256 gasUsed_) { | ||
| uint256 depositorKey = 0xBEEF; | ||
| address depositor = vm.addr(depositorKey); | ||
| vm.deal(depositor, 10 ether); | ||
|
|
||
| vm.startBroadcast(depositorKey); | ||
| uint256 gasBefore = gasleft(); | ||
| _l1StandardBridge.depositETH{ value: 1 ether }(200_000, hex""); | ||
| gasUsed_ = gasBefore - gasleft(); | ||
| vm.stopBroadcast(); | ||
| } | ||
|
|
||
| function _deployInput(uint32 _resourceConfigMinimumBaseFee) | ||
| internal | ||
| view | ||
| returns (SystemDeploy.DeployInput memory input_) | ||
| { | ||
| input_.saveArtifacts = false; | ||
| input_.superchainInput = SystemDeploy.SuperchainInput({ | ||
| guardian: guardian, incidentResponder: incidentResponder, superchainProxyAdminOwner: owner | ||
| }); | ||
| input_.implementationsInput = SystemDeploy.ImplementationInput({ | ||
| withdrawalDelaySeconds: 100, | ||
| proofMaturityDelaySeconds: 400, | ||
| disputeGameFinalityDelaySeconds: 500, | ||
| teeImageHash: bytes32(uint256(1)), | ||
| zkRangeHash: bytes32(uint256(2)), | ||
| zkAggregationHash: bytes32(uint256(3)), | ||
| multiproofConfigHash: bytes32(uint256(4)), | ||
| multiproofGameType: 621, | ||
| nitroEnclaveVerifier: address(0), | ||
| multiproofBlockInterval: 100, | ||
| multiproofIntermediateBlockInterval: 10, | ||
| multiproofMaxUpgradeId: 12, | ||
| sp1Verifier: ISP1Verifier(address(0)), | ||
| teeProposer: proposer, | ||
| teeChallenger: challenger, | ||
| devTeeSigner: address(0), | ||
| guardian: guardian, | ||
| incidentResponder: incidentResponder, | ||
| slowFinalizationDelay: 5 days, | ||
| fastFinalizationDelay: 1 days | ||
| }); | ||
| input_.opChainInput = Types.DeployInput({ | ||
| roles: Types.Roles({ | ||
| opChainProxyAdminOwner: owner, | ||
| systemConfigOwner: owner, | ||
| batcher: batcher, | ||
| unsafeBlockSigner: unsafeBlockSigner, | ||
| incidentResponder: incidentResponder | ||
| }), | ||
| basefeeScalar: 100, | ||
| blobBasefeeScalar: 200, | ||
| l2ChainId: l2ChainId, | ||
| startingAnchorRoot: Proposal({ root: Hash.wrap(bytes32(uint256(1))), l2SequenceNumber: 0 }), | ||
| saltMixer: "resource-config-minimum-base-fee-test", | ||
| gasLimit: 60_000_000, | ||
| resourceConfigMinimumBaseFee: _resourceConfigMinimumBaseFee | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we reference Fusaka here in a doc comment? some chains don't implement the newer tx gas limit, and a future hard fork alters this value