Skip to content

contracts-bedrock: OptimismPortal reduce codesize #10117

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 36 commits into from
Apr 12, 2024

Conversation

tynes
Copy link
Contributor

@tynes tynes commented Apr 11, 2024

Description

Reduce the codesize of the OptimismPortal and the OptimismPortal2
by converting require statements into custom error reverts.
Also remove legacy getters, they only bloat codesize.

This will help to reduce the diff of when we go to production
with custom gas token as that feature put the contract over the
codesize limit.

@tynes tynes requested a review from a team as a code owner April 11, 2024 17:29
@tynes tynes requested a review from mds1 April 11, 2024 17:29
Copy link
Contributor

coderabbitai bot commented Apr 11, 2024

Walkthrough

The updates across various files in the contracts-bedrock package primarily focus on enhancing error handling by introducing a new PortalErrors library, modifying control flows with if statements instead of require, and updating semantic versions. Additionally, there are changes in gas handling, removal of legacy functions, and updates in test configurations and documentation to align with the new code structure.

Changes

Files Changes
.../L1/OptimismPortal.sol, .../L1/OptimismPortal2.sol Introduced PortalErrors library, updated error handling with if conditions, removed legacy getter functions, updated semantic version.
.../L1/ResourceMetering.sol, .../test/L1/ResourceMetering.t.sol Added handling for gas limit issues with new OutOfGas() error, replaced require with if and revert.
.../libraries/PortalErrors.sol New error definitions for various conditions and actions such as bad targets, large calldata, and unauthorized access.
.../test/L1/OptimismPortal.t.sol, .../test/Specs.t.sol, .../test/kontrol/deployment/DeploymentSummary.t.sol Updated import statements, reorganized checks, updated revert messages, removed specific function calls and assertions.
op-chain-ops/genesis/layer_one_test.go, op-chain-ops/upgrades/l1.go Adjusted method calls and removed instance creation related to OptimismPortal.
.../.gas-snapshot, .../invariant-docs/OptimismPortal.md, .../invariant-docs/OptimismPortal2.md Updated gas benchmarks and test references, clarified invariants related to deposit and withdrawal processes.
.../scripts/ChainAssertions.sol Simplified address comparisons and removed specific require statements for cleaner logic.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tynes tynes marked this pull request as draft April 11, 2024 17:29
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Actionable comments outside the diff hunks (1)
packages/contracts-bedrock/test/L1/OptimismPortal.t.sol (1)

Line range hint 518-518: Correct the usage of blockhash function to avoid always getting zero.

- blockhash(block.number)
+ blockhash(block.number - 1) // Use the hash of the most recent block

Copy link

codecov bot commented Apr 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 29.22%. Comparing base (4aa875f) to head (203f554).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #10117       +/-   ##
============================================
- Coverage    42.40%   29.22%   -13.18%     
============================================
  Files           73       31       -42     
  Lines         4830     2898     -1932     
  Branches       766      614      -152     
============================================
- Hits          2048      847     -1201     
+ Misses        2676     1976      -700     
+ Partials       106       75       -31     
Flag Coverage Δ
cannon-go-tests ?
chain-mon-tests 27.14% <ø> (ø)
common-ts-tests ?
contracts-ts-tests 12.25% <ø> (ø)
core-utils-tests ?
sdk-tests 40.27% <ø> (ø)

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

see 42 files with indirect coverage changes

Copy link
Member

@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.

Direction is looking good; Flipped conditionals look good to me. Couple nits.

@tynes tynes marked this pull request as ready for review April 11, 2024 21:13
@tynes tynes requested a review from a team as a code owner April 11, 2024 21:21
@tynes tynes requested a review from ajsutton April 11, 2024 21:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

@smartcontracts smartcontracts added the M-do-not-merge Meta: Do not merge label Apr 11, 2024
@smartcontracts
Copy link
Contributor

Marking as do-not-merge for now while we discuss

Copy link
Member

@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.

LGTM, re-reviewed the checks on commit e1f1715. Approving pending discussion offline.

image

This should probably be a major semver bump due to the ABI-breaking changes with removing the legacy getters, but we do have a major bump queued up in the OptimismPortal2. Do we see this being deployed soon, and are we okay with violating proper semver here?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

tynes added 11 commits April 11, 2024 20:54
Reduce the codesize of the OptimismPortal and the OptimismPortal2
by converting `require` statements into custom error reverts.
Also remove legacy getters, they only bloat codesize.

This will help to reduce the diff of when we go to production
with custom gas token as that feature put the contract over the
codesize limit.
@tynes tynes force-pushed the feat/portal-reduce-codesize branch from 69114f8 to ac535d2 Compare April 12, 2024 03:05
Copy link
Contributor

@mds1 mds1 left a comment

Choose a reason for hiding this comment

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

Just noting that general approach lgtm, but I did not review all changes super closely

Copy link
Contributor

@smartcontracts smartcontracts left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for simplifying

@smartcontracts smartcontracts removed the M-do-not-merge Meta: Do not merge label Apr 12, 2024
@tynes
Copy link
Contributor Author

tynes commented Apr 12, 2024

Still having issues with deployment summary

@tynes tynes enabled auto-merge April 12, 2024 15:59
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.

The Go part of the changes looks good. One nit about a test-call that can be replaced rather than removed.

@tynes tynes added this pull request to the merge queue Apr 12, 2024
Merged via the queue into develop with commit 3ae85c9 Apr 12, 2024
@tynes tynes deleted the feat/portal-reduce-codesize branch April 12, 2024 17:14
pcw109550 pushed a commit to testinprod-io/optimism that referenced this pull request Apr 15, 2024
…10117)

* contracts-bedrock: OptimismPortal reduce codesize

Reduce the codesize of the OptimismPortal and the OptimismPortal2
by converting `require` statements into custom error reverts.
Also remove legacy getters, they only bloat codesize.

This will help to reduce the diff of when we go to production
with custom gas token as that feature put the contract over the
codesize limit.

* contracts-bedrock: cleanup errors

* contracts-bedrock: more custom errors

* contracts-bedrock: updates to portal

* contracts-bedrock: error comments

* contracts-bedrock: more custom errors

* portal: fixup style

* spec: update

* op-bindings: regenerate

* contracts-bedrock: update abi snapshots

* snapshots: kontrol deploy

* lint: fix

* op-chain-ops: cleanup tests

* contracts-bedrock: fix invariant tests

* contracts-bedrock: correct assertion

Co-authored-by: clabby <[email protected]>

* op-bindings: regenerate

* contracts-bedrock: cleanup style

* contracts-bedrock: update locks

* ctb: update test

* snapshots: update

* contracts-bedrock: simplify require

* contracts-bedrock: require

* contracts-bedrock: reduce diff

* bindings: regenerate

* snapshots: update

* contracts-bedrock: small update

* contracts-bedrock: more cleanup

* contracts-bedrock: update snapshots

* semver-lock: update

* lint: fix

* contracts-bedrock: fix tests

* contracts-bedrock: fix test

* kontrol: update

* contracts-bedrock: delete dead errors

* temp: fixes for kontrol

* invariant-docs: regenerate

---------

Co-authored-by: clabby <[email protected]>
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.

7 participants