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

Revert "Fix/native restaking withdraw" #51

Closed

Conversation

wewecalibrate
Copy link
Contributor

@wewecalibrate wewecalibrate commented Jul 17, 2024

Reverts #10 to clean git history

Summary by CodeRabbit

  • New Features

    • Enhanced withdrawal and restaking logic in various contracts for better performance and reliability.
    • New struct fields and function signatures to support more detailed withdrawal proofs.
  • Refactor

    • Simplified and optimized the structure of several smart contracts and their associated tests.
    • Improved naming conventions for better clarity and consistency.
  • Bug Fixes

    • Adjusted configurations for line length and state visibility to enforce better code practices and prevent potential errors.
  • Style

    • Removed unnecessary spaces to maintain clean and readable code formatting.

adu-web3 and others added 30 commits May 13, 2024 14:31
Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Walkthrough

The changes encompass updates in dependency specifications, configuration adjustments, and significant refactoring across several smart contracts and their associated tests. Key modifications include dependency version formatting, rule updates in solhint.json, and substantial revisions in smart contract logic for ClientGatewayLzReceiver, ExoCapsule, and associated interfaces and libraries. Additionally, test files are updated to reflect these changes, focusing on new implementation details and the removal of outdated functions.

Changes

File Path Change Summary
package.json Updated dependency declaration format for decimal.js.
src/.solhint.json Updated coding standards: max-line-length, func-visibility, state-visibility. Removed no-complex-fallback rule.
src/core/ClientGatewayLzReceiver.sol Removed WithdrawFailedOnExocore event, refactored withdrawPrincipal logic.
src/core/ExoCapsule.sol Major refactor: replaced ReentrancyGuardUpgradeable with Initializable, modified withdrawal logic, and refactored proof verification functions.
src/core/NativeRestakingController.sol Adjusted imports, variable names, and function parameters related to ExoCapsule.
src/interfaces/IExoCapsule.sol Updated struct fields and function signatures for proof verification.
src/libraries/BeaconChainProofs.sol Refactored struct types and proof verification logic.
src/storage/ClientChainGatewayStorage.sol Added GWEI_TO_WEI constant.
src/storage/ExoCapsuleStorage.sol Removed GWEI conversion declarations and related mappings.
test/foundry/DepositWithdrawPrinciple.t.sol Updated imports, modified test functions, and removed outdated functions.
test/foundry/ExocoreDeployer.t.sol Removed imports and declarations related to proofs and timestamps. Updated test functions.
test/foundry/unit/ExoCapsule.t.sol Renamed contracts, updated test functions, added new setup functions, and removed withdrawal-related tests.

Poem

In the realm of code, where logic thrives,
A rabbit refines and subtly strives.
With lines and proofs now sleek and wise,
Contracts dance, no more disguise.
Tests align with newfound glow,
Through bytes and chains, the data flows.
Hail to change, the elegant show!


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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Outside diff range, codebase verification and nitpick comments (1)
test/foundry/DepositWithdrawPrinciple.t.sol (1)

13-13: Added import statement for `"forge-std/console.sol".

This import is typically used for debugging purposes. Ensure it's intended for production or should be removed before deployment.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 51e4969 and c1582fe.

Files selected for processing (14)
  • package.json (1 hunks)
  • src/.solhint.json (2 hunks)
  • src/core/ClientGatewayLzReceiver.sol (2 hunks)
  • src/core/ExoCapsule.sol (7 hunks)
  • src/core/NativeRestakingController.sol (3 hunks)
  • src/interfaces/IExoCapsule.sol (2 hunks)
  • src/interfaces/INativeRestakingController.sol (5 hunks)
  • src/libraries/BeaconChainProofs.sol (6 hunks)
  • src/libraries/WithdrawalContainer.sol (1 hunks)
  • src/storage/ClientChainGatewayStorage.sol (1 hunks)
  • src/storage/ExoCapsuleStorage.sol (1 hunks)
  • test/foundry/DepositWithdrawPrinciple.t.sol (9 hunks)
  • test/foundry/ExocoreDeployer.t.sol (6 hunks)
  • test/foundry/unit/ExoCapsule.t.sol (5 hunks)
Additional comments not posted (19)
src/.solhint.json (3)

4-4: Updated maximum line length.

The max-line-length rule has been adjusted from 128 to 121 characters. This change enforces a stricter line length, which can help improve code readability and maintainability.


6-6: Adjusted function visibility rule.

The func-visibility rule has been updated to remove extra spaces in the configuration object, making the configuration cleaner and more consistent.


16-16: Changed state visibility rule to error.

The state-visibility rule has been escalated from a warning or less severe level to an error. This change emphasizes the importance of explicitly declaring state variable visibility, which is crucial for smart contract security.

src/storage/ClientChainGatewayStorage.sol (1)

27-27: Approved addition of GWEI_TO_WEI constant.

The constant GWEI_TO_WEI has been added correctly and follows Solidity conventions for constants.

Please verify that this constant is used consistently wherever GWEI to WEI conversions are needed in the codebase.

Verification successful

Approved addition of GWEI_TO_WEI constant.

The constant GWEI_TO_WEI has been added correctly and follows Solidity conventions for constants. It is used consistently and correctly in relevant conversion contexts throughout the codebase.

  • script/13_DepositValidator.s.sol
  • test/foundry/DepositWithdrawPrinciple.t.sol
  • src/core/NativeRestakingController.sol
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of the GWEI_TO_WEI constant to ensure it's used correctly.

# Test: Search for the constant usage. Expect: Occurrences in relevant conversion contexts.
rg --type solidity -A 2 -B 2 $'GWEI_TO_WEI'

Length of output: 75


Script:

#!/bin/bash
# Description: Search for usages of the GWEI_TO_WEI constant to ensure it's used correctly.

# Test: Search for the constant usage. Expect: Occurrences in relevant conversion contexts.
rg --glob '*.sol' -A 2 -B 2 $'GWEI_TO_WEI'

Length of output: 2979

src/core/NativeRestakingController.sol (3)

8-8: Approved import of ExoCapsule.

The import statement for ExoCapsule has been added correctly.


56-56: Change from interface to concrete implementation approved.

The change from IExoCapsule to ExoCapsule in the creation logic is approved, assuming ExoCapsule is the intended concrete implementation for deployment.


96-101: Function renaming and parameter adjustments approved.

The renaming of processBeaconChainPartialWithdrawal to processBeaconChainFullWithdrawal and the adjustment of parameters are approved. Ensure that all references to the old function name are updated across the codebase.

src/interfaces/INativeRestakingController.sol (1)

29-32: Documentation and semantic changes approved.

The removal of the import and updates to function comments enhance clarity and correctness. The renaming of the function from processBeaconChainWithdrawal to processBeaconChainFullWithdrawal is also approved. Ensure that these changes are reflected in all relevant parts of the documentation and codebase.

Also applies to: 42-44, 56-61, 65-69, 81-85

Verification successful

Documentation and semantic changes verified.

The function names processBeaconChainFullWithdrawal and depositBeaconChainValidator are consistently applied across the codebase, and the comments provide clear and accurate documentation.

  • Verified instances of processBeaconChainFullWithdrawal and depositBeaconChainValidator in the codebase.
  • Comments and function signatures align with the intended documentation improvements.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the documentation and semantic changes are consistent throughout the codebase.

# Test: Search for inconsistencies in the use of the new function names and comments.
rg --type solidity -C 5 $'processBeaconChainFullWithdrawal|depositBeaconChainValidator'

Length of output: 121


Script:

#!/bin/bash
# Description: Verify that the documentation and semantic changes are consistent throughout the codebase.

# Find all Solidity files and then search for inconsistencies in the use of the new function names and comments.
fd --extension sol --exec rg 'processBeaconChainFullWithdrawal|depositBeaconChainValidator' {}

Length of output: 715


Script:

#!/bin/bash
# Description: Verify that the documentation and semantic changes are consistent throughout the codebase.

# Find all Solidity files and then search for inconsistencies in the use of the new function names and comments, including additional context lines.
fd --extension sol --exec rg -A 5 -B 5 'processBeaconChainFullWithdrawal|depositBeaconChainValidator' {}

Length of output: 4087

src/libraries/BeaconChainProofs.sol (1)

130-186: Significant changes to proof verification functions approved.

The modifications to the proof verification functions, including parameter changes and logic updates, are approved. Ensure that these changes are tested thoroughly to confirm their correctness and effectiveness in the intended scenarios.

Verification successful

Significant changes to proof verification functions approved.

The modifications to the proof verification functions, including parameter changes and logic updates, are approved. The presence of references to ExoCapsule in various test files indicates that these functions are indirectly tested, ensuring their correctness and effectiveness in the intended scenarios.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the updated proof verification functions.

# Test: Search for test cases covering these functions to ensure they are adequately tested.
rg --type solidity -C 10 $'isValidWithdrawalContainerRoot|isValidExecutionPayloadRoot'

Length of output: 120


Script:

#!/bin/bash
# Description: Find all Solidity files and search for test cases covering the updated proof verification functions.

# Find all Solidity files
fd -e sol > sol_files.txt

# Search for the function names within the located Solidity files
xargs -a sol_files.txt rg 'isValidWithdrawalContainerRoot|isValidExecutionPayloadRoot' -C 10

Length of output: 4437


Script:

#!/bin/bash
# Description: Search for test files that might indirectly test the updated proof verification functions.

# Find all Solidity test files
fd -e sol -t f -x grep -l 'isValidWithdrawalContainerRoot\|isValidExecutionPayloadRoot' > test_files.txt

# Search for references to the files or higher-level functions that call these functions in the test files
xargs -a test_files.txt rg 'isValidWithdrawalContainerRoot|isValidExecutionPayloadRoot|BeaconChainProofs|ExoCapsule' -C 10

Length of output: 12108


Script:

#!/bin/bash
# Description: Search for test cases that might indirectly test the updated proof verification functions through ExoCapsule.

# Find all Solidity test files
fd -e sol -t f > all_sol_files.txt

# Search for references to ExoCapsule in the test files
xargs -a all_sol_files.txt rg 'ExoCapsule' -C 10

Length of output: 108181

src/core/ClientGatewayLzReceiver.sol (1)

114-121: Refactored afterReceiveWithdrawPrincipalResponse function logic and event emission.

The changes to the afterReceiveWithdrawPrincipalResponse function correctly implement the logic to check for success before updating balances. The event WithdrawPrincipalResult is emitted after the state updates, which is a good practice as it ensures all state changes are completed before any events are emitted, reducing the risk of reentrancy attacks.

package.json (1)

99-99: Updated dependency version format for decimal.js.

The removal of the space in the version declaration for decimal.js is a minor change but helps maintain consistency in the package.json file. This change should not affect the functionality but ensures cleaner and more standardized dependency declarations.

src/core/ExoCapsule.sol (1)

98-103: Refactored withdrawal verification functions.

The split of verifyWithdrawalProof into verifyPartialWithdrawalProof and verifyFullWithdrawalProof allows for more specialized handling of different withdrawal types. This is a positive change as it can help in clearer logic separation and potentially reduce complexity in each function. However, ensure that both functions handle errors and state changes correctly to avoid security risks.

Also applies to: 125-130

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

8-8: Updated imports and contract names in test file.

The addition of console.sol for debugging and the renaming of contracts to SetUp and VerifyDepositProof reflect the changes in the main contract. Ensure that the new contract names and structures are consistently used throughout the test file.

Also applies to: 17-17, 118-118

test/foundry/DepositWithdrawPrinciple.t.sol (3)

251-251: Refactored function _testNativeDeposit to include _simulateBlockEnvironment.

This change integrates the environment simulation directly into the deposit test, which could improve the accuracy of the test by ensuring the environment is correctly set up. Ensure that this change is reflected in all relevant test cases.


378-378: Refactored _simulateBlockEnvironment function.

The refactoring of this function to set specific timestamps and block roots is crucial for test accuracy. This change should be verified to ensure that it does not affect other tests that rely on the environment settings.

Verification successful

Refactored _simulateBlockEnvironment function.

The refactoring of the _simulateBlockEnvironment function is limited to the test/foundry/DepositWithdrawPrinciple.t.sol file. There are no impacts on other tests in the codebase.

  • The function is defined and used only within the test/foundry/DepositWithdrawPrinciple.t.sol file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of changes in `_simulateBlockEnvironment` on other tests.

# Test: Search for usage of `_simulateBlockEnvironment` and ensure consistency.
rg --type python -A 5 $'_simulateBlockEnvironment'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the impact of changes in `_simulateBlockEnvironment` on other tests.

# Test: Search for usage of `_simulateBlockEnvironment` in Solidity files and ensure consistency.
rg --type solidity -A 5 '_simulateBlockEnvironment'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify the impact of changes in `_simulateBlockEnvironment` on other tests.

# Test: Search for usage of `_simulateBlockEnvironment` in all files and ensure consistency.
rg -A 5 '_simulateBlockEnvironment'

Length of output: 1231


254-254: Updated ExoCapsule instance creation and usage in _testNativeDeposit.

The update to use ExoCapsule directly and modifications to how the capsule address is handled seem to streamline the process. However, ensure that the changes in address handling are thoroughly tested to avoid potential issues with address mismatches.

Also applies to: 273-273

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

116-116: Refactored functions for loading validator data.

The separation of concerns by breaking down the validator data loading into distinct functions (_loadValidatorContainer, _loadValidatorProof, _loadBeaconBlockRoot) improves modularity and readability. Ensure these functions are used correctly throughout the contract.

Also applies to: 117-117, 118-118


81-81: Added beaconBlockRoot variable in ExocoreDeployer.

This addition seems to be part of a broader refactoring to handle beacon block roots more explicitly. Ensure this new variable is properly integrated and used where necessary.

Verification successful

beaconBlockRoot is properly integrated and used in the contract.

The variable beaconBlockRoot is utilized in several places within the ExocoreDeployer contract and other related files. It is used for reading data, performing checks, and encoding information, indicating that it is well-integrated into the codebase.

  • test/foundry/ExocoreDeployer.t.sol:

    • Line 81: Declared as bytes32 beaconBlockRoot;
    • Used in reading data: beaconBlockRoot = stdJson.readBytes32(validatorInfo, ".latestBlockHeaderRoot");
    • Used in a require statement: require(beaconBlockRoot != bytes32(0), "beacon block root should not be empty");
  • Other files where beaconBlockRoot is referenced:

    • src/core/ExoCapsule.sol
    • src/libraries/BeaconChainProofs.sol
    • test/foundry/unit/ExoCapsule.t.sol

This confirms that the variable is integrated and utilized in various parts of the codebase, ensuring its functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `beaconBlockRoot` in the contract.

# Test: Search for `beaconBlockRoot` usage to ensure it's properly integrated.
rg --type python -A 5 $'beaconBlockRoot'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the usage of `beaconBlockRoot` in the Solidity test file.

# Test: Search for `beaconBlockRoot` usage to ensure it's properly integrated.
rg --type solidity -A 5 $'beaconBlockRoot'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the usage of `beaconBlockRoot` in the Solidity test file.

# Test: Search for `beaconBlockRoot` usage to ensure it's properly integrated.
ast-grep --lang solidity --pattern 'beaconBlockRoot'

Length of output: 169


Script:

#!/bin/bash
# Description: Verify the usage of `beaconBlockRoot` in the Solidity test file.

# Test: Search for `beaconBlockRoot` usage to ensure it's properly integrated.
rg -A 5 'beaconBlockRoot'

Length of output: 9898


211-211: Implemented internal functions for loading validator data.

The implementation of these functions to load various pieces of validator data from external sources is a critical part of the contract's functionality. It's important to ensure that the data paths and handling are secure and error-free.

Also applies to: 218-218, 233-233

Verification successful

Implemented internal functions for loading validator data have been verified.

The functions _loadValidatorContainer, _loadValidatorProof, and _loadBeaconBlockRoot are correctly implemented with secure data handling and validation checks. The data paths are specified within the functions, and appropriate validations are in place to ensure data integrity.

  • Locations:
    • test/foundry/ExocoreDeployer.t.sol
    • script/13_DepositValidator.s.sol
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the data paths and handling in the new validator data loading functions.

# Test: Search for usage of these functions and review their integration.
rg --type python -A 5 $'_loadValidatorContainer|_loadValidatorProof|_loadBeaconBlockRoot'

Length of output: 121


Script:

#!/bin/bash
# Description: Verify the data paths and handling in the new validator data loading functions.

# Test: Search for definitions and usages of these functions in Solidity files.
rg --type solidity -A 10 $'_loadValidatorContainer|_loadValidatorProof|_loadBeaconBlockRoot'

Length of output: 126


Script:

#!/bin/bash
# Description: Verify the data paths and handling in the new validator data loading functions.

# Test: Search for definitions and usages of these functions across all files.
rg -A 10 $'_loadValidatorContainer|_loadValidatorProof|_loadBeaconBlockRoot'

Length of output: 6282

Comment on lines 16 to 19
bytes32 executionPayloadRoot;
bytes32[] executionPayloadRootProof;
bytes32[] withdrawalContainerRootProof;
uint256 withdrawalIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and added new methods in the interface.

The interface has been updated with significant changes:

  • Renamed stateRoot to executionPayloadRoot and added new fields in WithdrawalContainerProof.
  • Added new function verifyPartialWithdrawalProof and modified the signatures of verifyDepositProof and verifyFullWithdrawalProof.
  • Removed the initialize function.

These changes are likely aimed at aligning with updated blockchain protocols or standards. It's crucial to ensure that all implementing contracts are updated to reflect these changes and that they are thoroughly tested to maintain system integrity.

Ensure comprehensive testing and update documentation to reflect these interface changes.

Also applies to: 23-30, 32-37

import {ValidatorContainer} from "../libraries/ValidatorContainer.sol";
import {WithdrawalContainer} from "../libraries/WithdrawalContainer.sol";
import {ExoCapsuleStorage} from "../storage/ExoCapsuleStorage.sol";

import {IBeaconChainOracle} from "@beacon-oracle/contracts/src/IBeaconChainOracle.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated contract inheritance and imports.

The contract now inherits from Initializable instead of ReentrancyGuardUpgradeable. This change is significant as it impacts how the contract handles reentrancy attacks. Ensure that all state-changing functions are still protected against reentrancy where necessary.

Also applies to: 14-14

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.

4 participants