Skip to content

Conversation

ernestognw
Copy link
Member

@ernestognw ernestognw commented Aug 28, 2025

Fixes #????

PR Checklist

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

Summary by Sourcery

Enforce mandatory initialization during ERC1967 proxy deployment by default and update tests to reflect the new requirement.

New Features:

  • Require proxies to be initialized upon deployment by default, reverting with ERC1967ProxyUninitialized if not
  • Introduce _unsafeAllowUninitialized hook to opt out of mandatory initialization

Enhancements:

  • Change ERC1967Utils.upgradeToAndCall to return whether initialization was invoked
  • Require successful upgradeToAndCall or an explicit override in ERC1967Proxy constructor
  • Add ERC1967ProxyUninitialized custom error

Tests:

  • Add test to ensure proxy creation without initialization reverts with ERC1967ProxyUninitialized
  • Update proxy tests to supply encoded initialize data and remove legacy uninitialized behavior tests
  • Refactor TransparentUpgradeableProxy tests to use scoped implementation variables and proper initialization calls

Copy link

changeset-bot bot commented Aug 28, 2025

⚠️ No Changeset found

Latest commit: 2b051e7

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

Copy link
Contributor

sourcery-ai bot commented Aug 28, 2025

Reviewer's Guide

This PR enforces explicit initialization of ERC1967 proxies by default, modifying the proxy constructor to revert on uninitialized deployments, updating the upgradeToAndCall utility to return a flag indicating whether initialization was performed, and updating related tests and mocks to provide initialization data accordingly.

Sequence diagram for ERC1967Proxy constructor enforcing initialization

sequenceDiagram
    participant User
    participant ERC1967Proxy
    participant ERC1967Utils
    User->>ERC1967Proxy: Deploy with implementation, _data
    ERC1967Proxy->>ERC1967Utils: upgradeToAndCall(implementation, _data)
    ERC1967Utils-->>ERC1967Proxy: returns called (bool)
    alt _unsafeAllowUninitialized() is false and called is false
        ERC1967Proxy-->>User: revert with ERC1967ProxyUninitialized
    else
        ERC1967Proxy-->>User: deployment succeeds
    end
Loading

Class diagram for updated ERC1967Proxy and ERC1967Utils

classDiagram
    class ERC1967Proxy {
        +constructor(address implementation, bytes _data)
        +_implementation() internal view returns (address)
        +_unsafeAllowUninitialized() internal pure virtual returns (bool)
    }
    ERC1967Proxy --|> Proxy
    ERC1967Proxy ..> ERC1967Utils

    class ERC1967Utils {
        +error ERC1967NonPayable()
        +error ERC1967ProxyUninitialized()
        +upgradeToAndCall(address newImplementation, bytes data) internal returns (bool)
        +getImplementation() internal view returns (address)
    }
Loading

Class diagram for ClashingImplementation mock contract

classDiagram
    class ClashingImplementation {
        +initialize() external payable
        +upgradeToAndCall(address, bytes calldata) external payable
    }
Loading

File-Level Changes

Change Details Files
Enforce proxy initialization in ERC1967Proxy constructor
  • Wrap upgradeToAndCall in a require that checks its return value
  • Introduce _unsafeAllowUninitialized hook to opt out of initialization enforcement
  • Add ERC1967ProxyUninitialized error for clearer revert reason
contracts/proxy/ERC1967/ERC1967Proxy.sol
Return initialization flag from upgradeToAndCall and define uninitialized error
  • Change upgradeToAndCall to return a boolean indicating if init data was provided
  • Add return statement instead of branching on data length
  • Define ERC1967ProxyUninitialized error in utils library
contracts/proxy/ERC1967/ERC1967Utils.sol
Add initialize function stub to clashing implementation mock
  • Implement placeholder initialize function in ClashingImplementation
contracts/mocks/proxy/ClashingImplementation.sol
Revise tests to always supply initialization data and assert on uninitialized proxies
  • Use interface.encodeFunctionData('initialize', ...) in beforeEach hooks to generate init data
  • Replace local deployment variables with this.implN and shared this.initializeData
  • Remove legacy 'without initialization' test suite
  • Add new test expecting revert with ERC1967ProxyUninitialized when no init data is provided
test/proxy/transparent/TransparentUpgradeableProxy.behaviour.js
test/proxy/Proxy.behaviour.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

coderabbitai bot commented Aug 28, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbit review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@ernestognw ernestognw added the breaking change Changes that break backwards compatibility of the public API. label Aug 28, 2025
@ernestognw ernestognw modified the milestone: 6.0 Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Changes that break backwards compatibility of the public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant