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

feat: remove reward vault deployment in initialization #143

Merged
merged 4 commits into from
Jan 21, 2025

Conversation

adu-web3
Copy link
Collaborator

@adu-web3 adu-web3 commented Jan 21, 2025

Description

The logics of deploying reward vault in ClientChainGateway.initialize function would cause out-of-gas error when upgrading Bootstrap to ClientChainGateway, so we just remove this part of logics and make deployRewardVault a standalone function instead of an internal function since reward vault is currently not working currently.

I don't totally remove the rewardvault state from current contract storage just to make things like keeping storage layout compatible easier.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced deployRewardVault function with access control and event emission in the ClientChainGateway contract.
  • Tests

    • Updated test setup across multiple test files to set chain ID to 1 for consistent network constant usage.
  • Bug Fixes

    • Modified reward vault initialization logic in ExocoreDeployer to require an empty reward vault during contract initialization.

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Warning

Rate limit exceeded

@adu-web3 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 51 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4e5780c and bf5b2ad.

📒 Files selected for processing (1)
  • src/core/ClientChainGateway.sol (1 hunks)

Walkthrough

The pull request introduces changes to the ClientChainGateway.sol contract by transforming the internal _deployRewardVault method into a public deployRewardVault function with enhanced access controls. Additionally, several test files have been updated to set the chain ID to 1, ensuring consistent network constant usage across test environments. The modifications focus on improving contract security, visibility, and test configuration by adding owner-only access, a pause mechanism, and event emission for reward vault deployment.

Changes

File Change Summary
src/core/ClientChainGateway.sol Replaced internal _deployRewardVault() with public deployRewardVault() function, adding onlyOwner and whenNotPaused modifiers, and RewardVaultCreated event
test/foundry/*.t.sol Added vm.chainId(1) in setUp() methods to set consistent chain ID for network constants
test/foundry/ExocoreDeployer.t.sol Modified _deploy() function to require rewardVault address to be zero during initialization

Sequence Diagram

sequenceDiagram
    participant Owner
    participant ClientChainGateway
    participant RewardVault
    
    Owner->>ClientChainGateway: deployRewardVault()
    activate ClientChainGateway
    ClientChainGateway-->>ClientChainGateway: Check owner and paused status
    ClientChainGateway->>RewardVault: Create using Create2
    ClientChainGateway->>ClientChainGateway: Emit RewardVaultCreated event
    deactivate ClientChainGateway
Loading

Possibly related PRs

Suggested reviewers

  • bwhour
  • MaxMustermann2
  • cloud8little

Poem

🐰 A Rabbit's Ode to Vault Deployment

With access tight and pause in sight,
Our gateway stands, secure and bright.
Create2 magic, events so clear,
Reward vault spawns without a fear.
Code hops with grace, control supreme! 🔒✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title 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

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.

Copy link

github-actions bot commented Jan 21, 2025

✅ The Forge CI workflow has completed successfully. Check the workflow run for details. (bf5b2ad)

Copy link

github-actions bot commented Jan 21, 2025

✅ The Solhint workflow has completed successfully. Check the workflow run for details. (bf5b2ad)

Copy link

github-actions bot commented Jan 21, 2025

✅ The Slither Analysis workflow has completed successfully. Check the workflow run for details. (bf5b2ad)

Copy link

github-actions bot commented Jan 21, 2025

✅ The Compare Storage Layouts workflow has completed successfully. Check the workflow run for details. (bf5b2ad)

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: 0

🧹 Nitpick comments (2)
src/core/ClientChainGateway.sol (1)

Line range hint 149-159: LGTM! The new deployRewardVault function looks well-structured.

The function has proper access controls and follows best practices for proxy deployment. The use of Create2 with a fixed salt ensures deterministic address generation, which is important for cross-chain verification.

Consider adding:

  1. A check to prevent redeployment if the reward vault already exists
  2. Documentation explaining the expected deployment workflow
 function deployRewardVault() external onlyOwner whenNotPaused {
+    if (address(rewardVault) != address(0)) {
+        revert("RewardVault already deployed");
+    }
     rewardVault = IRewardVault(
         Create2.deploy(
             0,
             bytes32(bytes("REWARD_VAULT")),
             // for clarity, this BEACON_PROXY is not related to beacon chain
             // but rather it is the bytecode for the beacon proxy upgrade pattern.
             abi.encodePacked(BEACON_PROXY_BYTECODE.getBytecode(), abi.encode(address(REWARD_VAULT_BEACON), ""))
         )
     );
     rewardVault.initialize(address(this));
     emit RewardVaultCreated(address(rewardVault));
 }
test/foundry/unit/Bootstrap.t.sol (1)

Line range hint 1007-1019: Consider adding edge case tests for withdrawNonBeaconChainETHFromCapsule.

The function's error cases could be more thoroughly tested. Consider adding tests for:

  1. Zero address recipient
  2. Zero withdrawal amount
+    function test27_WithdrawNonBeaconChainETHFromCapsule_ZeroRecipient() public {
+        _enableNativeRestaking();
+        vm.startPrank(addrs[0]);
+        bootstrap.createExoCapsule();
+
+        uint256 withdrawAmount = 1 ether;
+        vm.expectRevert(Errors.ZeroAddress.selector);
+        bootstrap.withdrawNonBeaconChainETHFromCapsule(payable(address(0)), withdrawAmount);
+        vm.stopPrank();
+    }
+
+    function test27_WithdrawNonBeaconChainETHFromCapsule_ZeroAmount() public {
+        _enableNativeRestaking();
+        vm.startPrank(addrs[0]);
+        bootstrap.createExoCapsule();
+
+        address payable recipient = payable(addrs[1]);
+        vm.expectRevert(Errors.ZeroValue.selector);
+        bootstrap.withdrawNonBeaconChainETHFromCapsule(recipient, 0);
+        vm.stopPrank();
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02e51e3 and 4141203.

📒 Files selected for processing (5)
  • src/core/ClientChainGateway.sol (1 hunks)
  • test/foundry/BootstrapDepositNST.t.sol (1 hunks)
  • test/foundry/ExocoreDeployer.t.sol (1 hunks)
  • test/foundry/unit/Bootstrap.t.sol (1 hunks)
  • test/foundry/unit/ExoCapsule.t.sol (2 hunks)
🧰 Additional context used
📓 Learnings (2)
test/foundry/BootstrapDepositNST.t.sol (1)
Learnt from: adu-web3
PR: ExocoreNetwork/exocore-contracts#121
File: test/foundry/BootstrapDepositNST.t.sol:285-300
Timestamp: 2024-11-12T10:03:05.536Z
Learning: In `test/foundry/BootstrapDepositNST.t.sol`, adu-web3 prefers to use `vm.etch` and direct storage manipulation in tests, instead of deploying the capsule contract with the desired state or using Solidity inheritance and overrides.
test/foundry/ExocoreDeployer.t.sol (1)
Learnt from: adu-web3
PR: ExocoreNetwork/exocore-contracts#102
File: src/core/ClientChainGateway.sol:166-181
Timestamp: 2024-11-12T10:03:21.957Z
Learning: In the Exocore smart contracts, only a single `RewardVault` is deployed during initialization when the transparent proxy is created. Therefore, concerns about `Create2` salt uniqueness, address collisions, and front-running are not applicable in this context.
🔇 Additional comments (6)
test/foundry/BootstrapDepositNST.t.sol (1)

74-74: LGTM! Setting chain ID ensures consistent test environment.

The addition of vm.chainId(1) ensures that the capsule implementation uses the correct network constants during testing.

test/foundry/unit/ExoCapsule.t.sol (2)

51-51: LGTM! Chain ID configuration added to DepositSetup.

Setting chain ID to 1 ensures proper network constant initialization for deposit tests.


360-361: LGTM! Chain ID configuration added to WithdrawalSetup.

Setting chain ID to 1 ensures proper network constant initialization for withdrawal tests.

test/foundry/ExocoreDeployer.t.sol (1)

386-389: LGTM! Updated reward vault validation aligns with the new deployment flow.

The assertion correctly verifies that the reward vault is not deployed during initialization, which is consistent with the architectural change to deploy the reward vault separately.

test/foundry/unit/Bootstrap.t.sol (2)

88-88: LGTM! Well-documented chain ID configuration.

The addition of vm.chainId(1) is properly documented and necessary for the capsule implementation to use default network constants.


Line range hint 1-1146: Excellent test implementation with comprehensive coverage!

The test file demonstrates high-quality testing practices:

  • Consistent and clear test naming convention
  • Well-organized test structure
  • Proper use of test utilities and helpers
  • Thorough state verification

adu-web3 and others added 2 commits January 21, 2025 15:07
Co-authored-by: Max <82761650+MaxMustermann2@users.noreply.github.com>
@adu-web3 adu-web3 added this pull request to the merge queue Jan 21, 2025
Merged via the queue into imua-xyz:main with commit 06ec06c Jan 21, 2025
16 checks passed
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.

3 participants