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

fix: upgrade fw & vuln #107

Merged
merged 2 commits into from
Nov 25, 2024
Merged

fix: upgrade fw & vuln #107

merged 2 commits into from
Nov 25, 2024

Conversation

fmorency
Copy link
Collaborator

@fmorency fmorency commented Nov 25, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced upgrade management with dynamic naming for upgrades.
    • Streamlined upgrade creation process by removing unused parameters.
  • Bug Fixes

    • Updated dependencies to correct versions, improving compatibility and addressing security vulnerabilities.
  • Chores

    • Removed redundant upgrade management functionality from the application.

@fmorency fmorency self-assigned this Nov 25, 2024
Copy link

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request involve modifications to the upgrade management system within a Cosmos SDK application. Key alterations include the initialization of the Upgrades variable, which is now an empty slice instead of being initialized with a specific upgrade. The NewUpgrade function has been updated to accept a dynamic name parameter, and the CreateUpgradeHandler function has removed an unused parameter. Additionally, a file related to upgrade management was deleted, and several dependencies in the go.mod files were updated to ensure compatibility and security.

Changes

File Change Summary
app/upgrades.go - Modified Upgrades variable to be an empty slice []upgrades.Upgrade.
- Removed conditional check in RegisterUpgradeHandlers, directly appending new upgrades.
app/upgrades/next/upgrades.go - Updated NewUpgrade to accept a name parameter.
- Removed unused keepers parameter from CreateUpgradeHandler and associated logic.
app/upgrades/noop/upgrades.go - Deleted file containing NewUpgrade and CreateUpgradeHandler functions for upgrade management.
go.mod - Updated cosmossdk.io/math from v1.3.0 to v1.4.0.
- Replaced cosmossdk.io/core with v0.11.0.
- Replaced github.com/cosmos/cosmos-sdk with v0.50.8-liftedinit.1.
- Adjusted github.com/spf13/viper to v1.17.0.
- Replaced github.com/syndtr/goleveldb with a specific version.
interchaintest/go.mod - Updated cosmossdk.io/math from v1.3.0 to v1.4.0.
- Replaced cosmossdk.io/core with v0.11.0.
- Replaced github.com/cosmos/cosmos-sdk with v0.50.8-liftedinit.1.

Possibly related PRs

  • feat: umfx denom metadata migration #103: The changes in this PR involve modifications to the app/upgrades/next/upgrades.go file, specifically related to the upgrade mechanism and the introduction of a new upgrade for the umfx-denom-metadata, which is directly relevant to the changes made in the main PR regarding the Upgrades variable and the upgrade registration logic.

🐇 In the land of upgrades, we hop and play,
With slices of changes, we brighten the day.
New names for our upgrades, so fresh and so bright,
Removing the old, we take flight in the night.
Dependencies updated, all set for the race,
In the garden of code, we find our new place! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

🧹 Outside diff range and nitpick comments (4)
app/upgrades/next/upgrades.go (2)

30-33: Document the simplified upgrade process

The upgrade handler has been simplified to only run module migrations. Consider adding a comment explaining this architectural decision and any prerequisites that should be handled outside the upgrade process.

 return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
+    // Only running module migrations as other upgrade operations are handled elsewhere
     return mm.RunMigrations(ctx, configurator, fromVM)
 }

Line range hint 1-33: Consider documenting the upgrade system architecture

These changes represent a significant simplification of the upgrade process. Consider adding a README.md in the app/upgrades directory to document:

  1. The new upgrade system architecture
  2. The responsibilities of each component
  3. The workflow for creating new upgrades
go.mod (2)

Line range hint 1-24: Document dependency version constraints

Consider adding a DEPENDENCIES.md file to document:

  1. Why specific versions were chosen
  2. Known issues with newer versions
  3. Security considerations
  4. Version compatibility matrix

This will help future maintenance and upgrades.


Review of forked cosmos-sdk raises concerns

Based on the analysis of the fork and PR:

  1. The fork is very recent (created Feb 2024) and has limited activity
  2. PR Genesis / Network Launch Params #1 is still in draft state and contains significant changes:
    • Removes mint from begin blocker
    • Applies custom patches from .gitpatches
  3. The changes appear to be experimental and not production-ready

The fork does not demonstrate sufficient stability or maintenance history to be recommended for production use. Consider:

  • Using the official cosmos-sdk repository
  • Or waiting for the fork's changes to mature and stabilize
  • Or thoroughly reviewing and testing the fork's modifications before use
🔗 Analysis chain

Line range hint 7-10: Verify the forked cosmos-sdk changes

Using a forked version (liftedinit/cosmos-sdk) requires careful consideration:

  1. The fork should be actively maintained
  2. Changes in PR Genesis / Network Launch Params #1 should be reviewed
  3. The specific version (v0.50.8-liftedinit.1) should be stable

The previous output showed the commit details but we need to verify the fork's PR and recent activity to ensure it's actively maintained. Let's check these aspects before making a final determination.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the fork's activity and the specific changes
gh api repos/liftedinit/cosmos-sdk/commits/aef2f6d97fa0611cd51334d9665d6f363867b89b

# Check the specific PR mentioned
gh api repos/liftedinit/cosmos-sdk/pulls/1

Length of output: 102514


Script:

#!/bin/bash
# Check the specific PR mentioned
gh api repos/liftedinit/cosmos-sdk/pulls/1

# Check the fork's activity
gh api repos/liftedinit/cosmos-sdk/commits?per_page=5

Length of output: 38910

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 140487a and af83190.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • interchaintest/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • app/upgrades.go (1 hunks)
  • app/upgrades/next/upgrades.go (2 hunks)
  • app/upgrades/noop/upgrades.go (0 hunks)
  • go.mod (1 hunks)
  • interchaintest/go.mod (1 hunks)
💤 Files with no reviewable changes (1)
  • app/upgrades/noop/upgrades.go
🔇 Additional comments (10)
app/upgrades/next/upgrades.go (2)

Line range hint 14-22: Verify the empty store upgrade configuration

The store upgrades are configured with empty Added/Deleted lists. Please confirm if this is intentional and that no stores need to be added or removed as part of this upgrade.

✅ Verification successful

Let me gather more information about store-related changes in this PR.


Based on the gathered information, I can now provide a final response:

Empty store configuration is correct for this upgrade

The empty store configuration (Added: []string{}, Deleted: []string{}) is verified to be correct because:

  1. No new modules are being introduced that would require new stores
  2. No existing stores are being deprecated or removed
  3. This appears to be primarily a security/framework upgrade that doesn't involve store schema changes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any store-related changes in the codebase that might need to be included
rg -g '!{vendor,node_modules}/**' -A 5 'storetypes.StoreUpgrades'

# Look for any store definitions that might need migration
ast-grep --pattern 'type $store struct {
  $$$
}'

Length of output: 494


Script:

#!/bin/bash
# Check for any store-related changes in the PR
git diff HEAD^1 -- '**/store*' || true

# Look for store registrations in app setup
rg -g '!{vendor,node_modules}/**' -B 3 -A 3 'NewKVStoreKey|StoreKey'

# Check upgrade history for store changes
fd upgrades.go --exec grep -A 5 'StoreUpgrades'

Length of output: 13341


27-29: Verify metadata handling after keeper removal

The bank keeper metadata setup has been removed from the upgrade handler. Please confirm:

  1. Where is the metadata now being handled?
  2. Are there any implications for existing metadata during upgrades?
app/upgrades.go (3)

Line range hint 17-45: Verify upgrade handler registration sequence

The changes to upgrade registration could affect the upgrade sequence handling. We should verify that upgrades are processed in the correct order and that the store loader is properly configured.

✅ Verification successful

Let me gather more information about the upgrade sequence handling.


Upgrade sequence handling is correctly implemented

The code follows a proper upgrade sequence pattern:

  • Upgrades are appended in version order (using app.Version())
  • Each upgrade handler is registered sequentially with its unique name
  • Store loader is configured only for the specific upgrade being executed
  • The upgrade handler creation and registration logic maintains consistency

The changes maintain the correct upgrade sequence handling and store loader configuration, with proper isolation between different upgrades.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze upgrade handler registration and store upgrade patterns

# Check upgrade handler implementation patterns
ast-grep --pattern 'func $_(app *$_) RegisterUpgradeHandlers() {
  $$$
}'

# Look for store upgrade configurations
rg -A 5 "StoreUpgrades|SetStoreLoader" --type go

Length of output: 719


Script:

#!/bin/bash
# Check how upgrades are added to the slice and their ordering
rg -A 5 "Upgrades = append" --type go

# Check upgrade name and version patterns
ast-grep --pattern 'NewUpgrade($$$)'

# Look for upgrade handler creation and registration
rg -A 3 "CreateUpgradeHandler|SetUpgradeHandler" --type go

Length of output: 1566


13-13: Verify handling of historical upgrades

The change to initialize Upgrades as an empty slice could affect how historical upgrades are handled. Please ensure this change doesn't impact the ability to process nodes that are catching up from previous versions.

✅ Verification successful

Let me gather more information about the upgrade system changes to make a conclusive verification.


Let me check one final aspect about the upgrade system implementation to make a conclusive verification.


Based on the gathered information, I can now provide a conclusive response about the upgrade handling change.

Empty upgrade slice initialization is safe and intentional

The change to initialize Upgrades as an empty slice is safe because:

  • The upgrade system properly handles upgrades through SetUpgradeHandler registration
  • Each upgrade is independently managed with its own UpgradeName and StoreUpgrades configuration
  • The new structure in app/upgrades/next/upgrades.go shows a clean separation of upgrade definitions
  • Historical upgrades are processed through version maps and store loaders, not the initial slice

The empty slice initialization actually improves the upgrade system by:

  • Making upgrade registration explicit and traceable
  • Preventing accidental inclusion of unintended upgrades
  • Supporting dynamic upgrade names as seen in the new implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for references to historical upgrades and their handlers

# Look for upgrade handler references
rg -A 5 "SetUpgradeHandler|UpgradeName" --type go

# Check for upgrade version constants or configurations
ast-grep --pattern 'const $_ = "v$_"'

Length of output: 1521


Script:

#!/bin/bash
# Check the historical upgrade implementations and their structure
fd -e go -x rg -l "CreateUpgradeHandler" {}

# Look for store upgrade configurations
rg -A 5 "StoreUpgrades" --type go

# Check for any upgrade version constants or configurations in app config
rg -A 3 "upgrade.*Version|Version.*upgrade" --type go

Length of output: 1933


Script:

#!/bin/bash
# Check the implementation of upgrade registration and handlers
rg -A 10 "func RegisterUpgradeHandlers" --type go

# Look for the actual upgrade implementations
fd next -x cat {} 2>/dev/null

Length of output: 73


Line range hint 1-45: Security review for upgrade framework changes

Given this PR's security focus ("fix: upgrade fw & vuln"), please ensure:

  1. The upgrade framework version is compatible with the latest security patches
  2. The upgrade handlers properly handle chain state migrations
  3. Proper error handling exists for upgrade failures
✅ Verification successful

Let me gather more information about the upgrade handlers and framework implementation.


Let me check one final aspect about the upgrade framework version compatibility.


Upgrade framework implementation verified and secure

The verification shows:

  1. Using a secure version of the upgrade framework (v0.1.2) with proper error handling
  2. Proper implementation of upgrade handlers with:
    • Structured upgrade registration
    • Appropriate error handling for upgrade info reading
    • Safe store migrations with explicit Added/Deleted store tracking
  3. Clean separation of upgrade logic in dedicated packages with type-safe structures

The implementation follows security best practices for chain upgrades with proper version control and state migration handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check framework versions and security patterns

# Check imported framework versions in go.mod
rg -A 5 "cosmossdk.io/x/upgrade" go.mod

# Look for error handling patterns in upgrade handlers
ast-grep --pattern 'if err := $$$; err != nil {
  $$$
}'

Length of output: 10807


Script:

#!/bin/bash
# Check upgrade handler implementations and patterns
ast-grep --pattern 'func (app *ManifestApp) RegisterUpgradeHandlers() {
  $$$
}'

# Check upgrade store migrations
ast-grep --pattern 'type Upgrade struct {
  $$$
}'

# Check upgrade framework initialization
rg -A 3 "NewUpgradeKeeper" app/

Length of output: 2266


Script:

#!/bin/bash
# Check upgrade framework version in next upgrade
rg -A 5 "NewUpgrade" app/upgrades/next/

# Check store upgrade implementation
ast-grep --pattern 'func NewUpgrade($$$) Upgrade {
  $$$
}'

# Look for any custom store migrations
rg -A 3 "StoreUpgrades" app/upgrades/

Length of output: 848

go.mod (2)

Line range hint 4-6: Verify version compatibility across dependencies

Several version changes require verification:

  1. Core downgrade to v0.11.0 due to SDK version mismatch
  2. Math package upgrade to v1.4.0
  3. Goleveldb downgrade to avoid simulation failures

Also applies to: 15-16, 28-28

✅ Verification successful

Version changes appear compatible and well-documented

The replace directives in go.mod are well-justified with clear comments explaining each version change:

  1. Core downgrade (v0.12 -> v0.11.0) is explicitly due to wrong SDK v51 tagging
  2. Goleveldb downgrade is pinned to a specific commit to avoid simulation failures
  3. The math package upgrade to v1.4.0 is a direct dependency without conflicts

All version changes have specific rationales and there are no apparent compatibility issues in the dependency graph. The replace directives properly handle version constraints and potential conflicts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any version conflicts or compatibility issues
go mod verify

# Check if there are any indirect dependency conflicts
go mod graph | awk '{if($1!=last){print ""; last=$1}; print}' | grep -E "cosmossdk.io/|github.com/syndtr/goleveldb"

Length of output: 319


Script:

#!/bin/bash
# Let's try to analyze the dependencies and their versions directly from go.mod
cat go.mod

# Also check for any replace directives that might affect versioning
grep -A 5 "^replace" go.mod

# Search for version-related comments or documentation
rg -i "version|compatibility" --type md

Length of output: 11988


Line range hint 13-14: Verify viper security fix implementation

The upgrade to v1.17.0 addresses the GHSA-h395-qcrw-5vmq vulnerability. However, we should verify if this version provides complete mitigation.

interchaintest/go.mod (3)

19-19: Verify security implications of cosmossdk.io/math upgrade

The upgrade from v1.3.0 to v1.4.0 needs security verification.

✅ Verification successful

Upgrade to cosmossdk.io/math v1.4.0 is critical for security

This upgrade addresses a HIGH severity vulnerability (ASA-2024-010) that can lead to panics due to mismatched bit-length validation in sdk.Int and sdk.Dec. Version 1.4.0 is the first patched version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for security advisories and changelog for cosmossdk.io/math

# Check for any security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: GO, package: "cosmossdk.io/math") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

# Get the changelog between versions
echo "Checking changes between v1.3.0 and v1.4.0:"
rg -A 5 "## \[1\.4\.0\]" || echo "Changelog not found in repository"

Length of output: 818


Line range hint 4-16: Verify the maintenance status of the forked cosmos-sdk

The replace directive points to a fork at github.com/liftedinit/cosmos-sdk. Ensure this fork is actively maintained and synchronized with the upstream repository.


Line range hint 19-24: Verify version compatibility between Cosmos SDK packages

The updated versions need to be compatible with each other:

  • cosmossdk.io/math v1.4.0
  • cosmossdk.io/x/upgrade v0.1.2
  • github.com/cosmos/cosmos-sdk v0.50.8
✅ Verification successful

Let me gather more information about the version compatibility by checking the go.mod files in the Cosmos SDK repository.


Let me check one more thing to verify the compatibility by looking at the upgrade module's dependencies.


The package versions are compatible with each other

The versions in use are compatible because:

  1. The go.sum file shows clean version resolution for both cosmossdk.io/math v1.4.0 and cosmossdk.io/x/upgrade v0.1.2
  2. These packages are being used together with cosmos-sdk v0.50.8 in the same module without any version conflicts or incompatible markers
  3. The go.mod file shows proper version resolution and no dependency conflicts between these packages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for version compatibility issues

# Search for any version-related errors or warnings in go.mod
rg "incompatible" go.mod

# Check if these versions are commonly used together
gh api search/code -X GET -f q='path:go.mod "cosmossdk.io/math" "v1.4.0" "cosmos-sdk" "v0.50.8"' --jq '.items[].repository.full_name' || echo "No matching combinations found"

Length of output: 288


Script:

#!/bin/bash
# Check the dependencies in cosmos-sdk v0.50.8
gh api repos/cosmos/cosmos-sdk/contents/go.mod?ref=v0.50.8 | jq -r '.content' | base64 -d | grep -A 5 "require ("

# Check if cosmossdk.io/math v1.4.0 is used in cosmos-sdk v0.50.8
gh api repos/cosmos/cosmos-sdk/contents/go.mod?ref=v0.50.8 | jq -r '.content' | base64 -d | grep "cosmossdk.io/math"

# Check if cosmossdk.io/x/upgrade v0.1.2 is used in cosmos-sdk v0.50.8
gh api repos/cosmos/cosmos-sdk/contents/go.mod?ref=v0.50.8 | jq -r '.content' | base64 -d | grep "cosmossdk.io/x/upgrade"

# Check the go.sum file for any version conflicts
rg "cosmossdk.io/(math|x/upgrade)" go.sum

Length of output: 1005


Script:

#!/bin/bash
# Check the dependencies in cosmossdk.io/x/upgrade v0.1.2
gh api repos/cosmos/cosmos-sdk/contents/x/upgrade/go.mod?ref=v0.50.8 | jq -r '.content' | base64 -d | grep -E "cosmossdk.io/math|github.com/cosmos/cosmos-sdk"

# Check for any dependency conflicts in the entire go.mod
cat go.mod

Length of output: 10960

// always have a unique upgrade registered for the current version to test in system tests
Upgrades = append(Upgrades, noop.NewUpgrade(app.Version()))
}
Upgrades = append(Upgrades, next.NewUpgrade(app.Version()))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Potential duplicate upgrades and version handling concerns

The unconditional append of upgrades could lead to duplicate entries if RegisterUpgradeHandlers is called multiple times. Additionally, using app.Version() directly for upgrade naming needs careful consideration.

Consider these improvements:

  1. Add a check to prevent duplicate upgrades
  2. Validate version format before using it as an upgrade name

Consider applying this improvement:

-	Upgrades = append(Upgrades, next.NewUpgrade(app.Version()))
+	version := app.Version()
+	// Check for existing upgrade with this version
+	for _, upgrade := range Upgrades {
+		if upgrade.UpgradeName == version {
+			return
+		}
+	}
+	Upgrades = append(Upgrades, next.NewUpgrade(version))
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Upgrades = append(Upgrades, next.NewUpgrade(app.Version()))
version := app.Version()
// Check for existing upgrade with this version
for _, upgrade := range Upgrades {
if upgrade.UpgradeName == version {
return
}
}
Upgrades = append(Upgrades, next.NewUpgrade(version))

@fmorency fmorency merged commit 799b309 into liftedinit:main Nov 25, 2024
14 checks passed
@fmorency fmorency deleted the upgrade branch November 25, 2024 19:41
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.

1 participant