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: add interchain-security #157

Merged
merged 7 commits into from
Mar 10, 2024
Merged

feat: add interchain-security #157

merged 7 commits into from
Mar 10, 2024

Conversation

hoank101
Copy link
Collaborator

@hoank101 hoank101 commented Mar 9, 2024

  • Interchain v4 using sdk50, ibc8

Summary by CodeRabbit

  • New Features
    • Added interchain security modules (ccv) including ccvconsumer, ccvdistr, ccvgov, and `ccvstaking.
    • Implemented whitelisting functions for governance transactions.
    • Introduced a consumer section in the genesis file for enhanced testing capabilities.
  • Enhancements
    • Improved ante handler with new ConsumerKeeper for better module interactions.
    • Enhanced local development experience with updated start_local_node.sh script for the "eve" network.
  • Bug Fixes
    • Adjusted build commands and file paths in Makefile for better compatibility across different operating systems.
  • Documentation
    • Added comments and documentation in newly introduced functions and modules for clarity.

Copy link
Contributor

coderabbitai bot commented Mar 9, 2024

Walkthrough

The changes in this update focus on integrating new modules for interchain security, particularly enhancing consumer functionality within the blockchain network. These changes involve adjustments to module imports, keeper initializations, and genesis file manipulations for testing purposes. Additionally, modifications to the build process and local node setup scripts have been made to support these enhancements, improving the network's capabilities and testing environment.

Changes

File(s) Change Summary
Makefile Adjusted go build commands and output file paths for Windows and non-Windows systems.
app/ante.go, app/app.go Added imports and initialized ConsumerKeeper; introduced new modules for interchain security.
app/export.go, app/test_support.go Updated StakingKeeper references to pointers.
app/proposals_whitelisting.go Added functions for governance transaction whitelisting.
cmd/consumer.go, cmd/eved/main.go Enhanced genesis file manipulation for testing and added new command functionality.
scripts/start_local_node.sh Updated local node setup script for the "eve" network.
testutil/consumer.go Introduced function to create minimal consumer genesis state.

Related issues

  • Interchain Security #123: This PR seems to address the objective of integrating support for interchain security as mentioned in the issue, by introducing new modules and functionalities related to cosmos/interchain-security.

Poem

In the realm of bytes and dreams so bright,
A rabbit danced through the code's starlight.
🌟 Across chains it weaved with grace,
Binding worlds in a secure embrace.
"To safeguard the links," it softly spoke,
Leaving a trail of trust, unbroken and bespoke.
🚀 In the blockchain's tapestry, a story unfurled,
Of security and strength in a digital world.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@faddat
Copy link
Contributor

faddat commented Mar 9, 2024

Yoooo omg that was fast.

Great work!


sed -i -E "s|chain-id = \"\"|chain-id = \"${CHAIN_ID}\"|g" $client_toml
sed -i -E "s|keyring-backend = \"os\"|keyring-backend = \"test\"|g" $client_toml
sed -i -E "s|node = \".*\"|node = \"tcp://localhost:26657\"|g" $client_toml

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
Copy link
Contributor

Choose a reason for hiding this comment

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

oh, interesting test approach.

@faddat
Copy link
Contributor

faddat commented Mar 9, 2024

so this commit angers the go mod gods I think

@hoank101 hoank101 marked this pull request as ready for review March 9, 2024 17:00
@hoank101
Copy link
Collaborator Author

hoank101 commented Mar 9, 2024

now it work ok, but need fix test ci

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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 73bc03e and 2146004.
Files ignored due to path filters (2)
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
Files selected for processing (10)
  • Makefile (1 hunks)
  • app/ante.go (3 hunks)
  • app/app.go (23 hunks)
  • app/export.go (1 hunks)
  • app/proposals_whitelisting.go (1 hunks)
  • app/test_support.go (1 hunks)
  • cmd/consumer.go (1 hunks)
  • cmd/eved/main.go (2 hunks)
  • scripts/start_local_node.sh (1 hunks)
  • testutil/consumer.go (1 hunks)
Additional comments: 20
cmd/eved/main.go (3)
  • 5-6: The addition of the cmd package from github.com/eve-network/eve/cmd and its usage in adding a new command to rootCmd is a significant change. This likely introduces new functionality or alters the behavior of the application's command-line interface. Ensure that the new command is well-documented and tested, especially since command-line interfaces are a critical part of user interaction.
Verification successful

The addition of the cmd package from github.com/eve-network/eve/cmd and its usage in adding a new command to rootCmd has been verified. The AddConsumerSectionCmd function is indeed present and documented within the cmd/consumer.go file. The documentation clearly states that the command is intended "ONLY FOR TESTING PURPOSES!" and describes its functionality. This addresses the initial concern about ensuring that the new command is well-documented and tested.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the existence and documentation of the new command in the cmd package.
fd --type f --exec grep -Hn "AddConsumerSectionCmd" {}

Length of output: 235



Script:

#!/bin/bash
# Extract comments/documentation for the AddConsumerSectionCmd function in cmd/consumer.go
fd consumer.go --exec grep -B 3 -A 10 "func AddConsumerSectionCmd" {}

Length of output: 668

* 15-15: Adding a new command `AddConsumerSectionCmd` to `rootCmd` is a clear indication of extending the CLI's functionality. It's crucial to ensure that this command is accompanied by adequate documentation and help text within the CLI to assist users in understanding its purpose and usage.

Consider adding a comment above the AddCommand line briefly explaining the purpose of the new command for future maintainability.

  • 18-18: The error handling in the main function has been adjusted to use log.NewLogger(rootCmd.OutOrStderr()).Error for logging errors. This is a good practice as it ensures that errors are logged in a consistent manner across the application. However, ensure that the logger is configured correctly elsewhere in the application to handle these error logs appropriately, especially in terms of log levels and destinations (e.g., file, stdout).
app/test_support.go (1)
  • 32-32: Changing the return type of GetStakingKeeper to return a pointer to StakingKeeper is a significant change that affects how the StakingKeeper is accessed and modified. This change likely aims to ensure that modifications to the StakingKeeper within test cases are reflected globally within the test context. Ensure that all usages of GetStakingKeeper have been updated to handle a pointer return type correctly to avoid nil pointer dereferences or unintended behavior.
testutil/consumer.go (1)
  • 13-32: The function CreateMinimalConsumerTestGenesis sets up a minimal genesis state for consumer tests, including enabling the consumer, setting it as a new chain, and configuring the provider client state and consensus state. This is a crucial function for testing interchain security features. Ensure that the values set here, such as ChainId, TrustingPeriod, and UnbondingPeriod, are aligned with the expected test scenarios. Additionally, consider handling the panic more gracefully in a testing context, perhaps by returning an error instead, to improve test debuggability and maintainability.

Consider replacing panic with error returns to allow test cases to handle initialization failures more gracefully.

scripts/start_local_node.sh (1)
  • 1-65: The script start_local_node.sh includes various configuration adjustments and the addition of a consumer section to the genesis for testing purposes. It's important to ensure that these changes are well-documented within the script, especially the purpose and impact of the new consumer section. Additionally, consider the security implications of hardcoded mnemonics within the script. While likely intended for local testing, ensure that such practices are clearly flagged as unsafe for production environments.

Add comments within the script explaining the purpose and usage of each section, especially the new consumer section. Additionally, add a warning comment regarding the hardcoded mnemonics, advising against their use in production environments.

app/ante.go (3)
  • 8-9: The addition of imports for consumerante and ccvconsumerkeeper indicates new functionality related to interchain security being integrated into the ante handler. This is a significant change that enhances the application's capability to handle transactions related to interchain security. Ensure that these new dependencies are well-maintained and secure, as they play a crucial role in the application's transaction processing pipeline.
Verification successful

The information provided from the GitHub repository for cosmos/interchain-security indicates that the project is well-maintained and secure. It has active measures in place for monitoring and improving code quality and security, as evidenced by the SonarCloud badges for Security Rating, Vulnerabilities, Bugs, and Coverage. The project is described as a working and in-production implementation of the Replicated Security protocol, further supporting its reliability and ongoing maintenance. This aligns with the initial review comment on the importance of integrating secure and well-maintained dependencies related to interchain security into the application's transaction processing pipeline.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the security and maintenance status of the new dependencies.
gh repo view github.com/cosmos/interchain-security

Length of output: 3165

* 28-28: Introducing `ConsumerKeeper` in the `HandlerOptions` struct is a key change that enables the ante handler to interact with the consumer functionality of interchain security. This integration is crucial for ensuring that transactions related to interchain security are handled appropriately. Ensure that the `ConsumerKeeper` is properly initialized and used throughout the application to maintain consistency and security.
Verification successful

To further verify the usage of ConsumerKeeper throughout the application, beyond its initialization, I will generate a new shell script to search for references to ConsumerKeeper. This will help confirm that it's being utilized as intended for interacting with the consumer functionality of interchain security.


The verification process confirms that ConsumerKeeper is properly initialized and extensively used throughout the application, particularly in app.go and ante.go. This includes its initialization, setting up modules, passing it as a parameter, and calling methods on it, which aligns with the importance of ConsumerKeeper for interacting with the consumer functionality of interchain security as mentioned in the review comment. Therefore, the review comment is accurate in highlighting the key change and its implications for the application's consistency and security.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that ConsumerKeeper is properly initialized and used where necessary.
ast-grep --lang go --pattern $'ConsumerKeeper'

Length of output: 108



Script:

#!/bin/bash
# Search for references to ConsumerKeeper beyond its initialization to verify its usage.
rg "ConsumerKeeper" --vimgrep

Length of output: 1521

* 63-63: The use of `consumerante.NewDisabledModulesDecorator` to initialize `ConsumerKeeper` in `NewAnteHandler` suggests a specific configuration for handling transactions related to disabled modules. This approach is important for ensuring that transactions are processed according to the application's security and operational requirements. Review the configuration of `NewDisabledModulesDecorator` to ensure it aligns with the intended security policies and operational practices.
Verification successful

The verification process has confirmed the usage of consumerante.NewDisabledModulesDecorator within app/ante.go, specifically with the parameters "/cosmos.evidence" and "/cosmos.slashing". This aligns with the initial review comment regarding the importance of reviewing the configuration of NewDisabledModulesDecorator to ensure it matches the intended security policies and operational practices. The provided context from the script output directly supports the review comment's suggestion to verify the configuration and usage of NewDisabledModulesDecorator.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the configuration and usage of NewDisabledModulesDecorator.
ast-grep --lang go --pattern $'NewDisabledModulesDecorator'

Length of output: 58



Script:

#!/bin/bash
# Use ripgrep to search for the usage of NewDisabledModulesDecorator in the codebase.
rg 'NewDisabledModulesDecorator'

Length of output: 128

cmd/consumer.go (1)
  • 26-88: The introduction of the add-consumer-section command in consumer.go is a significant addition aimed at facilitating testing by modifying the genesis state to include a consumer section. This command appears to be designed for internal testing purposes, as indicated by the comment on line 32. It's crucial to ensure that this command is not accessible or misused in production environments, given its potential impact on the genesis state. Additionally, consider adding more detailed documentation within the code and in user-facing documentation to clarify its intended use and the implications of its execution.

Add a warning in the command's help text and documentation emphasizing that it is intended for testing purposes only and should not be used in production environments.

Makefile (1)
  • 86-100: The modifications in the Makefile to remove the -mod=readonly flag from go build commands and adjust output file paths for eved and contract_tests targets are important for the build process. Removing -mod=readonly increases flexibility in handling dependencies during the build, but it also introduces the risk of unintended modifications to the go.mod and go.sum files. Ensure that the build process remains reproducible and that any changes to dependencies are intentional and reviewed. Additionally, the adjustments to output file paths should be verified to ensure that they align with the project's directory structure and deployment practices.
app/export.go (1)
  • 43-43: Changing the argument passed to staking.WriteValidators from a value to a pointer (&app.StakingKeeper) in the ExportAppStateAndValidators function is a critical change that affects how the StakingKeeper is accessed and potentially modified. This change likely aims to ensure that any modifications made within WriteValidators are reflected in the original StakingKeeper. It's important to ensure that this change does not introduce unintended side effects, especially in terms of state mutation during the export process.
app/app.go (8)
  • 40-45: The addition of new imports for ccvconsumer, ccvdistr, ccvgov, and ccvstaking modules is necessary for the integration of interchain security features. These changes are correctly implemented.
  • 176-177: The addition of module account permissions for ccvconsumer related accounts (ConsumerRedistributeName, ConsumerToSendToProviderName) is correctly implemented and necessary for the operation of the new modules.
  • 234-234: The declaration of ConsumerKeeper as ccvconsumerkeeper.Keeper is correctly implemented and necessary for the operation of the ccvconsumer module.
  • 241-241: The declaration of ScopedCCVConsumerKeeper as capabilitykeeper.ScopedKeeper is correctly implemented and necessary for capability management within the ccvconsumer module.
  • 708-712: The addition of new modules (ccvgov, ccvdistr, ccvstaking) to the module manager is correctly implemented. These changes are necessary for integrating the functionality of the ccv modules into the application.
  • 494-494: The inclusion of the ConsumerKeeper in the IBCKeeper initialization is correctly implemented and necessary for enabling interchain security features that involve IBC.
  • 544-544: The inclusion of the ConsumerKeeper in the EvidenceKeeper initialization is correctly implemented and necessary for handling evidence related to the ccvconsumer module.
  • 553-571: The comprehensive reinitialization of the ConsumerKeeper with a full set of parameters and keepers is correctly implemented and necessary for the correct operation of the ccvconsumer module.

Comment on lines +439 to +443
app.ConsumerKeeper = ccvconsumerkeeper.NewNonZeroKeeper(
appCodec,
keys[ccvconsumertypes.StoreKey],
app.GetSubspace(ccvconsumertypes.ModuleName),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The ConsumerKeeper is initialized twice, which seems to be an oversight. The first initialization as NonZeroKeeper should be removed, and the second, more comprehensive initialization should be kept to ensure correct operation of the module.

- app.ConsumerKeeper = ccvconsumerkeeper.NewNonZeroKeeper(
-   appCodec,
-   keys[ccvconsumertypes.StoreKey],
-   app.GetSubspace(ccvconsumertypes.ModuleName),
- )

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
app.ConsumerKeeper = ccvconsumerkeeper.NewNonZeroKeeper(
appCodec,
keys[ccvconsumertypes.StoreKey],
app.GetSubspace(ccvconsumertypes.ModuleName),
)

Comment on lines +9 to +11
func IsModuleWhiteList(typeUrl string) bool {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The function IsModuleWhiteList always returns true, indicating that all transactions are considered whitelisted. While this might be intended for simplicity or specific use cases, it's important to consider the security implications of such an approach. Whitelisting all transactions without any checks can potentially open up the system to unwanted or harmful transactions.

Consider implementing actual whitelisting logic based on typeUrl to ensure only safe and intended transactions are allowed.

Comment on lines +15 to +17
func IsProposalWhitelisted(content govv1beta1.Content) bool {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to IsModuleWhiteList, the function IsProposalWhitelisted also always returns true, indicating a blanket whitelisting approach for proposals. This could lead to security risks if harmful proposals are submitted and executed without any checks.

Implement validation logic within IsProposalWhitelisted to ensure only proposals that meet certain criteria are whitelisted, enhancing the security and integrity of the governance process.

@hoank101 hoank101 requested a review from faddat March 9, 2024 17:11
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2146004 and 19f979c.
Files selected for processing (1)
  • cmd/eved/main.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cmd/eved/main.go

@hoank101 hoank101 enabled auto-merge March 9, 2024 17:13
@hoank101 hoank101 disabled auto-merge March 9, 2024 17:13
@faddat
Copy link
Contributor

faddat commented Mar 9, 2024

You know that this is the fastest I've ever seen anyone do something similar, ever?

@hoank101 hoank101 merged commit 6905b9f into main Mar 10, 2024
8 checks passed
@hoank101 hoank101 deleted the hoa/interchain-security branch March 10, 2024 09:20
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.

2 participants