optimism icon indicating copy to clipboard operation
optimism copied to clipboard

Create a new Errors.sol for reused across codebase

Open maurelian opened this issue 1 year ago • 5 comments

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 BadAuth across various contracts for more precise error handling regarding authorization failures.
  • Refactor
    • Updated ABI fields, error handling, and bytecode for improved contract metadata and interaction.
    • Replaced the Unauthorized error with BadAuth in 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.

maurelian avatar Apr 09 '24 14:04 maurelian

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 of BadAuth error for standardized error handling is a good practice.

packages/contracts-bedrock/snapshots/abi/LivenessGuard.json (1)

178-187: LGTM! Adding the BadAuth error to the ABI aligns with the standardized error handling approach.

packages/contracts-bedrock/snapshots/abi/DelayedVetoable.json (1)

189-195: LGTM! Renaming Unauthorized to BadAuth and updating the parameter to expectedRole in the ABI is consistent with the standardized error handling approach.

packages/contracts-bedrock/src/dispute/PermissionedDisputeGame.sol (3)

9-9: LGTM! Importing Errors.sol is correctly done.


29-29: LGTM! Using BadAuth for standardized error handling in onlyAuthorized is a good practice.


99-99: LGTM! Using BadAuth in initialize for standardized error handling is appropriate.

op-bindings/bindings/delayedvetoable_more.go (1)

16-16: LGTM! Updating the DelayedVetoableDeployedBin variable's value reflects the changes in the contract deployment.

packages/contracts-bedrock/src/Safe/LivenessGuard.sol (3)

11-11: LGTM! Importing Errors.sol is correctly done.


65-65: LGTM! Replacing require with if and revert for error handling is a good practice.


155-157: LGTM! Using BadAuth in showLiveness for standardized error handling is appropriate.

packages/contracts-bedrock/src/L1/DelayedVetoable.sol (3)

5-5: LGTM! Importing Errors.sol is correctly done.


129-129: LGTM! Replacing Unauthorized with BadAuth for standardized error handling is a good practice.


162-162: LGTM! Using BadAuth for unauthorized initiation attempts aligns with the standardized error handling approach.

packages/contracts-bedrock/test/dispute/PermissionedDisputeGame.t.sol (3)

16-16: LGTM! Importing Errors.sol is correctly done.


123-123: LGTM! Using abi.encodeWithSelector with BadAuth.selector for more specific error messages is a good practice.


163-163: LGTM! Using abi.encodeWithSelector with BadAuth.selector for 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 for Errors.sol to explain its purpose.


75-83: Ensure that the expectedRole parameter passed to BadAuth accurately reflects the role required for the operation being tested.


154-154: Verify that the expectedRole parameter in BadAuth is correctly set to "Initiator" for operations that should only be performed by the initiator.


190-190: Double-check that the expectedRole parameter in BadAuth is 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 importing Errors.sol could improve code readability.


68-68: Ensure the expectedRole parameter in BadAuth accurately 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 the expectedRole parameter in BadAuth is correctly set to "Safe" for operations that should only be performed by the Safe contract.


129-129: Verify that the expectedRole parameter in BadAuth is 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 the expectedRole parameter to the BadAuth error aligns with the PR's objective to enhance error message clarity by specifying the expected authorization role upon failure. Ensure that all contracts using BadAuth are 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 the BadAuth error 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?

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.

coderabbitai[bot] avatar Apr 09 '24 14:04 coderabbitai[bot]

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.

see 42 files with indirect coverage changes

codecov[bot] avatar Apr 09 '24 14:04 codecov[bot]

For example, BadAuth (with different params) already exists in the dispute / cannon errors somewhere.

Actually I moved it over to the new file

maurelian avatar Apr 09 '24 14:04 maurelian

Be sure to update semver in each file please :)

tynes avatar Apr 10 '24 01:04 tynes

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.

github-actions[bot] avatar Apr 26 '24 01:04 github-actions[bot]

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.

github-actions[bot] avatar May 12 '24 01:05 github-actions[bot]