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 nil reference panic in abci.go #1745

Merged
merged 2 commits into from
Nov 17, 2024
Merged

fix nil reference panic in abci.go #1745

merged 2 commits into from
Nov 17, 2024

Conversation

joe-bowman
Copy link
Contributor

@joe-bowman joe-bowman commented Nov 17, 2024

1. Summary

Fixes #1744

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

3. Implementation details

Fix panic in v1.7.0 when onboarding a new zone.

Summary by CodeRabbit

  • New Features

    • Introduced a retraction for version v1.7.0 due to a safety bug, ensuring users are aware of potential issues.
  • Bug Fixes

    • Enhanced error handling in the interchain staking module to prevent runtime errors related to zone.DelegationAddress.
  • Chores

    • Updated dependencies for improved compatibility and security, including adjustments for vulnerabilities in specific libraries.

Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Walkthrough

The pull request includes significant updates to the go.mod file, which involve modifying dependencies, adding a retraction for version v1.7.0 due to a safety bug, and adjusting replace directives for various libraries. Additionally, changes to the BeginBlocker function in x/interchainstaking/keeper/abci.go introduce a nil check for zone.DelegationAddress, enhancing error handling by preventing nil pointer dereference errors.

Changes

File Path Change Summary
go.mod Updated dependencies, added retraction for v1.7.0 (safety bug), adjusted replace directives.
x/interchainstaking/keeper/abci.go Added nil check for zone.DelegationAddress in BeginBlocker to prevent nil pointer dereference.

Assessment against linked issues

Objective Addressed Explanation
No error thrown if a new zone is encountered (#1744)

🐰 In the meadow, changes bloom,
With nil checks to banish gloom.
Dependencies updated, retractions in place,
A safer code, a happier space!
Let's hop along, with joy we embrace! 🌼


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

🧹 Outside diff range and nitpick comments (2)
go.mod (2)

Line range hint 3-3: Invalid Go version specified

The Go version 1.23.3 is invalid. Go versions follow semantic versioning, and the latest stable version is 1.22.x. This could cause build issues.

-go 1.23.3
+go 1.22.0

Based on the vulnerability scan results, I can generate the final response since we have clear evidence of potential security concerns with the dependency versions used in the PR.

Update dependency versions to address security vulnerabilities

The current dependency versions have known security vulnerabilities:

  • github.com/cosmos/cosmos-sdk v0.46.16:

    • Affected by "Barberry" vulnerability (MODERATE) in v0.46.0-0.46.13
    • Has slashing evasion vulnerability (LOW) in versions <= 0.47.9
    • Contains PrepareProposalHandler and vesting module vulnerabilities (MODERATE) in versions <= 0.47.8
  • github.com/tendermint/tendermint v0.34.33:

    • Contains signature verification vulnerability (MODERATE) in v0.34.0-0.34.9
    • Has uncontrolled resource consumption vulnerability (MODERATE) in v0.34.0-0.34.3
  • github.com/cosmos/ibc-go/v6 v6.3.1:

    • Affected by "Huckleberry" vulnerability (MODERATE)
    • Contains potential reentrancy vulnerability in ibc-hooks (CRITICAL)

Please update these dependencies to their latest patched versions to address these security concerns.

🔗 Analysis chain

Line range hint 4-340: Verify dependency updates

While the dependency updates appear to be routine maintenance, it's good practice to verify that these updates don't introduce any known vulnerabilities.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any known vulnerabilities in the dependencies

echo "Checking for known vulnerabilities in direct dependencies..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 10, ecosystem: GO, package: "github.com/cosmos/cosmos-sdk") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

# Check other critical dependencies
for dep in "github.com/tendermint/tendermint" "github.com/cosmos/ibc-go"; do
  echo "Checking $dep..."
  gh api graphql -f query="
  {
    securityVulnerabilities(first: 10, ecosystem: GO, package: \"$dep\") {
      nodes {
        advisory {
          summary
          severity
          publishedAt
        }
        vulnerableVersionRange
        firstPatchedVersion {
          identifier
        }
      }
    }
  }"
done

Length of output: 6161

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 86729ea and a634dad.

📒 Files selected for processing (2)
  • go.mod (1 hunks)
  • x/interchainstaking/keeper/abci.go (1 hunks)
🔇 Additional comments (4)
x/interchainstaking/keeper/abci.go (2)

55-71: LGTM: Nil check prevents panic for new zones.

The addition of the nil check for zone.DelegationAddress successfully addresses issue #1744 by preventing nil pointer dereference when accessing delegation addresses of newly onboarded zones.


55-71: Verify impact on other periodic operations.

The changes are within a block that executes every 30 blocks. Let's verify that returning early on address decoding error doesn't disrupt other critical operations.

✅ Verification successful

Based on the shell script results, I can now generate the final response:

Early return on address decoding error is safe

The error handling for delegation address decoding is appropriate since:

  • The operation is within a 30-block interval check that handles multiple independent tasks
  • Other critical operations like EnsureWithdrawalAddresses and HandleMaturedWithdrawals continue to execute even if this fails
  • The error is properly logged for monitoring
  • The DelegationAddress balance query is independent and can safely retry on the next 30-block interval
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other operations that might be affected by early returns in the block interval check

# Search for other operations within the same block interval
rg -B 10 -A 10 "BlockHeight\(\)%30\s*==\s*0" --type go

# Look for dependencies on DelegationAddress processing
ast-grep --pattern 'zone.DelegationAddress.$$$'

Length of output: 54082

go.mod (2)

Line range hint 341-360: LGTM! Well-documented replace directives

The replace directives are well-documented and address specific issues including security vulnerabilities, broken dependencies, and required forks for compatibility.


362-364: LGTM! Appropriate version retraction

The retraction of v1.7.0 is appropriate given the safety bug (nil reference panic) being fixed in this PR.

#!/bin/bash
# Verify if there are any other references to v1.7.0 in the codebase that might need attention

echo "Checking for v1.7.0 references in the codebase..."
rg "v1\.7\.0" --type-add 'docs:*.{md,txt,rst}' --type docs

Comment on lines +56 to +71
addressBytes, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, zone.AccountPrefix)
if err != nil {
k.Logger(ctx).Error("cannot decode bech32 delegation addr", "error", err.Error())
}
zone.DelegationAddress.IncrementBalanceWaitgroup()
k.ICQKeeper.MakeRequest(
ctx,
zone.ConnectionId,
zone.ChainId,
types.BankStoreKey,
append(banktypes.CreateAccountBalancesPrefix(addressBytes), []byte(zone.BaseDenom)...),
sdk.NewInt(-1),
types.ModuleName,
"accountbalance",
0,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling flow.

The current implementation continues processing even if address decoding fails, which could lead to inconsistent state. Consider restructuring the error handling:

 if zone.DelegationAddress != nil {
   addressBytes, err := addressutils.AccAddressFromBech32(zone.DelegationAddress.Address, zone.AccountPrefix)
   if err != nil {
     k.Logger(ctx).Error("cannot decode bech32 delegation addr", "error", err.Error())
+    return false
   }
   zone.DelegationAddress.IncrementBalanceWaitgroup()
   k.ICQKeeper.MakeRequest(
     ctx,
     zone.ConnectionId,
     zone.ChainId,
     types.BankStoreKey,
     append(banktypes.CreateAccountBalancesPrefix(addressBytes), []byte(zone.BaseDenom)...),
     sdk.NewInt(-1),
     types.ModuleName,
     "accountbalance",
     0,
   )
 }

Committable suggestion skipped: line range outside the PR's diff.

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.

Project coverage is 61.60%. Comparing base (86729ea) to head (a634dad).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
x/interchainstaking/keeper/abci.go 0.00% 17 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1745      +/-   ##
==========================================
- Coverage   61.60%   61.60%   -0.01%     
==========================================
  Files         196      196              
  Lines       17012    17013       +1     
==========================================
  Hits        10481    10481              
- Misses       5685     5686       +1     
  Partials      846      846              
Flag Coverage Δ
unittests 61.60% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
x/interchainstaking/keeper/abci.go 26.66% <0.00%> (-0.37%) ⬇️

@joe-bowman joe-bowman merged commit f11e862 into main Nov 17, 2024
16 of 18 checks passed
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.

Nil reference in abci.go after new zone onboarding
1 participant