Skip to content

contracts-bedrock: prevent too low of gas config#5112

Closed
tynes wants to merge 17 commits intodevelopfrom
fix/syscfg-prevent-low-gaslimit
Closed

contracts-bedrock: prevent too low of gas config#5112
tynes wants to merge 17 commits intodevelopfrom
fix/syscfg-prevent-low-gaslimit

Conversation

@tynes
Copy link
Contributor

@tynes tynes commented Mar 11, 2023

Description

The chain liveliness depends on the L2 gas limit being larger than the gas consumed by a deposit. If a deposit consumes more gas than what is possible in an L2 block, then the chain will halt and be unable to produce blocks.

This was previously handled by having a hardcoded constant in the system config contract. This constant must be kept in sync with the value in the optimism portal. It is also possible to deploy a new optimism portal such that it has a different resource limit. To remove the need to always having to keep these values in sync, a handle to the portal is given to the system config contract. The system config contract will call the portal to get the value dynamically.

This ensures that we do not need to remember what the value is and update the contracts in tandem.

@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2023

⚠️ No Changeset found

Latest commit: 640664b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tynes
Copy link
Contributor Author

tynes commented Mar 11, 2023

If we opt into this solution, then I will need to modify the L1 deploy process such that the correct optimism portal contract exists at the correct location before the deployment of the system config contract. Will require a refactor of how the L1 deployment works so that contracts are deployed + initialized + moved to the account one at a time, in dependency order.

@netlify
Copy link

netlify bot commented Mar 14, 2023

Deploy Preview for opstack-docs ready!

Name Link
🔨 Latest commit 640664b
🔍 Latest deploy log https://app.netlify.com/sites/opstack-docs/deploys/6419109c47ee250008b097ac
😎 Deploy Preview https://deploy-preview-5112--opstack-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@tynes tynes force-pushed the fix/syscfg-prevent-low-gaslimit branch from 2af93fc to 80a8f2a Compare March 14, 2023 23:10
@tynes tynes marked this pull request as ready for review March 14, 2023 23:25
@tynes tynes requested review from a team as code owners March 14, 2023 23:25
@tynes tynes requested review from maurelian and mslipper March 14, 2023 23:25
@semgrep-app
Copy link
Contributor

semgrep-app bot commented Mar 15, 2023

Semgrep found 1 unchecked-type-assertion finding:

  • op-bindings/bindings/systemconfig.go: L463

Unchecked type assertion.

Created by unchecked-type-assertion.

Copy link
Contributor

@protolambda protolambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a few comments about future contract dependency / checks. The PR description makes sense, but I'm not sure if future additional configurable values change this.

@tynes tynes force-pushed the fix/syscfg-prevent-low-gaslimit branch from 80a8f2a to 8f47ddd Compare March 15, 2023 18:14
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #5112 (640664b) into develop (7d0c54c) will decrease coverage by 0.55%.
The diff coverage is 74.07%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5112      +/-   ##
===========================================
- Coverage    41.59%   41.05%   -0.55%     
===========================================
  Files          358      337      -21     
  Lines        22385    21769     -616     
  Branches       776      660     -116     
===========================================
- Hits          9312     8937     -375     
+ Misses       12366    12123     -243     
- Partials       707      709       +2     
Flag Coverage Δ
bedrock-go-tests 37.66% <75.00%> (-0.01%) ⬇️
contracts-bedrock-tests 51.35% <66.66%> (+0.18%) ⬆️
contracts-tests 98.86% <ø> (ø)
core-utils-tests ?
dtl-tests 47.15% <ø> (ø)
fault-detector-tests 33.88% <ø> (ø)
sdk-tests 39.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
op-chain-ops/genesis/config.go 30.58% <0.00%> (-0.29%) ⬇️
...es/contracts-bedrock/contracts/L1/SystemConfig.sol 71.42% <66.66%> (+4.76%) ⬆️
op-chain-ops/genesis/layer_one.go 75.13% <85.71%> (-0.21%) ⬇️

... and 22 files with indirect coverage changes

@tynes
Copy link
Contributor Author

tynes commented Mar 16, 2023

I've move the min gas check outside of the constructor and added a comment that it should happen offchain. I added a check to the deployment code. It would require a large refactor of how we do deployments/initializations to be able to allow a contract to make a call in the constructor.

@mergify
Copy link
Contributor

mergify bot commented Mar 17, 2023

Hey @tynes! This PR has merge conflicts. Please fix them before continuing review.

@mergify mergify bot added the conflict label Mar 17, 2023
@tynes tynes force-pushed the fix/syscfg-prevent-low-gaslimit branch from 39c384f to 86eb055 Compare March 17, 2023 22:14
@mergify mergify bot removed the conflict label Mar 17, 2023
tynes added a commit that referenced this pull request Mar 18, 2023
Ensures that things are smooth once #5112
is merged. A too small of gas limit will break things after
that PR is merged. We will run with 30 million limit on mainnet,
so we should ensure that our devnet config reflects that.
Copy link
Contributor

@maurelian maurelian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks solid, just looking for some small tweaks to comments then will approve.

Comment on lines +222 to +225
* @notice Returns the minimum gas limit allowed by the system. If the L2
* gas limit is set to a value smaller than this, then it is
* possible for a block to be produced that uses more gas than what
* is allowed on L2, resulting in a liveness failure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that what would happen, or would deposit blocks be rejected or invalid? I honestly don't know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to @trianglesphere it would cause the chain to halt. I don't believe we have test coverage of this case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How difficult would it be to add a test for this case in op-e2e? Is this something we could do prior to mainnet launch, or okay to put in the backlog in your opinion?

tynes added 5 commits March 20, 2023 19:04
The chain liveliness depends on the L2 gas limit being larger
than the gas consumed by a deposit. If a deposit consumes more
gas than what is possible in an L2 block, then the chain will
halt and be unable to produce blocks.

This was previously handled by having a hardcoded constant in
the system config contract. This constant must be kept in sync
with the value in the optimism portal. It is also possible to
deploy a new optimism portal such that it has a different resource
limit. To remove the need to always having to keep these values in
sync, a handle to the portal is given to the system config contract.
The system config contract will call the portal to get the value
dynamically.

This ensures that we do not need to remember what the value is
and update the contracts in tandem.
@tynes tynes force-pushed the fix/syscfg-prevent-low-gaslimit branch from 7d62d4e to 640664b Compare March 21, 2023 02:04
* gas the system transaction can consume in a block.
*/
function minimumGasLimit() public view returns (uint256) {
uint256 maxResourceLimit = uint256(ResourceMetering(PORTAL).MAX_RESOURCE_LIMIT());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this relationship pretty ugly. If anything, ResourceMetering should be pulling the max resource limit from SystemConfig rather than the other way around. That way you don't need a minimum gas limit like this. You just derive the maximum available deposit gas from the maximum resource gas as defined in this contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considered this design but decided against it balancing amount of diff

Copy link
Contributor

@clabby clabby Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also seems like a cleaner layout to me, but this feels like a change that should be done after we ship Bedrock (along with broader SystemConfig enhancements, like adding in immutables for all of the protocol's proxies etc. similar to curve's AddressProvider)

Copy link
Contributor

@clabby clabby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@mergify
Copy link
Contributor

mergify bot commented Mar 24, 2023

Hey @tynes! This PR has merge conflicts. Please fix them before continuing review.

@mergify mergify bot added the conflict label Mar 24, 2023
@tynes tynes closed this Mar 24, 2023
@tynes tynes deleted the fix/syscfg-prevent-low-gaslimit branch March 24, 2023 15:32
@mergify mergify bot removed the conflict label Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants