Skip to content
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

Raunak/upgradeable uch #87

Merged
merged 2 commits into from
Apr 17, 2024
Merged

Raunak/upgradeable uch #87

merged 2 commits into from
Apr 17, 2024

Conversation

RnkSngh
Copy link
Collaborator

@RnkSngh RnkSngh commented Apr 17, 2024

PR to make UCH upgradeable + add a setter in the UCH to upgrade the dispatcher contract to give us the most flexibility over upgrades.

Though we've previously discussed adding unimplemented methods as placeholders for when we implement channelClose - after discussing with @dshiell we came to the conclusion they don't bring a whole lot, since the current channel close handlers are called closeIbcChannel, and will soon be renamed to chanCloseInit and chanCloseConfirm

Summary by CodeRabbit

  • New Features

    • Introduced an interface for handling universal channels in Inter-Blockchain Communication, including middleware registration and channel management.
    • Added an initialization function and a setDispatcher function for enhanced control over channel handling.
  • Refactor

    • Updated the deployment process to use a proxy pattern, increasing modularity and flexibility.
    • Adjusted channel handling logic and related function calls to align with new interface implementations.
  • Tests

    • Updated test scripts to incorporate new interface and proxy usage, ensuring consistency and functionality across test cases.

@RnkSngh RnkSngh requested a review from nicopernas April 17, 2024 04:48
Copy link

coderabbitai bot commented Apr 17, 2024

Walkthrough

The update involves refactoring the UniversalChannelHandler for upgradeability using a proxy pattern, enhancing the IBC handling capabilities. It introduces interfaces and upgradeable contracts to streamline deployments and modifications, improving flexibility and control over channel management and dispatcher settings.

Changes

Files Change Summary
.../UniversalChannelHandler.sol Upgraded to use proxy pattern, added initialize and setDispatcher, replaced base contract.
.../interfaces/IUniversalChannelHandler.sol New interface for handling IBC channels including middleware and channel operations.
.../interfaces/IbcReceiverUpgradeable.sol Introduced upgradeable IBC receiver with initialization and access control.
script/Deploy.s.sol Updated deployment script to use ERC1967Proxy for deploying the UniversalChannelHandler.
test/... Adjusted tests to use proxies, updated imports and deployment functions, modified assertions.

Possibly related issues

🐰✨🎉
A hop, a skip, in the blockchain deep,
With proxies and patterns, our upgrades keep.
Through channels and codes, our contracts sweep,
On the ledger vast, where the smart bunnies leap!
🌟🐾


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8938907 and 0ba4b94.
Files selected for processing (7)
  • contracts/core/UniversalChannelHandler.sol (3 hunks)
  • contracts/interfaces/IUniversalChannelHandler.sol (1 hunks)
  • contracts/interfaces/IbcReceiverUpgradeable.sol (1 hunks)
  • script/Deploy.s.sol (2 hunks)
  • test/TestUtils.t.sol (2 hunks)
  • test/VirtualChain.sol (5 hunks)
  • test/universal.channel.t.sol (17 hunks)
Files skipped from review as they are similar to previous changes (6)
  • contracts/interfaces/IUniversalChannelHandler.sol
  • contracts/interfaces/IbcReceiverUpgradeable.sol
  • script/Deploy.s.sol
  • test/TestUtils.t.sol
  • test/VirtualChain.sol
  • test/universal.channel.t.sol
Additional comments not posted (5)
contracts/core/UniversalChannelHandler.sol (5)

19-19: Ensure the __gap array is adequately sized for future upgrades.

Verification successful

The verification of the __gap array size in the UniversalChannelHandler.sol file shows that the size of uint256[49] is consistent with other upgradeable contracts in the repository, such as DispatcherV2.sol and Dispatcher.sol. This consistency suggests that the __gap array size is standard across the upgradeable contracts within this codebase.

Conclusion: The __gap array size of uint256[49] in UniversalChannelHandler.sol is adequately sized for future upgrades, aligning with the standard practice observed in other contracts within the repository.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if the __gap size is standard across other upgradeable contracts in the repository.
rg "__gap" --type sol

Length of output: 49



Script:

#!/bin/bash
# Check if the __gap size is standard across other upgradeable contracts in the repository by searching for "__gap" in all files.
rg "__gap"

Length of output: 224


30-36: Transition from a constructor to an initializer is correctly implemented for upgradeability.


194-196: Ensure that the setDispatcher function has appropriate access control and is tested for correct functionality.

Verification successful

Review Summary

The review comment requested verification of the setDispatcher function in terms of access control and testing for correct functionality. The shell script was intended to find tests covering the setDispatcher function, but it encountered an issue with recognizing the .sol file type and incorrectly used --files-with-matches which led to a broad search result unrelated to the specific function.

Analysis of Shell Script Output

The output from the shell script execution contains a lot of unrelated information due to the incorrect command usage. However, there are a few relevant lines that mention tests related to the setDispatcher function:

  • test/universal.channel.t.sol: function test_uch_new_dispatcher_set_ok() public {
  • test/universal.channel.t.sol: address(uch.dispatcher()) == address(newDispatcher), "new dispatcher in uch test not setup correctly"
  • test/universal.channel.t.sol: function test_nonOwner_cannot_set_uch_dispatcher() public {

These lines indicate that there are indeed tests that check the functionality of setting a new dispatcher and ensuring that only the appropriate roles can set the dispatcher. This aligns with the concerns about access control and correct functionality testing.

Conclusion

Based on the analysis, it appears that the setDispatcher function has been covered by tests that check both the functionality of setting a new dispatcher and the access control to ensure that unauthorized users cannot set the dispatcher. Therefore, the original review comment has been addressed adequately in the codebase.

Final Response:

The setDispatcher function in UniversalChannelHandler.sol has appropriate tests to verify its functionality and access control. These tests are found in test/universal.channel.t.sol and include test_uch_new_dispatcher_set_ok and test_nonOwner_cannot_set_uch_dispatcher, which ensure that the dispatcher can only be set by authorized roles and functions correctly when changed.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for tests covering the setDispatcher function.
rg "setDispatcher" --type sol --files-with-matches | xargs rg "test"

Length of output: 15067


27-39: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [18-197]

The integration of upgradeable patterns using OpenZeppelin's standards appears correctly implemented. Ensure comprehensive testing, especially for state continuity and proxy delegation.


191-200: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [34-197]

Review the logic modifications in channel handling and middleware interactions to ensure they align with the new upgradeable architecture and maintain the intended functionality.

Verification successful

The search results from the rg command indicate that the mwStackAddrs mapping is used consistently across several functions within the UniversalChannelHandler.sol file. These usages are found in methods that handle packet reception, acknowledgment, and timeouts, as well as in a method for registering middleware stacks. This suggests that the middleware interaction patterns are integrated into the system's operations as expected.

Given this information, it appears that the middleware interactions and channel handling logic are aligned with the intended functionality of the system, and there are no discrepancies in the usage of mwStackAddrs that would suggest otherwise.

Conclusion: The review of the logic modifications in channel handling and middleware interactions confirms that they align with the new upgradeable architecture and maintain the intended functionality.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any discrepancies in middleware interaction patterns post-upgrade.
ast-grep --lang solidity --pattern $'function $_($_) {
  $$$
  $_.mwStackAddrs[$$$]
  $$$
}'

Length of output: 210



Script:

#!/bin/bash
# Search for usage of mwStackAddrs to verify middleware interaction patterns post-upgrade.
rg "mwStackAddrs" --glob "*.sol"

Length of output: 555


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.

@RnkSngh RnkSngh requested a review from dshiell April 17, 2024 04:48
@RnkSngh RnkSngh force-pushed the raunak/upgradeable-uch branch from 8123629 to 4ad764c Compare April 17, 2024 05:03
@RnkSngh RnkSngh force-pushed the raunak/upgradeable-uch branch from 4ad764c to 0ba4b94 Compare April 17, 2024 05:14
Copy link

@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

contracts/core/UniversalChannelHandler.sol Show resolved Hide resolved
@RnkSngh RnkSngh merged commit 881e47a into main Apr 17, 2024
2 checks passed
@RnkSngh RnkSngh linked an issue Apr 23, 2024 that may be closed by this pull request
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.

Add UCH dispatcher setter + proxy
2 participants