optimism
optimism copied to clipboard
Create a new Errors.sol for reused across codebase
Description
Adds a new Errors.sol library intended to be used for common error cases. Currently the only error is authorization.
I've also updated a few contracts which are already using custom errors.
Summary by CodeRabbit
- New Features
- Introduced a new error type
BadAuthacross various contracts for more precise error handling regarding authorization failures.
- Introduced a new error type
- Refactor
- Updated ABI fields, error handling, and bytecode for improved contract metadata and interaction.
- Replaced the
Unauthorizederror withBadAuthin multiple contracts, enhancing clarity in error messaging.
- Documentation
- Adjusted error names and parameters in ABI files for better alignment with the updated error handling approach.
Walkthrough
The overarching change focuses on enhancing error handling across various contracts by introducing a common BadAuth error, replacing the previous Unauthorized error. This update streamlines authorization failure responses and integrates a new Errors.sol library across multiple components. Additionally, adjustments in ABI fields, bytecode, and error structuring improve clarity and contract interaction efficiency.
Changes
| Files | Summary |
|---|---|
op-bindings/bindings/delayedvetoable.go, op-bindings/bindings/delayedvetoable_more.go |
Updated ABI field and bytecode, including a new BadAuth error. |
packages/contracts-bedrock/.../abi/DelayedVetoable.json, packages/contracts-bedrock/.../abi/LivenessGuard.json, packages/contracts-bedrock/.../abi/PermissionedDisputeGame.json |
Renamed Unauthorized to BadAuth, adjusted error parameters, and restructured error ordering. |
packages/contracts-bedrock/src/L1/DelayedVetoable.sol, packages/contracts-bedrock/src/Safe/LivenessGuard.sol, packages/contracts-bedrock/src/dispute/PermissionedDisputeGame.sol |
Integrated Errors.sol, replaced Unauthorized with BadAuth, and updated error handling logic. |
packages/contracts-bedrock/src/libraries/DisputeErrors.sol |
Removed BadAuth() error declaration. |
packages/contracts-bedrock/src/libraries/Errors.sol |
Introduced for common error handling functionality. |
packages/contracts-bedrock/test/L1/DelayedVetoable.t.sol, packages/contracts-bedrock/test/Safe/LivenessGuard.t.sol, packages/contracts-bedrock/test/dispute/PermissionedDisputeGame.t.sol |
Imported Errors.sol and updated error handling in tests to align with BadAuth usage. |
Recent Review Status
Configuration used: CodeRabbit UI
Commits
Files that changed from the base of the PR and between 4c97429811861cf61398b150347225aac669fb6f and 368eef7f2fb4121ec5da8d2ba51abb5eb278d8a6.Files selected for processing (13)
- op-bindings/bindings/delayedvetoable.go (1 hunks)
- op-bindings/bindings/delayedvetoable_more.go (1 hunks)
- packages/contracts-bedrock/snapshots/abi/DelayedVetoable.json (1 hunks)
- packages/contracts-bedrock/snapshots/abi/LivenessGuard.json (1 hunks)
- packages/contracts-bedrock/snapshots/abi/PermissionedDisputeGame.json (1 hunks)
- packages/contracts-bedrock/src/L1/DelayedVetoable.sol (4 hunks)
- packages/contracts-bedrock/src/Safe/LivenessGuard.sol (3 hunks)
- packages/contracts-bedrock/src/dispute/PermissionedDisputeGame.sol (3 hunks)
- packages/contracts-bedrock/src/libraries/DisputeErrors.sol (1 hunks)
- packages/contracts-bedrock/src/libraries/Errors.sol (1 hunks)
- packages/contracts-bedrock/test/L1/DelayedVetoable.t.sol (4 hunks)
- packages/contracts-bedrock/test/Safe/LivenessGuard.t.sol (3 hunks)
- packages/contracts-bedrock/test/dispute/PermissionedDisputeGame.t.sol (3 hunks)
Files skipped from review due to trivial changes (1)
- packages/contracts-bedrock/src/libraries/DisputeErrors.sol
Additional comments not posted (26)
packages/contracts-bedrock/src/libraries/Errors.sol (1)
8-9: LGTM! The introduction ofBadAutherror for standardized error handling is a good practice.packages/contracts-bedrock/snapshots/abi/LivenessGuard.json (1)
178-187: LGTM! Adding theBadAutherror to the ABI aligns with the standardized error handling approach.packages/contracts-bedrock/snapshots/abi/DelayedVetoable.json (1)
189-195: LGTM! RenamingUnauthorizedtoBadAuthand updating the parameter toexpectedRolein the ABI is consistent with the standardized error handling approach.packages/contracts-bedrock/src/dispute/PermissionedDisputeGame.sol (3)
9-9: LGTM! ImportingErrors.solis correctly done.
29-29: LGTM! UsingBadAuthfor standardized error handling inonlyAuthorizedis a good practice.
99-99: LGTM! UsingBadAuthininitializefor standardized error handling is appropriate.op-bindings/bindings/delayedvetoable_more.go (1)
16-16: LGTM! Updating theDelayedVetoableDeployedBinvariable's value reflects the changes in the contract deployment.packages/contracts-bedrock/src/Safe/LivenessGuard.sol (3)
11-11: LGTM! ImportingErrors.solis correctly done.
65-65: LGTM! Replacingrequirewithifandrevertfor error handling is a good practice.
155-157: LGTM! UsingBadAuthinshowLivenessfor standardized error handling is appropriate.packages/contracts-bedrock/src/L1/DelayedVetoable.sol (3)
5-5: LGTM! ImportingErrors.solis correctly done.
129-129: LGTM! ReplacingUnauthorizedwithBadAuthfor standardized error handling is a good practice.
162-162: LGTM! UsingBadAuthfor unauthorized initiation attempts aligns with the standardized error handling approach.packages/contracts-bedrock/test/dispute/PermissionedDisputeGame.t.sol (3)
16-16: LGTM! ImportingErrors.solis correctly done.
123-123: LGTM! Usingabi.encodeWithSelectorwithBadAuth.selectorfor more specific error messages is a good practice.
163-163: LGTM! Usingabi.encodeWithSelectorwithBadAuth.selectorfor standardized error handling in tests is appropriate.packages/contracts-bedrock/test/L1/DelayedVetoable.t.sol (4)
6-6: Consider adding a brief comment above the import statement forErrors.solto explain its purpose.
75-83: Ensure that theexpectedRoleparameter passed toBadAuthaccurately reflects the role required for the operation being tested.
154-154: Verify that theexpectedRoleparameter inBadAuthis correctly set to "Initiator" for operations that should only be performed by the initiator.
190-190: Double-check that theexpectedRoleparameter inBadAuthis appropriately set for cases where a call is forwarded or attempted to be forwarded twice.packages/contracts-bedrock/test/Safe/LivenessGuard.t.sol (4)
13-13: Adding a comment explaining the purpose of importingErrors.solcould improve code readability.
68-68: Ensure theexpectedRoleparameter inBadAuthaccurately reflects the role required for the operation being tested, such as "Safe" for operations that should only be performed by the Safe contract.
121-121: Double-check that theexpectedRoleparameter inBadAuthis correctly set to "Safe" for operations that should only be performed by the Safe contract.
129-129: Verify that theexpectedRoleparameter inBadAuthis appropriately set for operations that should only be performed by a Safe owner.packages/contracts-bedrock/snapshots/abi/PermissionedDisputeGame.json (1)
651-657: The addition of theexpectedRoleparameter to theBadAutherror aligns with the PR's objective to enhance error message clarity by specifying the expected authorization role upon failure. Ensure that all contracts usingBadAuthare updated accordingly.op-bindings/bindings/delayedvetoable.go (1)
33-34: Ensure ABI and bytecode updates align with contract changes.Please verify that the ABI and bytecode (
Bin) updates accurately reflect the intended contract changes, particularly the addition of theBadAutherror type. This verification is crucial for ensuring that the Go bindings remain consistent with the contract's functionality and error handling mechanisms.
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?
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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger a review. This is useful when automatic reviews are disabled for the repository.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai helpto 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.yamlfile 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.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 29.22%. Comparing base (
4c97429) to head (368eef7). Report is 256 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #10069 +/- ##
============================================
- 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.
For example,
BadAuth(with different params) already exists in the dispute / cannon errors somewhere.
Actually I moved it over to the new file
Be sure to update semver in each file please :)
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.