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

refactor(types)!: removed global config for verifier #18607

Merged
merged 61 commits into from
Feb 2, 2024

Conversation

bizk
Copy link
Contributor

@bizk bizk commented Dec 1, 2023

Description

Closes: #18608

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Refactor
    • Relocated address verifier logic for enhanced efficiency and clarity.
  • Bug Fixes
    • Improved error messaging for address validation errors.
  • Chores
    • Removed obsolete configuration and verification code, streamlining the system.
  • Tests
    • Updated tests to align with the new address verification approach.

Copy link
Contributor

coderabbitai bot commented Dec 1, 2023

Walkthrough

The changes primarily focus on the decoupling of address verification logic from the global SDK configuration and its integration into more specific areas, such as the Bech32 codec. This adjustment aligns with the goal of removing global configurations and clarifying the use cases for address verification. By relocating address verification to contextually appropriate locations, the changes ensure that Bech32 checks are explicitly used when intended, and custom address verifiers can be implemented without conflicting with the default behavior.

Changes

File Pattern Change Summary
codec/address/bech32_codec.go Refactored address verification into verifyAddress and updated StringToBytes, BytesToString.
store/root/store_test.go Modified import statements.
types/address.go, types/address_test.go Removed VerifyAddressFormat, updated Bech32 address handling, and removed unused imports.
types/config.go, types/config_test.go Removed SLIP-44 fields, address verification, and updated SetTxEncoder method. Removed test for SetFullFundraiserPath.
x/auth/types/credentials_test.go Updated to use direct verification methods instead of sdk.VerifyAddressFormat.
x/gov/keeper/msg_server_test.go Improved specificity of error messages.
fuzz/oss-fuzz-build.sh Removed FuzzTypesVerifyAddressFormat function.

Assessment against linked issues

Objective Addressed Explanation
Remove address verifier from global sdk.Config and clarify use cases for address verification (#18608)
Decouple verification logic from global configuration and integrate it into specific areas like Bech32 codec
Ensure custom address verifiers can be implemented without conflicting with default Bech32 checks

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.
  • 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 from git 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.

@bizk bizk changed the title featÑ removed global config for verifier feat: removed global config for verifier Dec 1, 2023
@github-actions github-actions bot added C:CLI C:Keys Keybase, KMS and HSMs C:x/auth labels Dec 1, 2023
@tac0turtle
Copy link
Member

Tbh those PRs looks related as you are removing the verifier from all the AccAdressFromBech32 and all. I agree that extending it to support a custom address codec should be done in a follow-up; but the swap should be straightforward.

lets do this in this pr, otherwise lets can close this pr and remake it with the changes proposed. This pr becomes a bit mute if we avoid doing it here.

@bizk
Copy link
Contributor Author

bizk commented Jan 9, 2024

So we are using the codec then, right?

@tac0turtle
Copy link
Member

So we are using the codec then, right?

yea

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

types/address.go Outdated Show resolved Hide resolved
@JulianToledano
Copy link
Contributor

see above, please update AccAddressFromBech32, ValAddressFromBech32,... as in https://github.com/cosmos/cosmos-sdk/compare/julien/address-cdc#diff-f275f0ae24edfd997f8b93477171779ea2caa786d98cd249f4cb7699e58a67b2L6-L530

done

Comment on lines 166 to 175

// AccAddressFromBech32 creates an AccAddress from a Bech32 string.
func AccAddressFromBech32(address string) (addr AccAddress, err error) {
if len(strings.TrimSpace(address)) == 0 {
return AccAddress{}, errors.New("empty address string is not allowed")
}

bech32PrefixAccAddr := GetConfig().GetBech32AccountAddrPrefix()

bz, err := GetFromBech32(address, bech32PrefixAccAddr)
if err != nil {
return nil, err
}

err = VerifyAddressFormat(bz)
if err != nil {
return nil, err
}

return AccAddress(bz), nil
addrCdc := addresscodec.NewBech32Codec(bech32PrefixAccAddr)
return addrCdc.StringToBytes(address)
}

// Returns boolean for whether two AccAddresses are Equal
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [16-311]

The refactoring to use addresscodec.NewBech32Codec for address decoding introduces a significant change in how addresses are handled within the SDK. It's important to ensure that documentation, examples, and migration guides are updated to reflect these changes. This will help developers understand how to use the new address codecs and adjust their code accordingly.

Would you like assistance in updating the documentation or creating a migration guide for these changes?

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

Commits Files that changed from the base of the PR and between d15a92e and ae6fc3b.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 134-134: The changelog entry for PR refactor(types)!: removed global config for verifier #18607 has been updated to include a note about the breaking change, which is good practice for transparency and informing users. However, ensure that all related documentation, migration guides, or upgrade instructions are also updated to reflect this breaking change and guide users through any necessary adjustments.

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

Commits Files that changed from the base of the PR and between ae6fc3b and 83dc83b.
Files selected for processing (1)
  • types/address.go (5 hunks)
Additional comments: 4
types/address.go (4)
  • 15-15: The import of the addresscodec package from github.com/cosmos/cosmos-sdk/codec/address introduces a new dependency for handling address encoding and decoding. This change aligns with the PR's objective to decouple address verification from global configuration, promoting modularity.
  • 170-171: The AccAddressFromBech32 function now uses the addresscodec.NewBech32Codec to decode Bech32 addresses, which is a significant change from the previous global verifier approach. This modification enhances modularity by allowing for different address codecs to be used, aligning with the PR's objectives. Ensure that all calls to this function across the codebase are updated to handle the new return type, as this change could impact error handling and address parsing logic.
Verification successful

The verification process has identified three instances in types/address.go where AccAddressFromBech32 is used, specifically at lines 158, 223, and 244. Each of these usages correctly handles the return type, which includes both the address and an error, indicating that the changes to AccAddressFromBech32 have been properly integrated within the codebase. This confirms that the modifications align with the PR's objectives of enhancing modularity by allowing for different address codecs to be used and ensuring that error handling and address parsing logic are appropriately managed across the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all usages of AccAddressFromBech32 handle the new return type correctly.
ast-grep --lang go --pattern $'AccAddressFromBech32($_)'

Length of output: 244

* 309-310: The `ValAddressFromBech32` function's adaptation to use `addresscodec.NewBech32Codec` for decoding addresses is consistent with the changes made to `AccAddressFromBech32`. This ensures a uniform approach to address decoding across different address types, supporting the PR's goal of removing global verifier dependencies. Similar to `AccAddressFromBech32`, verify that all usages of this function are compatible with the changes.
Verification successful

The verification process has identified three usages of the ValAddressFromBech32 function within the types/address.go file. These usages are at lines 315, 373, and 395, respectively. Each instance correctly handles the return type, indicating that the changes made to the ValAddressFromBech32 function are properly integrated across its usages within the same file.

Given this information, it can be concluded that the adaptation of the ValAddressFromBech32 function to use addresscodec.NewBech32Codec for decoding addresses, and the subsequent handling of its new return type, is correctly implemented in the identified usages within the codebase. This supports the PR's goal of removing global verifier dependencies and ensures a uniform approach to address decoding across different address types.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all usages of ValAddressFromBech32 handle the new return type correctly.
ast-grep --lang go --pattern $'ValAddressFromBech32($_)'

Length of output: 244

* 461-462: The changes to `ConsAddressFromBech32` mirror those applied to `AccAddressFromBech32` and `ValAddressFromBech32`, utilizing `addresscodec.NewBech32Codec` for address decoding. This consistent application of the new codec across different address types is crucial for maintaining a coherent and modular approach to address handling within the SDK. As with the other address types, ensure compatibility with the updated function across the codebase.
Verification successful

The new context from the shell scripts provides the necessary details around the usage of ConsAddressFromBech32 at lines 520 and 542 in types/address.go. From the provided output, it's clear that in both instances, the function ConsAddressFromBech32 is used within a conditional block where the error returned by the function is checked. If an error is present, the function returns the error, effectively handling the new return type correctly.

This behavior aligns with the original review comment's emphasis on ensuring compatibility across the codebase with the updated function. The usages of ConsAddressFromBech32 correctly handle the return values, especially focusing on error handling, which is crucial for maintaining robustness in address handling within the SDK.

Given this information, it can be concluded that the changes to ConsAddressFromBech32 and its usages within the codebase are correctly implemented and handle the new return type as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all usages of ConsAddressFromBech32 handle the new return type correctly.
ast-grep --lang go --pattern $'ConsAddressFromBech32($_)'

Length of output: 180



Script:

#!/bin/bash
# Extract and review the usage of ConsAddressFromBech32 at lines 520 and 542 in types/address.go
fd "address.go" --exec grep -C 3 "ConsAddressFromBech32" {}

Length of output: 548

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! thank you

@JulianToledano JulianToledano added this pull request to the merge queue Feb 2, 2024
Merged via the queue into cosmos:main with commit ffda4af Feb 2, 2024
55 of 57 checks passed
@JulianToledano JulianToledano deleted the feature/sdkConfig-verifier branch February 2, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove address verifier from global sdk.Config
6 participants