-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
WalkthroughThe changes in this pull request involve modifications to the upgrade management system within a Cosmos SDK application. Key alterations include the initialization of the Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 processThe 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 architectureThese changes represent a significant simplification of the upgrade process. Consider adding a README.md in the
app/upgrades
directory to document:
- The new upgrade system architecture
- The responsibilities of each component
- The workflow for creating new upgrades
go.mod (2)
Line range hint
1-24
: Document dependency version constraintsConsider adding a
DEPENDENCIES.md
file to document:
- Why specific versions were chosen
- Known issues with newer versions
- Security considerations
- 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:
- The fork is very recent (created Feb 2024) and has limited activity
- 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
- 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 changesUsing a forked version (
liftedinit/cosmos-sdk
) requires careful consideration:
- The fork should be actively maintained
- Changes in PR Genesis / Network Launch Params #1 should be reviewed
- 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/1Length 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=5Length of output: 38910
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ 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:
- No new modules are being introduced that would require new stores
- No existing stores are being deprecated or removed
- 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:
- Where is the metadata now being handled?
- 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
andStoreUpgrades
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:
- The upgrade framework version is compatible with the latest security patches
- The upgrade handlers properly handle chain state migrations
- 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:
- Using a secure version of the upgrade framework (v0.1.2) with proper error handling
- 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
- 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:
- Core downgrade to v0.11.0 due to SDK version mismatch
- Math package upgrade to v1.4.0
- 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:
- Core downgrade (v0.12 -> v0.11.0) is explicitly due to wrong SDK v51 tagging
- Goleveldb downgrade is pinned to a specific commit to avoid simulation failures
- 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:
- The
go.sum
file shows clean version resolution for bothcosmossdk.io/math v1.4.0
andcosmossdk.io/x/upgrade v0.1.2
- These packages are being used together with
cosmos-sdk v0.50.8
in the same module without any version conflicts or incompatible markers - 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())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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:
- Add a check to prevent duplicate upgrades
- 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.
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)) |
Summary by CodeRabbit
New Features
Bug Fixes
Chores