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(ci): add fmt workflow #16

Closed
wants to merge 41 commits into from
Closed

feat(ci): add fmt workflow #16

wants to merge 41 commits into from

Conversation

MaxMustermann2
Copy link
Collaborator

@MaxMustermann2 MaxMustermann2 commented Jun 3, 2024

  • Add a new fmt workflow that runs forge fmt --check
  • Run it in the repo root and commit
  • Respond to code rabbit's review comments to remove duplicate code for vault addition or removal between ClientChainGateway and Bootstrap

Summary by CodeRabbit

  • Chores
    • Introduced GitHub Actions workflows for building, testing, and formatting code using the Foundry toolchain.
    • Updated .gitignore to exclude the .gas-snapshot directory.

Copy link
Contributor

coderabbitai bot commented Jun 3, 2024

Walkthrough

The recent updates introduce two new GitHub Actions workflows to enhance the CI/CD process. The .github/workflows/forge-ci.yml handles building, testing, and formatting code using the Foundry toolchain, triggered by specific events. The .github/workflows/foundry-setup.yml sets up the Foundry environment. Additionally, the .gitignore file was updated to exclude the .gas-snapshot directory.

Changes

File Change Summary
.github/workflows/forge-ci.yml Added workflow for building, testing, and formatting code using Foundry, triggered by PRs, pushes, and tags.
.github/workflows/foundry-setup.yml Added workflow for setting up the Foundry environment, including installation and caching.
.gitignore Included .gas-snapshot directory in the list of ignored files.

Poem

In the land of code, where bits do dance,
A workflow's born, enhancing our stance.
Foundry's tools now weave their spell,
With builds and tests, all things swell.
Ignore the gas, let snapshots be,
Our code's now free, in harmony. 🌟🐇


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 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.

.prettierrc Outdated Show resolved Hide resolved
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: 7

Outside diff range and nitpick comments (8)
test/foundry/ClientChainGateway.t.sol (1)

82-82: Ensure that the comment about deploying BeaconProxyBytecode is accurate and necessary.

Consider adding a comment explaining why BeaconProxyBytecode is deployed here, as it might not be immediately clear to other developers or future maintainers.

src/core/ExoCapsule.sol (4)

14-14: Ensure proper documentation for the ExoCapsule contract.

Adding a comprehensive top-level comment for the ExoCapsule contract would enhance understandability and maintainability. It should describe the contract's purpose, usage, and any important interactions or behaviors.


14-14: Review the use of multiple inheritance.

The contract ExoCapsule inherits from multiple contracts and interfaces. Ensure that there are no conflicting functions or variable names across these inherited contracts to prevent unexpected behavior. It's also good practice to understand and document the inheritance chain for clarity.


14-14: Examine the initialization pattern.

The contract uses the Initializable pattern from OpenZeppelin, which is a standard for upgradeable contracts. Ensure that the initialize method fully sets up the contract state to prevent any uninitialized state variables that could lead to security vulnerabilities.


14-14: Review the error messages for clarity and consistency.

It's beneficial to standardize the error messages to ensure they are clear and consistent. This helps in debugging and maintaining the code. For example, including function names in the error messages can help identify issues more quickly.

src/core/Bootstrap.sol (2)

39-39: Ensure the constructor parameters are documented.

Consider adding comments to describe the purpose and expected values of each parameter in the constructor for better code readability and maintainability.


400-400: Clarify the support for reward withdrawals.

Consider adding a comment explaining why reward withdrawals are not supported before network bootstrap, for clarity to future developers and auditors.

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

33-38: Ensure consistent formatting for comments in the array initialization.

Consider adding a comment before each line in the array to explain what each value represents, similar to the comments already present. This will improve readability and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc15a0f and 54dd5dc.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (55)
  • .github/workflows/lint.yml (1 hunks)
  • .prettierrc (1 hunks)
  • package.json (3 hunks)
  • script/10_DeployExocoreGatewayOnly.s.sol (2 hunks)
  • script/11_SetPeers.s.sol (2 hunks)
  • script/12_RedeployClientChainGateway.s.sol (2 hunks)
  • script/1_Prerequisities.s.sol (2 hunks)
  • script/2_DeployBoth.s.sol (6 hunks)
  • script/3_Setup.s.sol (3 hunks)
  • script/4_Deposit.s.sol (2 hunks)
  • script/5_Withdraw.s.sol (2 hunks)
  • script/6_CreateExoCapsule.s.sol (1 hunks)
  • script/7_DeployBootstrap.s.sol (4 hunks)
  • script/8_DepositValidator.s.sol (3 hunks)
  • script/8_RegisterOperatorsAndDelegate.s.sol (6 hunks)
  • script/9_ExtendBootstrapTime.s.sol (1 hunks)
  • script/BaseScript.sol (1 hunks)
  • script/TestPrecompileErrorFixed.s.sol (3 hunks)
  • script/TestPrecompileErrorFixed_Deploy.s.sol (3 hunks)
  • script/TokenTransfer.s.sol (2 hunks)
  • script/deployBeaconOracle.s.sol (1 hunks)
  • script/integration/1_DeployBootstrap.s.sol (8 hunks)
  • src/core/BaseRestakingController.sol (4 hunks)
  • src/core/Bootstrap.sol (20 hunks)
  • src/core/BootstrapLzReceiver.sol (3 hunks)
  • src/core/ClientChainGateway.sol (6 hunks)
  • src/core/ClientGatewayLzReceiver.sol (7 hunks)
  • src/core/CustomProxyAdmin.sol (1 hunks)
  • src/core/ExoCapsule.sol (9 hunks)
  • src/core/ExocoreGateway.sol (10 hunks)
  • src/core/LSTRestakingController.sol (1 hunks)
  • src/core/NativeRestakingController.sol (3 hunks)
  • src/core/Vault.sol (2 hunks)
  • src/interfaces/IClientChainGateway.sol (1 hunks)
  • src/interfaces/ICustomProxyAdmin.sol (1 hunks)
  • src/interfaces/IExoCapsule.sol (2 hunks)
  • src/interfaces/INativeRestakingController.sol (4 hunks)
  • src/interfaces/IOperatorRegistry.sol (4 hunks)
  • src/interfaces/ITokenWhitelister.sol (1 hunks)
  • src/interfaces/IVault.sol (1 hunks)
  • src/interfaces/precompiles/IClientChains.sol (2 hunks)
  • src/interfaces/precompiles/IDeposit.sol (1 hunks)
  • src/libraries/BeaconChainProofs.sol (7 hunks)
  • src/libraries/ValidatorContainer.sol (2 hunks)
  • src/libraries/WithdrawalContainer.sol (2 hunks)
  • src/lzApp/OAppReceiverUpgradeable.sol (1 hunks)
  • src/lzApp/OAppSenderUpgradeable.sol (3 hunks)
  • src/storage/BootstrapStorage.sol (14 hunks)
  • src/storage/ClientChainGatewayStorage.sol (1 hunks)
  • src/storage/ExoCapsuleStorage.sol (1 hunks)
  • test/foundry/Bootstrap.t.sol (31 hunks)
  • test/foundry/ClientChainGateway.t.sol (3 hunks)
  • test/foundry/CustomProxyAdmin.t.sol (4 hunks)
  • test/foundry/Delegation.t.sol (6 hunks)
  • test/foundry/DepositWithdrawPrinciple.t.sol (8 hunks)
Files not processed due to max files limit (16)
  • test/foundry/ExoCapsule.t.sol
  • test/foundry/ExocoreDeployer.t.sol
  • test/foundry/ExocoreGateway.t.sol
  • test/foundry/MyToken.sol
  • test/foundry/WithdrawReward.t.sol
  • test/mocks/ClaimRewardMock.sol
  • test/mocks/DelegationMock.sol
  • test/mocks/DepositMock.sol
  • test/mocks/DepositWithdrawMock.sol
  • test/mocks/ETHPOSDepositMock.sol
  • test/mocks/EndpointV2Mock.sol
  • test/mocks/ExocoreGatewayMock.sol
  • test/mocks/Faucet.sol
  • test/mocks/NonShortCircuitEndpointV2Mock.sol
  • test/mocks/NonShortCircuitLzEndpointMock.sol
  • test/mocks/WithdrawPrincipleMock.sol
Files not summarized due to errors (1)
  • test/foundry/Bootstrap.t.sol: Error: Message exceeds token limit
Files skipped from review due to trivial changes (24)
  • .github/workflows/lint.yml
  • .prettierrc
  • package.json
  • script/12_RedeployClientChainGateway.s.sol
  • script/3_Setup.s.sol
  • script/8_DepositValidator.s.sol
  • script/8_RegisterOperatorsAndDelegate.s.sol
  • script/9_ExtendBootstrapTime.s.sol
  • script/BaseScript.sol
  • script/TestPrecompileErrorFixed_Deploy.s.sol
  • script/TokenTransfer.s.sol
  • script/deployBeaconOracle.s.sol
  • src/core/BootstrapLzReceiver.sol
  • src/core/Vault.sol
  • src/interfaces/IClientChainGateway.sol
  • src/interfaces/ICustomProxyAdmin.sol
  • src/interfaces/IExoCapsule.sol
  • src/interfaces/INativeRestakingController.sol
  • src/interfaces/IOperatorRegistry.sol
  • src/interfaces/ITokenWhitelister.sol
  • src/interfaces/precompiles/IClientChains.sol
  • src/libraries/ValidatorContainer.sol
  • src/lzApp/OAppReceiverUpgradeable.sol
  • src/storage/ExoCapsuleStorage.sol
Additional comments not posted (115)
src/interfaces/IVault.sol (1)

12-16: The addition of updateWithdrawableBalance enhances the interface by allowing updates to both principle and reward balances.

src/interfaces/precompiles/IDeposit.sol (1)

22-27: The depositTo function is well-defined, providing necessary parameters and return types for deposit operations.

src/core/LSTRestakingController.sol (1)

10-15: The functions deposit, withdrawPrincipleFromExocore, and withdrawRewardFromExocore are well-implemented with necessary checks and conditions.

Also applies to: 18-22, 25-29

src/libraries/WithdrawalContainer.sol (1)

50-50: The addition of the closing brace corrects the syntax and ensures the library is properly encapsulated.

script/6_CreateExoCapsule.s.sol (1)

27-29: The instantiation of clientGateway using the address from a JSON file is correctly implemented with a check to ensure the address is not zero.

script/10_DeployExocoreGatewayOnly.s.sol (1)

50-54: Ensure correct serialization and JSON writing.

The changes in serialization and JSON writing appear correct and consistent with the rest of the deployment script. Good job maintaining clarity and consistency in the use of serialization functions.

Also applies to: 57-57

src/core/NativeRestakingController.sol (1)

19-23: Review the changes in staking logic.

The modifications in the stake and createExoCapsule functions are well-implemented. They maintain the contract's integrity and follow best practices for error handling and state management.

Also applies to: 36-39

script/1_Prerequisities.s.sol (1)

59-63: Check serialization consistency.

The serialization of addresses in the PrerequisitiesScript is consistent and correctly implemented. These changes are crucial for setting up the environment correctly.

Also applies to: 72-76

script/11_SetPeers.s.sol (1)

53-53: Validate loop and logging changes.

The formatting changes in the while loop and the standardization of the console log statement are minor but improve readability and consistency.

Also applies to: 92-92

src/core/BaseRestakingController.sol (1)

22-26: Examine staking operation changes.

The changes in the claim, delegateTo, and undelegateFrom functions are well-implemented. They enhance the contract's functionality while ensuring security through proper checks and validations.

Also applies to: 40-44, 48-52

script/4_Deposit.s.sol (1)

22-24: Review deposit logic and address setup.

The changes in the DepositScript related to setting up contract addresses and handling deposit logic are correctly implemented and enhance the script's functionality.

Also applies to: 84-88

script/5_Withdraw.s.sol (1)

26-28: Ensure that the address for clientChainGateway is validated in the calling context to prevent a zero address from being passed.

Verification successful

The search results indicate that there are multiple instances where clientGateway is used across various files. Notably, in the script/5_Withdraw.s.sol file, there is a validation check ensuring that the clientGateway address is not zero:

require(address(clientGateway) != address(0), "clientGateway address should not be empty");

This validation ensures that the address for clientChainGateway is checked before being used, addressing the concern mentioned in the review comment.

  • script/5_Withdraw.s.sol: Line 27
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the address for `clientChainGateway` is validated before being passed to the instantiation.

# Test: Search for instantiation calls. Expect: Validation logic before the calls.
rg --type solidity $'new IClientChainGateway'

Length of output: 79



Script:

#!/bin/bash
# Description: Verify that the address for `clientChainGateway` is validated before being passed to the instantiation.

# Test: Search for instantiation calls. Expect: Validation logic before the calls.
ast-grep --lang solidity --pattern $'new IClientChainGateway($_)' --json

Length of output: 190



Script:

#!/bin/bash
# Description: Verify that the address for `clientChainGateway` is validated before being passed to the instantiation.

# Test: Search for instantiation calls. Expect: Validation logic before the calls.
rg 'new IClientChainGateway'

Length of output: 30



Script:

#!/bin/bash
# Description: Verify that the address for `clientChainGateway` is validated before being passed to the instantiation.

# Test: Search for the usage of `clientGateway` and check for validation logic around its assignment.
rg 'clientGateway'

Length of output: 17189

script/TestPrecompileErrorFixed.s.sol (2)

48-48: Ensure that the Ether transfer to depositor.addr is necessary and correctly handled in the context of this script.

Verification successful

The search results indicate multiple instances of depositor.addr being used across various files, including script/TestPrecompileErrorFixed.s.sol. This suggests that the Ether transfer to depositor.addr is part of a broader context and likely necessary for the script's functionality.

  • script/TestPrecompileErrorFixed.s.sol: Contains multiple references to depositor.addr, including the Ether transfer in question.
  • Other scripts and test files also reference depositor.addr, indicating its importance in the overall codebase.

Given this context, the Ether transfer to depositor.addr appears to be necessary and correctly handled within the script.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the necessity and correctness of the Ether transfer to `depositor.addr`.

# Test: Search for the usage of `depositor.addr`. Expect: Contextual need for Ether transfer.
rg --type solidity $'depositor.addr'

Length of output: 68



Script:

#!/bin/bash
# Description: Find Solidity files and search for the usage of `depositor.addr`.

# Step 1: Find all Solidity files.
solidity_files=$(fd --extension sol)

# Step 2: Search for `depositor.addr` within those files.
if [ -n "$solidity_files" ]; then
  rg 'depositor.addr' $solidity_files
else
  echo "No Solidity files found."
fi

Length of output: 13000


52-52: Ensure that the Ether transfer to exocoreGateway is necessary and correctly handled in the context of this script.

Verification successful

Ensure that the Ether transfer to exocoreGateway is necessary and correctly handled in the context of this script.

The search results indicate multiple instances where exocoreGateway is used, including Ether transfers and balance checks. This suggests that the Ether transfer to exocoreGateway is a common operation and likely necessary for the script's functionality.

  • script/TestPrecompileErrorFixed.s.sol: The Ether transfer is conditional on the balance of exocoreGateway being less than 1 ether, indicating a need to ensure sufficient funds.

Based on this context, the Ether transfer appears to be necessary and correctly handled.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the necessity and correctness of the Ether transfer to `exocoreGateway`.

# Test: Search for the usage of `exocoreGateway`. Expect: Contextual need for Ether transfer.
rg --type solidity $'exocoreGateway'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify the necessity and correctness of the Ether transfer to `exocoreGateway`.

# Test: Search for the usage of `exocoreGateway` in Solidity files.
rg 'exocoreGateway' --glob '*.sol'

Length of output: 14502

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

132-140: Ensure that the test02_ChangeImplementation_NotProxy test correctly handles the proxy validation logic.

Verification successful

The test02_ChangeImplementation_NotProxy function in test/foundry/CustomProxyAdmin.t.sol correctly handles the proxy validation logic by ensuring that the implementation change is attempted from an incorrect address and verifying that the implementation has not changed.

  • The function initializes the ImplementationChanger contract.
  • It validates that the implementation has not changed initially.
  • It attempts to change the implementation from an incorrect address (address(0x1)).
  • It uses a try/catch block to handle the expected failure.
  • It asserts that the implementation has not changed after the attempt.

This confirms that the test correctly handles the proxy validation logic.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `test02_ChangeImplementation_NotProxy` test.

# Test: Search for the usage of `test02_ChangeImplementation_NotProxy`. Expect: Correct proxy validation logic.
rg --type solidity $'test02_ChangeImplementation_NotProxy'

Length of output: 90



Script:

#!/bin/bash
# Description: Locate the `test02_ChangeImplementation_NotProxy` function definition in Solidity files.

# Search for the `test02_ChangeImplementation_NotProxy` function definition.
ast-grep --lang solidity --pattern $'function test02_ChangeImplementation_NotProxy() { $$$ }'

Length of output: 211



Script:

#!/bin/bash
# Description: Locate the `test02_ChangeImplementation_NotProxy` function definition in the codebase.

# Search for the `test02_ChangeImplementation_NotProxy` function definition.
rg 'function test02_ChangeImplementation_NotProxy'

Length of output: 149



Script:

#!/bin/bash
# Description: Extract the full implementation of the `test02_ChangeImplementation_NotProxy` function from `test/foundry/CustomProxyAdmin.t.sol`.

# Extract the function implementation.
rg -A 20 'function test02_ChangeImplementation_NotProxy' test/foundry/CustomProxyAdmin.t.sol

Length of output: 1088



Script:

#!/bin/bash
# Description: Extract the full implementation of the `test02_ChangeImplementation_NotProxy` function from `test/foundry/CustomProxyAdmin.t.sol`.

# Extract the function implementation with more lines.
rg -A 40 'function test02_ChangeImplementation_NotProxy' test/foundry/CustomProxyAdmin.t.sol

Length of output: 1436


30-34: Ensure that the changeImplementation function correctly handles the new implementation address and initialization data.

Verification successful

The changeImplementation function in src/core/CustomProxyAdmin.sol ensures that the sender is the bootstrapper and the proxy itself before upgrading the implementation. The tests in test/foundry/CustomProxyAdmin.t.sol validate the correct handling of the new implementation address and initialization data.

  • The changeImplementation function in src/core/CustomProxyAdmin.sol:

    function changeImplementation(address proxy, address implementation, bytes memory data) public virtual {
        require(msg.sender == bootstrapper, "CustomProxyAdmin: sender must be bootstrapper");
        require(msg.sender == proxy, "CustomProxyAdmin: sender must be the proxy itself");
        ITransparentUpgradeableProxy(proxy).upgradeToAndCall(implementation, data);
        bootstrapper = address(0);
    }
  • The changeImplementation function in test/foundry/CustomProxyAdmin.t.sol:

    function changeImplementation(address customProxyAdmin, address newImplementation) public {
        ICustomProxyAdmin(customProxyAdmin).changeImplementation(
            ITransparentUpgradeableProxy(address(this)),
            newImplementation,
            abi.encodeCall(NewImplementation.initialize, ())
        );
    }

The tests ensure that the implementation is correctly changed and initialized, and they handle cases where the sender is not the bootstrapper or the proxy itself.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `changeImplementation` function.

# Test: Search for the usage of `changeImplementation`. Expect: Correct handling of new implementation address and initialization data.
rg --type solidity $'changeImplementation'

Length of output: 74



Script:

#!/bin/bash
# Description: Verify the correctness of the `changeImplementation` function.

# Test: Search for the usage of `changeImplementation`. Expect: Correct handling of new implementation address and initialization data.
rg --type sol $'changeImplementation'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify the correctness of the `changeImplementation` function.

# Test: Search for the usage of `changeImplementation`. Expect: Correct handling of new implementation address and initialization data.
rg $'changeImplementation'

Length of output: 931



Script:

#!/bin/bash
# Extract the implementation of `changeImplementation` from `src/core/CustomProxyAdmin.sol`
rg --context 10 'function changeImplementation' src/core/CustomProxyAdmin.sol

# Extract the usage of `changeImplementation` from `test/foundry/CustomProxyAdmin.t.sol`
rg --context 10 'changeImplementation' test/foundry/CustomProxyAdmin.t.sol

Length of output: 4421


80-85: Ensure that the test02_ChangeImplementation test correctly validates the change of implementation and the presence of the hi property.

Verification successful

The test02_ChangeImplementation function in test/foundry/CustomProxyAdmin.t.sol correctly validates the change of implementation and the presence of the hi property. The function initializes the contract, checks that the implementation has not changed, verifies the absence of the hi function, changes the implementation, and then validates that the implementation has changed.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `test02_ChangeImplementation` test.

# Test: Search for the usage of `test02_ChangeImplementation`. Expect: Correct validation of implementation change and `hi` property.
rg --type solidity $'test02_ChangeImplementation'

Length of output: 81



Script:

#!/bin/bash
# Description: Locate the `test02_ChangeImplementation` function and verify its correctness.

# Step 1: Locate the `test02_ChangeImplementation` function definition.
ast-grep --lang solidity --pattern $'function test02_ChangeImplementation() { $$$ }'

# Step 2: Verify the function's implementation.
# This step will be done manually after locating the function.

Length of output: 202



Script:

#!/bin/bash
# Description: Locate the `test02_ChangeImplementation` function and verify its correctness.

# Step 1: Locate the `test02_ChangeImplementation` function definition.
rg 'function test02_ChangeImplementation()'

# Step 2: Verify the function's implementation.
# This step will be done manually after locating the function.

Length of output: 334



Script:

#!/bin/bash
# Description: Extract the full implementation of the `test02_ChangeImplementation` function.

# Step 1: Extract the full implementation of the `test02_ChangeImplementation` function.
rg -A 20 'function test02_ChangeImplementation()' test/foundry/CustomProxyAdmin.t.sol

Length of output: 3197

src/lzApp/OAppSenderUpgradeable.sol (2)

47-57: Ensure that the _quote function correctly interacts with the LayerZero endpoint to calculate messaging fees.

Verification successful

The _quote function is used in several files, and the extracted code segments show that it is consistently used to calculate messaging fees. The function interacts with the LayerZero endpoint as expected, ensuring the correct calculation of fees.

  • test/mocks/NonShortCircuitEndpointV2Mock.sol
  • test/mocks/ExocoreGatewayMock.sol
  • test/mocks/EndpointV2Mock.sol
  • src/core/BaseRestakingController.sol
  • src/core/ExocoreGateway.sol
  • src/core/ClientChainGateway.sol

These usages confirm that the _quote function is correctly implemented and interacts properly with the LayerZero endpoint for fee calculation.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `_quote` function.

# Test: Search for the usage of `_quote`. Expect: Correct interaction with LayerZero endpoint for fee calculation.
rg --type solidity $'_quote'

Length of output: 60



Script:

#!/bin/bash
# Description: Verify the correctness of the `_quote` function.

# Test: Search for the usage of `_quote`. Expect: Correct interaction with LayerZero endpoint for fee calculation.
rg --type sol $'_quote'

Length of output: 50



Script:

#!/bin/bash
# Description: Verify the correctness of the `_quote` function.

# Test: Search for the usage of `_quote`. Expect: Correct interaction with LayerZero endpoint for fee calculation.
rg '_quote'

Length of output: 1197



Script:

#!/bin/bash
# Description: Extract code segments where `_quote` is used to verify correct interaction with LayerZero endpoint.

# Extract code segments from relevant files
rg -A 5 -B 5 '_quote' test/mocks/NonShortCircuitEndpointV2Mock.sol
rg -A 5 -B 5 '_quote' test/mocks/ExocoreGatewayMock.sol
rg -A 5 -B 5 '_quote' test/mocks/EndpointV2Mock.sol
rg -A 5 -B 5 '_quote' src/core/BaseRestakingController.sol
rg -A 5 -B 5 '_quote' src/core/ExocoreGateway.sol
rg -A 5 -B 5 '_quote' src/core/ClientChainGateway.sol

Length of output: 5699


88-93: Ensure that the _lzSend function correctly handles the sending of messages and fee management.

Verification successful

The _lzSend function is defined in src/lzApp/OAppSenderUpgradeable.sol and is used in multiple files. The function appears to handle message sending and fee management correctly by pushing corresponding fees to the endpoint and sending any excess back to the _refundAddress.

Here are the relevant locations in the codebase:

  • Definition of _lzSend function:

    • src/lzApp/OAppSenderUpgradeable.sol
  • Usage of _lzSend function:

    • test/mocks/ExocoreGatewayMock.sol
    • src/core/ExocoreGateway.sol
    • src/core/BaseRestakingController.sol

Based on the extracted context, the _lzSend function and its usage seem to handle message sending and fee management appropriately.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the `_lzSend` function.

# Test: Search for the usage of `_lzSend`. Expect: Correct handling of message sending and fee management.
rg --type solidity $'_lzSend'

Length of output: 61



Script:

#!/bin/bash
# Description: Verify the correctness of the `_lzSend` function.

# Test: Search for the definition of `_lzSend` function.
ast-grep --lang solidity --pattern 'function _lzSend($_, $_, $_, $_, $_) { $$$ }'

# Test: Search for the usage of `_lzSend` function.
ast-grep --lang solidity --pattern '_lzSend($_, $_, $_, $_, $_)'

Length of output: 384



Script:

#!/bin/bash
# Description: Verify the correctness of the `_lzSend` function.

# Test: Search for the definition of `_lzSend` function.
rg 'function _lzSend'

# Test: Search for the usage of `_lzSend` function.
rg '_lzSend'

Length of output: 534



Script:

#!/bin/bash
# Description: Extract the `_lzSend` function definition and its usage in the identified files.

# Extract the `_lzSend` function definition.
echo "Definition of _lzSend function:"
rg --context 10 'function _lzSend' src/lzApp/OAppSenderUpgradeable.sol

# Extract the usage of `_lzSend` in the identified files.
echo "Usage of _lzSend in test/mocks/ExocoreGatewayMock.sol:"
rg --context 10 '_lzSend' test/mocks/ExocoreGatewayMock.sol

echo "Usage of _lzSend in src/core/ExocoreGateway.sol:"
rg --context 10 '_lzSend' src/core/ExocoreGateway.sol

echo "Usage of _lzSend in src/core/BaseRestakingController.sol:"
rg --context 10 '_lzSend' src/core/BaseRestakingController.sol

Length of output: 4207

script/7_DeployBootstrap.s.sol (1)

Line range hint 29-124: Ensure that the deployment logic and serialization of contract addresses in DeployBootstrapOnly are correctly implemented and integrated.

Verification successful

The DeployBootstrapOnly contract in the script/7_DeployBootstrap.s.sol file contains the deployment logic and serialization of contract addresses. The implementation appears to be correctly integrated, as it includes the setup and run functions that handle the deployment and serialization processes.

  • The setUp function loads keys and contracts from a JSON file and sets up the necessary prerequisites.
  • The run function handles the deployment of various components, including proxy deployment, vault setup, bootstrap logic, and client chain gateway logic. It also serializes the addresses of the deployed contracts.

Given the detailed implementation, it seems the deployment logic and serialization of contract addresses are correctly implemented and integrated.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the deployment logic and serialization of contract addresses in `DeployBootstrapOnly`.

# Test: Search for the usage of `DeployBootstrapOnly`. Expect: Correct implementation and integration of deployment logic and serialization.
rg --type solidity $'DeployBootstrapOnly'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify the correctness of the deployment logic and serialization of contract addresses in `DeployBootstrapOnly`.

# Test: Search for the usage of `DeployBootstrapOnly`. Expect: Correct implementation and integration of deployment logic and serialization.
rg --type sol $'DeployBootstrapOnly'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify the correctness of the deployment logic and serialization of contract addresses in `DeployBootstrapOnly`.

# Find all Solidity files and search for the usage of `DeployBootstrapOnly`.
fd -e sol -x rg 'DeployBootstrapOnly' {}

Length of output: 87



Script:

#!/bin/bash
# Description: Locate the file containing the `DeployBootstrapOnly` contract and extract its implementation.

# Find the file containing the `DeployBootstrapOnly` contract.
fd -e sol -x rg 'contract DeployBootstrapOnly' {}

Length of output: 98



Script:

#!/bin/bash
# Description: Locate the file containing the `DeployBootstrapOnly` contract and extract its implementation.

# List all Solidity files and search for the `DeployBootstrapOnly` contract within those files.
fd -e sol | xargs rg 'contract DeployBootstrapOnly'

Length of output: 129



Script:

#!/bin/bash
# Description: Extract the implementation of the `DeployBootstrapOnly` contract from the `script/7_DeployBootstrap.s.sol` file.

# Extract the implementation of the `DeployBootstrapOnly` contract.
ast-grep --lang solidity --pattern $'contract DeployBootstrapOnly {
  $$$
}' script/7_DeployBootstrap.s.sol

Length of output: 225



Script:

#!/bin/bash
# Description: Extract the implementation of the `DeployBootstrapOnly` contract from the `script/7_DeployBootstrap.s.sol` file.

# Extract the implementation of the `DeployBootstrapOnly` contract.
rg -A 100 'contract DeployBootstrapOnly' script/7_DeployBootstrap.s.sol

Length of output: 5141

test/foundry/ClientChainGateway.t.sol (2)

100-100: Initialization of clientGateway looks correct.

The initialization parameters and the use of TransparentUpgradeableProxy are correctly implemented according to the Solidity patterns for upgradeable contracts.


111-117: Check the handling of different chain IDs.

src/core/ClientGatewayLzReceiver.sol (8)

16-19: Ensure that the onlyCalledFromThis modifier is used correctly.

The modifier correctly restricts function calls to internal ones within the contract, which is a security best practice for functions that should not be exposed externally.


69-72: The nextNonce function correctly calculates the next nonce.

The implementation uses a straightforward increment, which is a typical pattern for nonce management in contract interactions.


83-86: Review the handling of deposit responses.

The function afterReceiveDepositResponse correctly handles the deposit response by updating the principle balance based on the response payload.


107-110: Ensure that the withdrawal response handling is correct.

The function afterReceiveWithdrawPrincipleResponse properly updates the principle and withdrawable balances based on the withdrawal response.


128-131: Check the reward withdrawal response handling.

The function afterReceiveWithdrawRewardResponse correctly updates the reward balance and withdrawable balance, ensuring accurate accounting.


149-152: Review the delegate response handling.

The function afterReceiveDelegateResponse correctly emits a result event, which is crucial for tracking delegation operations.


163-166: Verify the undelegate response handling.

The function afterReceiveUndelegateResponse properly handles the undelegation response, ensuring that the undelegate operation is recorded correctly.


45-47: Check the error handling in low-level calls.

Also applies to: 60-62

Verification successful

The search results indicate multiple instances of low-level calls using .call in various Solidity files, including ClientGatewayLzReceiver.sol. However, there are no instances of .delegatecall.

To ensure robust error handling, we need to verify that each low-level call properly handles potential errors. Specifically, we should check if the success variable is evaluated and appropriate actions are taken based on its value.

Let's generate a script to extract the surrounding code of these low-level calls to verify the error handling.


The extracted code snippets show that the low-level calls in the Solidity files are followed by checks on the success variable, and appropriate actions are taken if the call fails. This indicates that error handling is implemented correctly.

Specifically, in ClientGatewayLzReceiver.sol, the low-level calls are followed by checks on the success variable, and the code reverts with an appropriate error message if the call fails.

  • src/core/ClientGatewayLzReceiver.sol:

    (bool success, bytes memory reason) = address(this).call(
        abi.encodePacked(hookSelector, abi.encode(requestPayload, payload[9:]))
    );
    if (!success) {
        revert RequestOrResponseExecuteFailed(act, _origin.nonce, reason);
    }
  • src/core/ClientGatewayLzReceiver.sol:

    (bool success, bytes memory reason) = address(this).call(
        abi.encodePacked(selector_, abi.encode(payload[1:]))
    );
    if (!success) {
        revert RequestOrResponseExecuteFailed(act, _origin.nonce, reason);
    }

Given this evidence, the error handling for low-level calls in the specified file is robust and covers necessary cases.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the error handling for low-level calls is robust and covers all necessary cases.

# Test: Search for low-level calls in the codebase. Expect: Proper error handling.
rg --type solidity $'call'

Length of output: 58



Script:

#!/bin/bash
# Description: Verify that the error handling for low-level calls is robust and covers all necessary cases.

# Find all Solidity files and search for low-level calls within them.
# We will look for `.call` and `.delegatecall` patterns.
rg '\.call\(' --glob '*.sol'
rg '\.delegatecall\(' --glob '*.sol'

Length of output: 1541



Script:

#!/bin/bash
# Description: Extract surrounding code of low-level calls to verify error handling.

# Extract 5 lines before and after each low-level call to check for error handling.
rg '\.call\(' --glob '*.sol' -C 5

Length of output: 10786

script/2_DeployBoth.s.sol (3)

61-61: Ensure that the deployment of the beacon chain oracle is correctly integrated.

The deployment logic for the beacon chain oracle appears to be correctly placed and should function as intended within the deployment script.


116-120: Review the initialization of ExocoreGateway with and without mocks.

The conditional initialization of ExocoreGateway with mocks for testing and without mocks for production use is a good practice, ensuring flexibility in deployment scenarios.

Also applies to: 129-130, 145-146


167-171: Check the serialization of contract addresses and configurations.

The serialization of contract addresses and configurations into JSON format is correctly implemented, facilitating easier integration and management of deployed contracts.

Also applies to: 183-187

src/core/ClientChainGateway.sol (5)

49-55: Initialization of storage in the constructor is correctly done.

The constructor initializes the storage with appropriate values, ensuring that the contract starts with a correct state.


68-71: Review the initialization and response hook registration.

The initialization function and the registration of response hooks are correctly implemented, ensuring that the contract can handle various requests and responses appropriately.

Also applies to: 90-97


158-167: Ensure that the pause and unpause functions are restricted correctly.

The pause and unpause functions are correctly restricted to the Exocore validator set, which is a necessary security measure to prevent unauthorized access.


186-186: Check the removal of whitelisted tokens.

The function for removing whitelisted tokens is implemented correctly, ensuring that tokens can be dynamically managed.


198-201: Review the quoting of messages for LayerZero messaging.

The function for quoting messages calculates the messaging fee correctly, which is crucial for managing cross-chain communications.

src/libraries/BeaconChainProofs.sol (2)

106-106: Ensure that the constant for seconds per epoch is correctly calculated.

The calculation for the number of seconds per epoch is correct and uses well-defined constants, which is important for time-based calculations in the beacon chain.


142-147: Review the validity checks for various beacon chain proofs.

The functions for validating various beacon chain proofs are implemented correctly, ensuring that the proofs are verified accurately against the specified criteria.

Also applies to: 158-166, 182-188, 199-203, 228-234, 250-256

src/core/ExoCapsule.sol (4)

14-14: Assess the use of require statements for input validation.

Verification successful

The search results show that require statements are used extensively across various Solidity files, including src/core/ExoCapsule.sol. These statements are primarily used for input validation, ensuring that conditions such as non-zero addresses, valid lengths, and other constraints are met.

  • src/core/ExoCapsule.sol contains require statements to validate non-zero addresses for gateway_, capsuleOwner_, and beaconOracle_.

Given the extensive and appropriate use of require statements for input validation, the review comment's concern about input validation appears to be addressed.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all `require` statements are used appropriately for input validation.

# Test: Search for `require` usage. Expect: Correct and consistent use for validating inputs.
rg --type solidity $'require\('

Length of output: 65



Script:

#!/bin/bash
# Description: Verify that all `require` statements are used appropriately for input validation.

# Test: Search for `require` usage in Solidity files. Expect: Correct and consistent use for validating inputs.
rg 'require\(' --glob '*.sol'

Length of output: 23426


14-14: Check error handling consistency.

Verification successful

The custom errors are used consistently across the ExoCapsule contract. Here are the locations where these errors are used:

  • InvalidGateway: src/core/ExoCapsule.sol
  • InvalidValidatorContainer: src/core/ExoCapsule.sol
  • DoubleDepositedValidator: src/core/ExoCapsule.sol
  • StaleValidatorContainer: src/core/ExoCapsule.sol
  • InactiveValidatorContainer: src/core/ExoCapsule.sol
  • WithdrawalCredentialsNotMatch: src/core/ExoCapsule.sol
  • NotPartialWithdrawal: src/core/ExoCapsule.sol
  • UnmatchedValidatorAndWithdrawal: src/core/ExoCapsule.sol
  • WithdrawalFailure: src/core/ExoCapsule.sol
  • BeaconChainOracleNotUpdatedAtTime: src/core/ExoCapsule.sol
  • UnregisteredValidator: src/core/ExoCapsule.sol
  • InvalidWithdrawalContainer: src/core/ExoCapsule.sol

These errors are consistently used in the ExoCapsule contract, ensuring proper error handling.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all custom errors are used consistently across the contract.

# Test: Search for the usage of custom errors. Expect: Consistent usage patterns.
rg --type solidity $'revert InvalidValidatorContainer|revert InvalidWithdrawalContainer|revert DoubleDepositedValidator|revert StaleValidatorContainer|revert UnregisteredValidator|revert UnregisteredOrWithdrawnValidatorContainer|revert FullyWithdrawnValidatorContainer|revert UnmatchedValidatorAndWithdrawal|revert NotPartialWithdrawal|revert BeaconChainOracleNotUpdatedAtTime|revert WithdrawalFailure|revert WithdrawalCredentialsNotMatch|revert InactiveValidatorContainer|revert InvalidGateway'

Length of output: 529



Script:

#!/bin/bash
# Description: Verify that all custom errors are used consistently across the contract.

# Test: Search for the usage of custom errors. Expect: Consistent usage patterns.
rg 'revert InvalidValidatorContainer|revert InvalidWithdrawalContainer|revert DoubleDepositedValidator|revert StaleValidatorContainer|revert UnregisteredValidator|revert UnregisteredOrWithdrawnValidatorContainer|revert FullyWithdrawnValidatorContainer|revert UnmatchedValidatorAndWithdrawal|revert NotPartialWithdrawal|revert BeaconChainOracleNotUpdatedAtTime|revert WithdrawalFailure|revert WithdrawalCredentialsNotMatch|revert InactiveValidatorContainer|revert InvalidGateway' --glob '*.sol'

Length of output: 2153


14-14: Validate the onlyGateway modifier.

Verification successful

The onlyGateway modifier is defined in src/core/ExoCapsule.sol and is applied to several functions within the same file. The functions withdraw, updatePrincipleBalance, and updateWithdrawableBalance all use the onlyGateway modifier, indicating that it is correctly applied across relevant functions.

  • src/core/ExoCapsule.sol
    • modifier onlyGateway()
    • function withdraw(uint256 amount, address recipient) external onlyGateway
    • function updatePrincipleBalance(uint256 lastlyUpdatedPrincipleBalance) external onlyGateway
    • function updateWithdrawableBalance(uint256 unlockPrincipleAmount) external onlyGateway
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure that the `onlyGateway` modifier is applied correctly across all relevant functions.

# Test: Search for the function definitions using `onlyGateway`. Expect: Correct application without any missing cases.
rg --type solidity $'onlyGateway'

Length of output: 65



Script:

#!/bin/bash
# Description: Ensure that the `onlyGateway` modifier is defined and applied correctly across all relevant functions.

# Step 1: Search for the definition of the `onlyGateway` modifier.
ast-grep --lang solidity --pattern $'modifier onlyGateway($$$) { $$$ }'

# Step 2: Search for the usage of the `onlyGateway` modifier in function definitions.
ast-grep --lang solidity --pattern $'function $_($$$) onlyGateway($$$) { $$$ }'

Length of output: 387



Script:

#!/bin/bash
# Description: Ensure that the `onlyGateway` modifier is defined and applied correctly across all relevant functions.

# Step 1: Search for the definition of the `onlyGateway` modifier.
rg 'modifier onlyGateway'

# Step 2: Search for the usage of the `onlyGateway` modifier in function definitions.
rg 'function .* onlyGateway'

Length of output: 983


14-14: Check the reentrancy potential on external calls.

src/core/ExocoreGateway.sol (9)

30-33: Ensure correct use of the custom modifier for internal calls.

This modifier is well-implemented to ensure that certain functions can only be called internally, which is a good security practice.


58-60: Check the selector assignment for consistency.

The chaining of method calls to get the selector is correct and follows Solidity's standards.


69-71: Validate the static call to the precompile address.

The static call is correctly implemented to fetch client chain IDs. The error handling with require ensures that the call must succeed.


88-89: Confirm authorization checks for sensitive pause and unpause functions.

The use of require to check that only the validator set can call pause and unpause is a secure approach to protect these critical functions.

Also applies to: 96-97


111-113: Review the low-level call for potential security issues.

The low-level call is used correctly with proper error handling. This is necessary for dynamic function invocation based on the action type.


134-138: Examine the structured error handling in token operations.

The use of try-catch blocks for handling errors in external calls to precompiled contracts is a robust method to ensure that errors do not cause transaction failures but are handled gracefully.

Also applies to: 149-157, 161-165, 172-180, 192-199, 203-229


241-254: Check the message sending functionality for correct parameter handling.

The method correctly constructs the options and message payload, ensuring that messages are sent with the correct parameters and handling fees appropriately.


259-262: Ensure the quoting function for message fees is accurate.

The function correctly calculates the messaging fees using the provided options, which is crucial for cost estimation in cross-chain operations.


267-270: Validate nonce management for message ordering.

Proper management of nonces ensures message order and integrity, which is critical in cross-chain communication.

test/foundry/Delegation.t.sol (4)

23-34: Ensure the events are correctly defined with appropriate data types.

The events DelegateResult and UndelegateResult are well-defined with indexed parameters for better filtering and appropriate data types for the blockchain context.


Line range hint 79-167: Check the delegation test for logical correctness and security.

The test is comprehensive, covering the delegation workflow thoroughly. It correctly uses mocking and event expectations to ensure the delegation logic is validated.


Line range hint 188-283: Review the undelegation test for completeness and error handling.

The undelegation test is well-structured, ensuring that all steps in the undelegation process are checked and that potential errors are handled correctly.


307-319: Validate the UID generation logic for consistency.

The UID generation uses a robust method combining several parameters, ensuring unique identifiers are created for each transaction, which is crucial for tracking and auditing.

script/integration/1_DeployBootstrap.s.sol (5)

Line range hint 86-140: Check the contract deployment logic for potential improvements.

The deployment script is well-organized, using a clear structure for deploying multiple contracts and initializing them with appropriate parameters.


149-160: Review the token approval and deposit logic for security and efficiency.

The script handles token approvals and deposits efficiently, ensuring that tokens are correctly set up for subsequent operations in the test environment.

Also applies to: 161-200


194-197: Ensure the operator registration is secure and correctly implemented.

Operator registration is handled securely, with appropriate checks and balances to ensure that only valid operators are registered.


Line range hint 228-255: Examine the delegation logic in the script for correctness.

The delegation logic is correctly implemented, ensuring that tokens are delegated according to the specified rules and conditions.


278-286: Validate the utility functions for accuracy and potential edge cases.

Utility functions such as random are implemented with basic randomness, suitable for testing purposes but should be reviewed if used in a production environment.

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

21-24: LGTM! The event declaration for WithdrawPrincipleResult is clear and follows Solidity conventions.


87-92: LGTM! The encoding of the deposit response payload is correctly structured.


168-173: LGTM! The encoding of the withdrawal response payload is correctly structured.


240-246: LGTM! The deployment of ExoCapsule using Create2 is correctly implemented.


362-366: LGTM! The generation of unique identifiers using GUID.generate is correctly implemented.


370-374: LGTM! The generation of unique identifiers for the reverse direction is correctly implemented.


159-160: Ensure correct handling of withdrawal amounts.

Verification successful

Ensure correct handling of withdrawal amounts.

The withdrawPrincipleFromExocore function is referenced in multiple files, including test/foundry/DepositWithdrawPrinciple.t.sol. The next step is to verify the implementation of this function to ensure it correctly handles withdrawal amounts.


Ensure correct handling of withdrawal amounts.

The withdrawPrincipleFromExocore function is implemented in src/core/LSTRestakingController.sol and src/core/Bootstrap.sol. We need to inspect these implementations to verify the correct handling of withdrawal amounts.


Ensure correct handling of withdrawal amounts.

The withdrawPrincipleFromExocore function implementations in src/core/Bootstrap.sol and src/core/LSTRestakingController.sol include checks for sufficient deposited and withdrawable balances, and validate token and amount. This indicates that the withdrawal amounts are correctly handled.

  • src/core/Bootstrap.sol:

    • Checks for sufficient deposited balance.
    • Checks for sufficient withdrawable balance.
  • src/core/LSTRestakingController.sol:

    • Validates token and amount.
    • Processes the withdrawal request.

These implementations ensure that withdrawal amounts are correctly handled.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the withdrawal amounts are correctly handled in the contract logic.

# Test: Search for the withdrawal logic. Expect: Correct handling of amounts.
rg --type solidity $'withdrawPrincipleFromExocore'

Length of output: 82



Script:

#!/bin/bash
# Description: Verify that the withdrawal amounts are correctly handled in the contract logic.

# Locate all Solidity files
fd --extension sol > sol_files.txt

# Search for the withdrawal logic in the located Solidity files
rg 'withdrawPrincipleFromExocore' $(cat sol_files.txt)

Length of output: 4331



Script:

#!/bin/bash
# Description: Verify the implementation of the withdrawPrincipleFromExocore function to ensure correct handling of withdrawal amounts.

# Search for the implementation of the withdrawPrincipleFromExocore function in Solidity files
rg 'function withdrawPrincipleFromExocore' $(cat sol_files.txt)

Length of output: 3296



Script:

#!/bin/bash
# Description: Retrieve the implementation details of the withdrawPrincipleFromExocore function to verify correct handling of withdrawal amounts.

# Extract the implementation of the withdrawPrincipleFromExocore function from the identified files
rg --context 10 'function withdrawPrincipleFromExocore' src/core/LSTRestakingController.sol src/core/Bootstrap.sol

Length of output: 3264


222-224: Ensure the calculation of activationTimestamp is correct.

Verification successful

The calculation of activationTimestamp appears to be consistent across the identified files. The formula used is:

uint256 activationTimestamp = BEACON_CHAIN_GENESIS_TIME +
    _getActivationEpoch(validatorContainer) *
    SECONDS_PER_EPOCH;

This calculation is used in multiple test functions to set up the environment for testing validator proofs. The logic seems to be correctly implemented as it consistently adds the product of the activation epoch and seconds per epoch to the beacon chain genesis time.

  • test/foundry/DepositWithdrawPrinciple.t.sol
  • test/foundry/ExoCapsule.t.sol

These occurrences show that the calculation is used to simulate the correct block environment states for proof validation.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the calculation of activationTimestamp.

# Test: Search for usage of `activationTimestamp`. Expect: Correct calculation.
rg --type solidity $'activationTimestamp'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify the calculation of activationTimestamp.

# Test: Search for usage of `activationTimestamp` in Solidity files.
rg --type sol $'activationTimestamp'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify the calculation of activationTimestamp.

# Test: Search for usage of `activationTimestamp` in Solidity files.
rg --type solidity $'activationTimestamp'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify the calculation of activationTimestamp.

# Step 1: Find all Solidity files.
sol_files=$(fd --extension sol)

# Step 2: Search for usage of `activationTimestamp` in the found Solidity files.
for file in $sol_files; do
    rg 'activationTimestamp' "$file"
done

Length of output: 11221



Script:

#!/bin/bash
# Description: Extract and review the relevant lines for `activationTimestamp` calculation.

# Extract lines from `test/foundry/DepositWithdrawPrinciple.t.sol`
echo "Occurrences in test/foundry/DepositWithdrawPrinciple.t.sol:"
rg --context 5 'activationTimestamp' test/foundry/DepositWithdrawPrinciple.t.sol

# Extract lines from `test/foundry/ExoCapsule.t.sol`
echo "Occurrences in test/foundry/ExoCapsule.t.sol:"
rg --context 5 'activationTimestamp' test/foundry/ExoCapsule.t.sol

Length of output: 5879

src/storage/BootstrapStorage.sol (11)

61-61: LGTM! The documentation for registeredOperators is clear and informative.


73-73: LGTM! The mapping for operators is well-documented and correctly implemented.


98-98: LGTM! The mapping for delegationsByOperator is correctly implemented and well-documented.


121-121: LGTM! The mapping for totalDepositAmounts is correctly implemented and well-documented.


130-130: LGTM! The mapping for withdrawableAmounts is correctly implemented and well-documented.


139-140: LGTM! The nested mapping for delegations is correctly implemented and well-documented.


Line range hint 277-291: LGTM! The event declaration for WithdrawPrincipleResult is clear and follows Solidity conventions.


304-308: LGTM! The event declaration for DelegateResult is clear and follows Solidity conventions.


321-325: LGTM! The event declaration for UndelegateResult is clear and follows Solidity conventions.


401-410: Ensure the constructor parameters are correctly validated.

Verification successful

The constructor parameters in BootstrapStorage are correctly validated.

  • The constructor in src/storage/BootstrapStorage.sol ensures that exocoreChainId_, vaultBeacon_, and beaconProxyBytecode_ are validated with require statements.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the constructor parameter validations.

# Test: Search for the constructor usage. Expect: Correct validations.
rg --type solidity $'constructor'

Length of output: 65



Script:

#!/bin/bash
# Description: Verify the constructor parameter validations.

# Test: Search for the constructor definition in Solidity files.
rg --type sol $'constructor'

# Test: Search for the usage of the constructor parameters to ensure they are correctly validated.
rg --type sol 'exocoreChainId_|vaultBeacon_|beaconProxyBytecode_'

Length of output: 151



Script:

#!/bin/bash
# Description: Verify the constructor parameter validations.

# Test: Search for the constructor definition in Solidity files.
rg --type solidity $'constructor'

# Test: Search for the usage of the constructor parameters to ensure they are correctly validated.
rg --type solidity 'exocoreChainId_|vaultBeacon_|beaconProxyBytecode_'

Length of output: 171



Script:

#!/bin/bash
# Description: Verify the constructor parameter validations.

# Test: Search for the constructor definition in Solidity files.
rg --glob '*.sol' $'constructor'

# Test: Search for the usage of the constructor parameters to ensure they are correctly validated.
rg --glob '*.sol' 'exocoreChainId_|vaultBeacon_|beaconProxyBytecode_'

Length of output: 3491


425-425: Ensure the isValidExocoreAddress function correctly validates addresses.

src/core/Bootstrap.sol (19)

114-115: Good use of custom modifiers to enforce contract state rules.

This is a good practice as it centralizes the locking logic, making the contract easier to maintain and less error-prone.


137-140: Consistent and clear error messages enhance contract usability.

The error messages provided in the require statements are clear and informative, which is crucial for debugging and user interaction.


206-227: Ensure all new operators have unique attributes.

The checks for unique address, name, and consensus public key are crucial for maintaining the integrity of the operator registry.


307-309: Validate the replacement of consensus public keys.

The checks ensure that the new key is not already in use and that the operator exists, which is essential for maintaining the integrity of the operator registry.


Line range hint 315-330: Ensure rate changes are within allowed limits.

The validation of rate changes against the maximum rate and change rate is a good practice to prevent abrupt changes that could affect stakeholders.


343-343: Validate token deposits correctly.

The method _validateAndGetVault correctly checks if the token is whitelisted and the amount is greater than zero, which are essential checks for deposit operations.


376-384: Ensure withdrawals do not exceed balances.

The checks for sufficient deposited and withdrawable balances are crucial to prevent unauthorized withdrawals.


405-405: Validate claims correctly.

The method claim correctly validates the token, amount, and recipient before processing the claim, ensuring the integrity of transactions.


412-423: Check delegation logic for consistency and security.

The delegation logic includes comprehensive checks for operator existence and sufficient balances, which are essential for secure and reliable operation.


433-444: Ensure undelegations are handled correctly.

The checks for existing delegations and sufficient balances are crucial to ensure that undelegations are processed correctly and securely.


501-501: Log updates to client chain gateway logic.

Logging changes to critical components like the client chain gateway logic is good practice for auditability and tracking.


509-509: Provide accurate operator count.

The method getOperatorsCount provides an accurate count of registered operators, which is essential for administrative and audit purposes.


518-518: Accurately report the number of depositors.

The method getDepositorsCount provides an accurate count of depositors, which is essential for understanding the scale of participation in the contract.


527-527: Report the number of whitelisted tokens accurately.

The method getWhitelistedTokensCount provides an accurate count of whitelisted tokens, which is crucial for managing token-related operations.


541-549: Ensure token information is retrieved correctly.

The method getWhitelistedTokenAtIndex correctly retrieves and returns detailed information about a token, ensuring transparency and accessibility of token data.


57-57: Validate the logical consistency of spawn time checks.

Verification successful

The occurrences of spawnTime_ in src/core/Bootstrap.sol are as follows:

  1. Declaration:

    uint256 spawnTime_,
  2. Check that spawnTime_ is greater than the current block timestamp:

    require(spawnTime_ > block.timestamp, "Bootstrap: spawn time should be in the future");
  3. Check that spawnTime_ is greater than offsetDuration_:

    require(spawnTime_ > offsetDuration_, "Bootstrap: spawn time should be greater than offset duration");
  4. Calculation of lockTime using spawnTime_ and offsetDuration_:

    uint256 lockTime = spawnTime_ - offsetDuration_;
  5. Assignment of spawnTime_ to exocoreSpawnTime:

    exocoreSpawnTime = spawnTime_;

The checks ensure that spawnTime_ is logically consistent:

  • It must be in the future relative to the current block timestamp.
  • It must be greater than offsetDuration_.

These conditions ensure that the subsequent calculations and assignments involving spawnTime_ are valid.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the spawn time logic is consistent across the contract.

# Test: Search for all occurrences of spawn time checks. Expect: Consistent logic.
rg --type solidity $'spawnTime_' 'src/core'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify that the spawn time logic is consistent across the contract.

# Test: Search for all occurrences of spawn time checks. Expect: Consistent logic.
rg 'spawnTime_' src/core

Length of output: 470


155-157: Check the logical flow of time-related conditions.

Verification successful

The search results indicate multiple instances of time-related conditions in the Bootstrap.sol file. The logical flow of these conditions appears consistent, as they all check that certain events should occur in the future relative to block.timestamp.

  • require(spawnTime_ > block.timestamp, "Bootstrap: spawn time should be in the future");
  • require(lockTime > block.timestamp, "Bootstrap: lock time should be in the future");
  • return block.timestamp >= exocoreSpawnTime - offsetDuration;
  • require(_spawnTime > block.timestamp, "Bootstrap: spawn time should be in the future");
  • require(lockTime > block.timestamp, "Bootstrap: lock time should be in the future");
  • require(lockTime > block.timestamp, "Bootstrap: lock time should be in the future");
  • require(block.timestamp >= exocoreSpawnTime, "Bootstrap: not yet in the bootstrap time");

These conditions ensure that the spawnTime and lockTime are appropriately set in the future, maintaining logical consistency.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the logical flow and consistency of time-related conditions throughout the contract.

# Test: Search for all time-related conditions. Expect: Logical and consistent conditions.
rg --type solidity $'block.timestamp' 'src/core'

Length of output: 78



Script:

#!/bin/bash
# Description: Verify the logical flow and consistency of time-related conditions throughout the contract.

# Test: Search for all time-related conditions. Expect: Logical and consistent conditions.
rg --type sol 'block.timestamp|now|block.number' src/core

Length of output: 87



Script:

#!/bin/bash
# Description: Verify the logical flow and consistency of time-related conditions throughout the contract.

# Test: Search for all time-related conditions. Expect: Logical and consistent conditions.
rg --type solidity 'block.timestamp|now|block.number' src/core

Length of output: 97



Script:

#!/bin/bash
# Description: Verify the logical flow and consistency of time-related conditions throughout the contract.

# Test: Search for all time-related conditions. Expect: Logical and consistent conditions.
rg --type sol 'block.timestamp|now|block.number' src/core

Length of output: 87



Script:

#!/bin/bash
# Description: Verify the logical flow and consistency of time-related conditions throughout the contract.

# Test: Search for all time-related conditions. Expect: Logical and consistent conditions.
rg 'block.timestamp|now|block.number' src/core/*.sol

Length of output: 1649


473-480: Verify the conditions for marking the contract as bootstrapped.

Verification successful

The markBootstrapped function in src/core/Bootstrap.sol includes the following conditions:

  • onlyCalledFromThis
  • whenNotPaused
  • require(block.timestamp >= exocoreSpawnTime, "Bootstrap: not yet in the bootstrap time")
  • require(!bootstrapped, "Bootstrap: already bootstrapped")

These conditions ensure that the function can only be called internally, the contract is not paused, the current time is past the exocoreSpawnTime, and the contract has not already been bootstrapped.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the conditions under which the contract is marked as bootstrapped.

# Test: Search for the usage of `markBootstrapped` in the contract. Expect: Correct and consistent conditions.
rg --type solidity $'markBootstrapped' 'src/core'

Length of output: 79



Script:

#!/bin/bash
# Description: Verify the conditions under which the contract is marked as bootstrapped.

# Test: Search for the usage of `markBootstrapped` in the contract. Expect: Correct and consistent conditions.
rg --type solidity 'markBootstrapped' 'src/core'

Length of output: 79



Script:

#!/bin/bash
# Description: Verify the conditions under which the contract is marked as bootstrapped.

# Test: Search for the usage of `markBootstrapped` in the contract. Expect: Correct and consistent conditions.
rg --type 'sol' 'markBootstrapped' 'src/core'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify the conditions under which the contract is marked as bootstrapped.

# Test: Search for the usage of `markBootstrapped` in the contract. Expect: Correct and consistent conditions.
rg --glob '*.sol' 'markBootstrapped' 'src/core'

Length of output: 258



Script:

#!/bin/bash
# Description: Retrieve the implementation of `markBootstrapped` in `src/core/Bootstrap.sol`.

# Test: Extract the function definition and its conditions.
ast-grep --lang solidity --pattern $'function markBootstrapped() public $_ {
  $$$
}' 'src/core/Bootstrap.sol'

Length of output: 226



Script:

#!/bin/bash
# Description: Retrieve the implementation of `markBootstrapped` in `src/core/Bootstrap.sol`.

# Test: Extract the function definition and its conditions.
rg 'function markBootstrapped' -A 10 'src/core/Bootstrap.sol'

Length of output: 790


79-79: Ensure the selector used is correct and intended.

test/foundry/Bootstrap.t.sol (15)

333-401: Check the error handling in test03_RegisterOperator_EthAlreadyRegistered.

Verification successful

The search results show multiple instances of vm.expectRevert across various test files, including Bootstrap.t.sol. This indicates that the error handling pattern using vm.expectRevert is consistently applied throughout the codebase.

  • test/foundry/Bootstrap.t.sol contains several instances of vm.expectRevert with different error messages, including the one in test03_RegisterOperator_EthAlreadyRegistered.

Given this consistency, the error handling in test03_RegisterOperator_EthAlreadyRegistered appears to be in line with the rest of the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure that the error handling in `test03_RegisterOperator_EthAlreadyRegistered` is consistent with other parts of the codebase.

# Test: Search for similar error handling patterns.
rg --type solidity 'expectRevert'

Length of output: 66



Script:

#!/bin/bash
# Description: Ensure that the error handling in `test03_RegisterOperator_EthAlreadyRegistered` is consistent with other parts of the codebase.

# Test: Search for similar error handling patterns in Solidity files.
rg 'expectRevert' --glob '*.sol'

Length of output: 6753


133-133: Check the usage of setDestLzEndpoint method.

Verification successful

The setDestLzEndpoint method is used in multiple places across the project, including the line in question. The method appears to be used consistently and correctly.

  • NonShortCircuitEndpointV2Mock(address(clientChainLzEndpoint)).setDestLzEndpoint(...)
  • NonShortCircuitEndpointV2Mock(address(exocoreLzEndpoint)).setDestLzEndpoint(...)
  • exocoreLzEndpoint.setDestLzEndpoint(address(clientGateway), address(clientLzEndpoint))
  • clientChainLzEndpoint.setDestLzEndpoint(undeployedExocoreGateway, undeployedExocoreLzEndpoint)

These usages indicate that the method is being called on various endpoint objects with appropriate parameters.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `setDestLzEndpoint` method is used correctly across the project.

# Test: Search for usage of `setDestLzEndpoint` to ensure it's used consistently.
rg --type solidity 'setDestLzEndpoint'

Length of output: 71



Script:

#!/bin/bash
# Description: Verify that the `setDestLzEndpoint` method is used correctly across the project.

# Find all Solidity files and search for the usage of `setDestLzEndpoint`.
fd -e sol -x rg 'setDestLzEndpoint' {}

Length of output: 933


652-679: Check the undelegation logic in test10_UndelegateFrom.


Line range hint 88-117: Review the initialization sequence in the setUp function.

Verification successful

The search results show that there are setUp functions in other test files, but they only contain calls to super.setUp(). This does not provide enough information to verify the initialization sequence in the setUp function of test/foundry/Bootstrap.t.sol.

To ensure a thorough verification, we need to gather more details about the initialization sequences in other test files. Specifically, we should look for any additional initialization logic within these setUp functions.


The search results reveal that other setUp functions in the Solidity test files contain various initialization steps, including setting up RPC URLs, reading deployed contract addresses, creating forks, and ensuring sufficient Ether balance. These steps are consistent with the initialization logic seen in the setUp function of test/foundry/Bootstrap.t.sol.

Given this consistency, the initialization sequence in the setUp function of test/foundry/Bootstrap.t.sol appears to follow similar patterns and best practices as other test files.

  • The initialization sequence includes setting up endpoints, creating contract instances, and initializing the Bootstrap contract with necessary parameters.
  • The use of TransparentUpgradeableProxy and abi.encodeCall for initializing the Bootstrap contract is a standard practice for upgradeable contracts.

Therefore, the initialization sequence in the setUp function seems to be secure and follows best practices.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the initialization sequence in the setUp function follows best practices and is secure.

# Test: Search for similar initialization patterns in other test files to ensure consistency.
fd --type file --extension sol 'test' --exec rg --type solidity 'setUp\(\)'

Length of output: 141



Script:

#!/bin/bash
# Description: Verify that the initialization sequence in the setUp function follows best practices and is secure.

# Test: Search for similar initialization patterns in other test files to ensure consistency.
fd --type file --extension sol 'test' --exec rg 'setUp\(\)'

Length of output: 199



Script:

#!/bin/bash
# Description: Gather more details about the initialization sequences in the setUp functions of Solidity test files.

# Search for the full implementation of setUp functions in Solidity test files.
fd --type file --extension sol 'test' --exec rg -A 20 'function setUp\(\)'

Length of output: 1956


602-610: Validate the error handling in test09_DelegateTo_Unregistered.

Verification successful

The search results show multiple instances of vm.expectRevert across various test files, including Bootstrap.t.sol. The error handling in test09_DelegateTo_TokenNotWhitelisted appears consistent with other parts of the codebase, as similar patterns of vm.expectRevert with specific error messages are used throughout the tests.

  • test/foundry/Bootstrap.t.sol: vm.expectRevert("Bootstrap: token is not whitelisted");
  • test/foundry/Bootstrap.t.sol: vm.expectRevert("Bootstrap: token should be not whitelisted before");
  • test/foundry/Bootstrap.t.sol: vm.expectRevert("Bootstrap: insufficient withdrawable balance");

These examples confirm that the error handling in test09_DelegateTo_TokenNotWhitelisted is consistent with the rest of the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Validate the error handling to ensure it's consistent with other parts of the codebase.

# Test: Search for similar error handling patterns.
rg --type solidity 'expectRevert'

Length of output: 66



Script:

#!/bin/bash
# Description: Validate the error handling to ensure it's consistent with other parts of the codebase.

# Test: Search for similar error handling patterns.
rg --type sol 'expectRevert'

Length of output: 56



Script:

#!/bin/bash
# Description: Validate the error handling to ensure it's consistent with other parts of the codebase.

# Test: Search for similar error handling patterns.
rg 'expectRevert' --glob '*.sol'

Length of output: 6753


Line range hint 834-850: Ensure the bootstrapping logic in test12_MarkBootstrapped is secure and follows best practices.


742-751: Review the withdrawal logic in test11_WithdrawPrincipleFromExocore.

Verification successful

The test11_WithdrawPrincipleFromExocore function and its related tests have been located and reviewed. The function appears to handle various edge cases, including token not whitelisted, zero amount, no deposits, and excess withdrawal attempts. This comprehensive testing suggests that the withdrawal logic is robust and secure.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Review the withdrawal logic to ensure it's secure and follows best practices.

# Test: Check for similar withdrawal logic in other test files.
fd --type file --extension sol 'test' --exec rg --type solidity 'withdrawPrincipleFromExocore'

Length of output: 158



Script:

#!/bin/bash
# Description: Review the withdrawal logic to ensure it's secure and follows best practices.

# Test: Check for similar withdrawal logic in other test files.
fd --type file --extension sol 'test' --exec rg 'withdrawPrincipleFromExocore'

Length of output: 76



Script:

#!/bin/bash
# Description: Locate and retrieve the implementation of the `test11_WithdrawPrincipleFromExocore` function for review.

# Locate the file containing the `test11_WithdrawPrincipleFromExocore` function.
fd --type file --extension sol --exec rg 'function test11_WithdrawPrincipleFromExocore' --context 10

Length of output: 3223


166-166: Ensure that setClientChainGatewayLogic is called with correct parameters.

Verification successful

Ensure that setClientChainGatewayLogic is called with correct parameters.

The search results show multiple instances of setClientChainGatewayLogic being called with the same parameters: address(clientGatewayLogic) and initialization. These instances are found in:

  • test/foundry/Bootstrap.t.sol
  • script/7_DeployBootstrap.s.sol
  • script/12_RedeployClientChainGateway.s.sol

Given that the parameters are consistent across different files, it suggests that the parameters used in the test file are likely correct.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `setClientChainGatewayLogic` method is called with the correct parameters.

# Test: Search for other usages of `setClientChainGatewayLogic` to compare parameter patterns.
rg --type solidity 'setClientChainGatewayLogic'

Length of output: 80



Script:

#!/bin/bash
# Description: Verify that the `setClientChainGatewayLogic` method is called with the correct parameters.

# Test: Search for other usages of `setClientChainGatewayLogic` to compare parameter patterns.
rg --type sol 'setClientChainGatewayLogic'

Length of output: 70



Script:

#!/bin/bash
# Description: Verify that the `setClientChainGatewayLogic` method is called with the correct parameters.

# Test: Search for other usages of `setClientChainGatewayLogic` to compare parameter patterns.
rg 'setClientChainGatewayLogic'

Length of output: 86169


864-889: Validate the commission validation logic in test14_IsCommissionValid.

Verification successful

The isCommissionValid function in src/core/Bootstrap.sol checks the following conditions for a commission to be valid:

  • commission.rate must be less than or equal to 1e18.
  • commission.maxRate must be less than or equal to 1e18.
  • commission.maxChangeRate must be less than or equal to 1e18.
  • commission.rate must be less than or equal to commission.maxRate.
  • commission.maxChangeRate must be less than or equal to commission.maxRate.

The tests in test/foundry/Bootstrap.t.sol validate these conditions by asserting the expected outcomes for various commission values.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Validate the commission validation logic to ensure it's robust.

# Test: Search for similar commission validation logic in other parts of the codebase.
rg --type solidity 'isCommissionValid'

Length of output: 71



Script:

#!/bin/bash
# Description: Locate Solidity files and search for the `isCommissionValid` function.

# Step 1: Find all Solidity files.
sol_files=$(fd --extension sol)

# Step 2: Search for `isCommissionValid` within the found Solidity files.
for file in $sol_files; do
    rg 'isCommissionValid' "$file"
done

Length of output: 10628



Script:

#!/bin/bash
# Description: Extract the `isCommissionValid` function from `src/core/Bootstrap.sol` for review.

# Step 1: Extract the `isCommissionValid` function.
ast-grep --lang solidity --pattern $'function isCommissionValid($_) $_' src/core/Bootstrap.sol

Length of output: 212



Script:

#!/bin/bash
# Description: Extract the `isCommissionValid` function from `src/core/Bootstrap.sol` for review.

# Step 1: Search for the `isCommissionValid` function definition.
rg 'function isCommissionValid' src/core/Bootstrap.sol -A 20

Length of output: 1067


Line range hint 453-489: Ensure the rate update logic in test06_UpdateRate is correct and secure.

Verification successful

The search results show multiple instances of the updateRate function being called and defined. To ensure the rate update logic in test06_UpdateRate is correct and secure, we need to examine the implementation of the updateRate function and its usage in the context of the tests.


The ast-grep tool does not support Solidity, which caused the failure in retrieving the function implementation. We need to use an alternative approach to extract the implementation details of the updateRate function.


The implementation of the updateRate function has been successfully retrieved. Here is the relevant portion of the code:

function updateRate(uint256 newRate) external beforeLocked whenNotPaused {
    string memory operatorAddress = ethToExocoreAddress[msg.sender];
    require(bytes(operatorAddress).length != 0, "no such operator exists");
    // across the lifetime of this contract before network bootstrap,
    // allow the editing of commission only once.
    require(!commissionEdited[operatorAddress], "Commission already edited once");
    Commission memory commission = operators[operatorAddress].commission;
    uint256 rate = commission.rate;
    uint256 maxRate = commission.maxRate;
    uint256 maxChangeRate = commission.maxChangeRate;
    // newRate <= maxRate <= 1e18
    require(newRate <= maxRate, "Rate exceeds max rate");
    // to prevent operators from blindsiding users by first registering at low rate and
    // subsequently increasing it, we should also check that the change is within the
    // allowed rate change.
    require(newRate <= rate + maxChangeRate, "Rate change exceeds max change rate");
    operators[operatorAddress].commission.rate = newRate;
    commissionEdited[operatorAddress] = true;
    emit OperatorCommissionUpdated(newRate);
}

This function includes several checks to ensure the rate update is secure and within allowed limits:

  • It verifies that the operator exists.
  • It ensures the commission can only be edited once.
  • It checks that the new rate does not exceed the maximum rate.
  • It ensures the rate change is within the allowed maximum change rate.

Given these checks, the logic in test06_UpdateRate appears to be consistent with the function's implementation.

  • The test registers an operator and updates the rate.
  • It verifies the new rate is set correctly.
  • It attempts to update the rate again, expecting a revert due to the "Commission already edited once" requirement.

This confirms that the rate update logic in test06_UpdateRate is correct and secure.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure the rate update logic is correct and secure.

# Test: Search for rate update logic in other parts of the codebase for consistency.
rg --type solidity 'updateRate'

Length of output: 64



Script:

#!/bin/bash
# Description: Ensure the rate update logic is correct and secure.

# Locate all Solidity files and search for the updateRate function within them.
fd -e sol -x rg 'updateRate' {}

Length of output: 379



Script:

#!/bin/bash
# Description: Retrieve the implementation of the updateRate function and its context.

# Locate the Solidity file containing the updateRate function definition.
fd -e sol -x rg 'function updateRate' {}

# Retrieve the implementation of the updateRate function.
ast-grep --lang solidity --pattern 'function updateRate($_) { $$$ }'

Length of output: 362



Script:

#!/bin/bash
# Description: Retrieve the implementation of the updateRate function and its context.

# Locate the Solidity file containing the updateRate function definition.
fd -e sol -x rg 'function updateRate' {}

# Extract the implementation of the updateRate function from the located file.
fd -e sol -x sed -n '/function updateRate/,/}/p' {}

Length of output: 2688


561-588: Review the delegation logic in test09_DelegateTo.


406-419: Validate the key replacement logic in test05_ReplaceKey.

Verification successful

The search results indicate that the replaceKey function is defined in src/interfaces/IOperatorRegistry.sol and src/core/Bootstrap.sol. Additionally, it is used multiple times in test/foundry/Bootstrap.t.sol.

To validate the key replacement logic in test05_ReplaceKey, we need to:

  1. Review the implementation of the replaceKey function in src/core/Bootstrap.sol.
  2. Ensure that the tests in test/foundry/Bootstrap.t.sol adequately cover the key replacement logic.

Let's start by examining the implementation of the replaceKey function in src/core/Bootstrap.sol.


The implementation of the replaceKey function in src/core/Bootstrap.sol is as follows:

function replaceKey(bytes32 newKey) external beforeLocked whenNotPaused {
    require(bytes(ethToExocoreAddress[msg.sender]).length != 0, "no such operator exists");
    require(!consensusPublicKeyInUse(newKey), "Consensus public key already in use");
    operators[ethToExocoreAddress[msg.sender]].consensusPublicKey = newKey;
    emit OperatorKeyReplaced(ethToExocoreAddress[msg.sender], newKey);
}

This function:

  1. Ensures the caller is a registered operator.
  2. Checks that the new key is not already in use.
  3. Updates the operator's consensus public key.
  4. Emits an event indicating the key replacement.

Given this implementation, the test in test/foundry/Bootstrap.t.sol should:

  1. Register an operator.
  2. Replace the operator's key.
  3. Verify that the key has been updated correctly.

The test snippet provided earlier already covers these steps. Therefore, the key replacement logic appears to be adequately tested.

  • test/foundry/Bootstrap.t.sol lines 406-419:
    • Registers an operator.
    • Replaces the operator's key.
    • Verifies the key replacement.

No further issues were found with the key replacement logic.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Validate the key replacement logic to ensure it's secure and follows best practices.

# Test: Check for similar key replacement logic in other test files.
fd --type file --extension sol 'test' --exec rg --type solidity 'replaceKey'

Length of output: 140



Script:

#!/bin/bash
# Description: Validate the key replacement logic to ensure it's secure and follows best practices.

# Test: Check for similar key replacement logic in other test files.
fd --type file --extension sol 'test' --exec rg 'replaceKey'

Length of output: 58



Script:

#!/bin/bash
# Description: Validate the key replacement logic to ensure it's secure and follows best practices.

# Step 1: Find the implementation of the `replaceKey` function.
ast-grep --lang solidity --pattern 'function replaceKey($_) { $$$ }'

# Step 2: Search for any other occurrences of `replaceKey` in the codebase.
rg 'replaceKey'

Length of output: 86357



Script:

#!/bin/bash
# Description: Retrieve the implementation of the `replaceKey` function in `src/core/Bootstrap.sol`.

# Step 1: Find the implementation of the `replaceKey` function.
rg 'function replaceKey' -A 20 src/core/Bootstrap.sol

Length of output: 1385


313-325: Review the registration of operators in test03_RegisterOperator.

Verification successful

The registerOperator function in src/core/Bootstrap.sol includes several checks to ensure the validity and uniqueness of the operator's address, name, and public key. It also verifies the commission's validity. The registerOperators function in script/integration/1_DeployBootstrap.s.sol appears to be a helper function for registering multiple operators with predefined values.

The registration logic in test03_RegisterOperator aligns with the system's requirements as it follows the same checks and validations defined in the registerOperator function.

  • src/core/Bootstrap.sol:

    • Ensures the address format is valid.
    • Ensures only one operator per Ethereum address.
    • Checks if the operator with the same Exocore address already exists.
    • Ensures the consensus key is unique.
    • Ensures the name is unique.
    • Checks the commission's validity.
  • script/integration/1_DeployBootstrap.s.sol:

    • Registers multiple operators with predefined values.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Review the registration logic for operators to ensure it aligns with the system's requirements.

# Test: Search for similar registration logic in other parts of the codebase.
rg --type solidity 'registerOperator'

Length of output: 70



Script:

#!/bin/bash
# Description: Review the registration logic for operators to ensure it aligns with the system's requirements.

# Find all Solidity files and search for the `registerOperator` function within them.
fd -e sol -x rg 'registerOperator' {}

Length of output: 1372



Script:

#!/bin/bash
# Description: Locate and review the definitions of `registerOperator` and `registerOperators` functions in Solidity files.

# Search for the definition of `registerOperator` function.
ast-grep --lang solidity --pattern 'function registerOperator($_, $_, $_, $_) { $$$ }'

# Search for the definition of `registerOperators` function.
ast-grep --lang solidity --pattern 'function registerOperators() { $$$ }'

Length of output: 398



Script:

#!/bin/bash
# Description: Locate and review the definitions of `registerOperator` and `registerOperators` functions in Solidity files.

# Search for the definition of `registerOperator` function.
rg 'function registerOperator' --type-add 'sol:*.sol' --type sol

# Search for the definition of `registerOperators` function.
rg 'function registerOperators' --type-add 'sol:*.sol' --type sol

Length of output: 428



Script:

#!/bin/bash
# Description: Extract and review the implementations of `registerOperator` and `registerOperators` functions.

# Extract the implementation of `registerOperator` from `src/core/Bootstrap.sol`.
rg 'function registerOperator' -A 20 src/core/Bootstrap.sol

# Extract the implementation of `registerOperator` from `src/interfaces/IOperatorRegistry.sol`.
rg 'function registerOperator' -A 20 src/interfaces/IOperatorRegistry.sol

# Extract the implementation of `registerOperators` from `script/integration/1_DeployBootstrap.s.sol`.
rg 'function registerOperators' -A 20 script/integration/1_DeployBootstrap.s.sol

Length of output: 3747


Line range hint 208-223: Validate the logic in the test02_Deposit function.

Verification successful

The test02_Deposit function in test/foundry/Bootstrap.t.sol appears to be correctly implemented, with thorough checks and balances for the deposit logic. The function ensures that the token balances and deposit amounts are accurately updated and verified.

  • The function distributes tokens to addresses and verifies the balances.
  • It then makes deposits and checks various values such as depositor count, token balances, and deposit amounts.
  • The logic includes assertions to ensure the correctness of the deposit process.

Given the detailed implementation and the presence of multiple related test functions, the logic in the test02_Deposit function seems consistent and well-validated.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Validate the deposit logic in the `test02_Deposit` function.

# Test: Check for similar deposit logic in other test files for consistency.
fd --type file --extension sol 'test' --exec rg --type solidity 'deposit'

Length of output: 137



Script:

#!/bin/bash
# Description: Validate the deposit logic in the `test02_Deposit` function.

# Test: Check for similar deposit logic in other test files for consistency.
fd --type file --extension sol 'test' --exec rg 'deposit'

Length of output: 474



Script:

#!/bin/bash
# Description: Validate the logic in the `test02_Deposit` function.

# Test: Search for the `test02_Deposit` function definition and its logic.
fd --type file --extension sol 'test' --exec rg 'function test02_Deposit'

Length of output: 73



Script:

#!/bin/bash
# Description: Validate the logic in the `test02_Deposit` function.

# Test: Search for all function definitions in the test files to locate the `test02_Deposit` function.
fd --type file --extension sol 'test' --exec rg 'function '

Length of output: 243



Script:

#!/bin/bash
# Description: Validate the logic in the `test02_Deposit` function.

# Test: Search for the `test02_Deposit` function in the `test/foundry/Bootstrap.t.sol` file.
rg 'function test02_Deposit' test/foundry/Bootstrap.t.sol

Length of output: 310



Script:

#!/bin/bash
# Description: Extract the full implementation of the `test02_Deposit` function.

# Test: Extract the full implementation of the `test02_Deposit` function in the `test/foundry/Bootstrap.t.sol` file.
ast-grep --lang solidity --pattern 'function test02_Deposit() { $$$ }' test/foundry/Bootstrap.t.sol

Length of output: 218



Script:

#!/bin/bash
# Description: Extract the full implementation of the `test02_Deposit` function.

# Test: Extract the full implementation of the `test02_Deposit` function in the `test/foundry/Bootstrap.t.sol` file.
rg -A 50 'function test02_Deposit()' test/foundry/Bootstrap.t.sol

Length of output: 6329


541-549: Check the validity checks for Exocore addresses in test08_ExocoreAddressIsValid.

src/core/CustomProxyAdmin.sol Show resolved Hide resolved
src/core/Bootstrap.sol Outdated Show resolved Hide resolved
src/core/Bootstrap.sol Outdated Show resolved Hide resolved
src/core/Bootstrap.sol Show resolved Hide resolved
src/core/Bootstrap.sol Show resolved Hide resolved
src/storage/ClientChainGatewayStorage.sol Outdated Show resolved Hide resolved
src/storage/ClientChainGatewayStorage.sol Show resolved Hide resolved
@adu-web3
Copy link
Collaborator

adu-web3 commented Jun 3, 2024

if I format the files with forge fmt, would it pass this check?

This way, we avoid repeating the token whitelisting code in `Bootstrap`
and `ClientChainGateway`.
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54dd5dc and 925bf36.

Files selected for processing (7)
  • .prettierrc (1 hunks)
  • src/core/Bootstrap.sol (19 hunks)
  • src/core/ClientChainGateway.sol (4 hunks)
  • src/interfaces/IClientChainGateway.sol (1 hunks)
  • src/storage/BootstrapStorage.sol (15 hunks)
  • src/storage/ClientChainGatewayStorage.sol (1 hunks)
  • test/foundry/ClientChainGateway.t.sol (3 hunks)
Files skipped from review as they are similar to previous changes (6)
  • .prettierrc
  • src/core/Bootstrap.sol
  • src/core/ClientChainGateway.sol
  • src/interfaces/IClientChainGateway.sol
  • src/storage/ClientChainGatewayStorage.sol
  • test/foundry/ClientChainGateway.t.sol
Additional comments not posted (9)
src/storage/BootstrapStorage.sol (9)

10-10: Added import for ITokenWhitelister.

This import is necessary for the contract to implement the ITokenWhitelister interface.


16-16: Contract now implements ITokenWhitelister.

This change aligns with the added import and the new functionalities related to token whitelisting.


62-62: Introduction of new mappings and arrays for managing operators and deposits.

These changes enhance the contract's ability to manage operator details and track deposits and delegations effectively.

Also applies to: 74-74, 99-99, 122-122, 131-131, 140-141


226-226: Clarification in the comment about the vaultBeacon.

The comment helps clarify the purpose and usage of vaultBeacon in the context of beacon proxies.


Line range hint 278-292: Addition of new events for deposit, withdrawal, delegation, and undelegation.

These events are crucial for tracking state changes on-chain and will aid in debugging and operational monitoring.

Also applies to: 305-309, 322-326


402-405: Introduction of new modifiers for checking whitelisted tokens, valid amounts, existing vaults, and valid Exocore addresses.

These modifiers add necessary checks that enhance the security and robustness of the contract's functions.

Also applies to: 407-410, 412-415, 417-423


425-434: Constructor now takes parameters for exocoreChainId, vaultBeacon, and beaconProxyBytecode.

These parameters are essential for setting up the contract with the correct external dependencies and identifiers.


449-449: Function to validate Exocore addresses.

This function is necessary to ensure that only valid Exocore addresses can interact with the contract.


480-507: Implementation of addWhitelistToken and removeWhitelistToken methods.

These methods are crucial for managing the list of whitelisted tokens, which is central to the contract's functionality.

@MaxMustermann2
Copy link
Collaborator Author

if I format the files with forge fmt, would it pass this check?

No, prettier and forge fmt conflict. I have removed prettier and moved everything to forge fmt.

@MaxMustermann2 MaxMustermann2 changed the title chore(ci): add Lint workflow chore(ci): add Format workflow Jun 3, 2024
@MaxMustermann2 MaxMustermann2 changed the title chore(ci): add Format workflow feat(ci): add fmt workflow Jun 3, 2024
.github/workflows/fmt.yml Outdated Show resolved Hide resolved
src/libraries/Endian.sol Outdated Show resolved Hide resolved
We now have a multi-job workflow, which means it will run the jobs in
parallel. Between jobs, we cache the artifacts generated by Foundry so
they can be reused. The artifacts cached are the result of compilation
by Foundry, and hence, they can be reused across jobs. The `build` job
is responsible for generating them, while the `test` and `fmt` jobs can
reuse them, which is why they `need` the `build` job.
...and do not let the cache key depend on the job name.
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 30cc514 and 0429b22.

Files selected for processing (2)
  • .github/workflows/forge-ci.yml (1 hunks)
  • foundry.toml (1 hunks)
Additional comments not posted (3)
.github/workflows/forge-ci.yml (3)

15-55: The build job configuration looks solid, using a specific Foundry version for stability and properly handling caching and build failures.


56-95: The test job configuration is consistent with the build job, using the same Foundry version and handling errors effectively.


97-136: The formatting job is well set up with forge fmt --check to ensure code style consistency. The error handling for formatting issues is proactive and helpful.

foundry.toml Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0429b22 and c256322.

Files selected for processing (2)
  • .github/workflows/forge-ci.yml (1 hunks)
  • .github/workflows/foundry-setup.yaml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/foundry-setup.yaml
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/forge-ci.yml

@bwhour bwhour requested a review from coderabbitai[bot] June 4, 2024 11:09
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c256322 and 2dc216b.

Files selected for processing (2)
  • .github/workflows/forge-ci.yml (1 hunks)
  • .github/workflows/foundry-setup.yml (1 hunks)
Additional comments not posted (4)
.github/workflows/foundry-setup.yml (1)

20-34: Setup job is well-configured with appropriate caching and environment setup.

.github/workflows/forge-ci.yml (3)

19-46: Build job is well-structured with appropriate failure handling and caching strategies.


57-93: Test job is correctly configured with verbose output for easier debugging and effective use of caching.


95-131: Formatting job is correctly set up to enforce code style consistency across the project.

.github/workflows/foundry-setup.yml Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2dc216b and bb1ab95.

Files selected for processing (3)
  • .github/workflows/forge-ci.yml (1 hunks)
  • .github/workflows/foundry-setup.yml (1 hunks)
  • .gitignore (1 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/forge-ci.yml
  • .github/workflows/foundry-setup.yml

@wewecalibrate
Copy link
Contributor

This will be only linting changes? Can we somehow open only 1 PR then? I think #16 and #17 are kinda duplicated. @MaxMustermann2 cc: @bwhour @adu-web3

Copy link
Collaborator

@adu-web3 adu-web3 left a comment

Choose a reason for hiding this comment

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

good jub!

@MaxMustermann2
Copy link
Collaborator Author

Superseded by #17

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