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: genesis validation #319

Merged
merged 1 commit into from
Feb 26, 2025
Merged

Conversation

MaxMustermann2
Copy link
Contributor

@MaxMustermann2 MaxMustermann2 commented Feb 26, 2025

  • Check that operator address, earnings address and approve address are all the same
  • Do not vaidate that asset address is Ethereum only; support others

Summary by CodeRabbit

  • Bug Fixes
    • Relaxed asset ID validation to allow mixed-case input during subscriptions and deposits.
    • Enhanced operator validation by ensuring that both earnings and approval addresses match the operator’s address.

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request updates validation routines across several modules. Two files modify calls to the ValidateID function by changing the boolean parameter from true to false, thereby adjusting case sensitivity enforcement for asset and staker IDs. Another file revamps the operator address validations by replacing the Bech32 conversion of the earnings address with a direct comparison to the operator address and by introducing a new check for the approval address. No changes were made to the public API declarations.

Changes

File(s) Change Summary
x/appchain/coordinator/types/msg.go
x/assets/types/genesis.go
Modified the second argument in the ValidateID function call from true to false, altering case sensitivity enforcement for asset and staker IDs.
x/operator/types/genesis.go Updated operator validations by replacing Bech32 conversion with a direct comparison of EarningsAddr to OperatorAddress and added a check for ApproveAddr.

Sequence Diagram(s)

sequenceDiagram
    participant V as ValidateOperators
    participant O as OperatorInfo
    V->>O: Compare EarningsAddr with OperatorAddress
    alt EarningsAddr mismatch
        V-->>O: Return earnings address error
    else EarningsAddr match
        V->>O: Compare ApproveAddr with OperatorAddress
        alt ApproveAddr mismatch
            V-->>O: Return approve address error
        else
            V-->>O: Validation successful
        end
    end
Loading

Poem

In my burrow of code I hop with cheer,
Validations refined, crisp and clear!
No more forced lowercase in the drift,
Earnings and approve addresses now swiftly shift.
Carrots and bytes in a rhythmic tap,
I celebrate these changes with a joyful rap!
🥕🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 505516b and 6dc5f04.

📒 Files selected for processing (3)
  • x/appchain/coordinator/types/msg.go (1 hunks)
  • x/assets/types/genesis.go (1 hunks)
  • x/operator/types/genesis.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-unit-e2e
  • GitHub Check: test-unit-cover
  • GitHub Check: goreleaser
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
x/assets/types/genesis.go (1)

127-127:

✅ Verification successful

Case sensitivity validation updated for stakerID

The change modifies the ValidateID function call to set the third parameter to false, which adjusts the case sensitivity enforcement for staker IDs. This aligns with the PR objective to remove certain address validation restrictions.


🏁 Script executed:

#!/bin/bash
# Search for other calls to ValidateID to ensure consistent parameter usage
rg "ValidateID\(" --type go -A 3 -B 1

Length of output: 6668


ValidateID Usage in Genesis Updated Consistently

The change in x/assets/types/genesis.go now calls:

if _, stakerClientChainID, err = ValidateID(stakerID, true, false); err != nil {

This update sets the third parameter to false, which disables the Ethereum address validation while still enforcing the lowercase check on stakerID. Our repository-wide scan confirms that similar calls (especially in the delegation and msg modules) use this same parameter configuration, aligning well with the PR’s objective to relax address validation restrictions.

No further modifications are required.

x/appchain/coordinator/types/msg.go (1)

47-51:

✅ Verification successful

Case sensitivity validation updated for assetID

The change modifies the ValidateID function call to set the third parameter to false, relaxing the case sensitivity enforcement for asset IDs. This change supports the PR objective to remove the restriction that only Ethereum addresses are acceptable.


🏁 Script executed:

#!/bin/bash
# Search for the ValidateID function definition to understand the parameter meaning
rg "func ValidateID" --type go -A 10

Length of output: 1520


Asset ID Validation Update Confirmed

The update in x/appchain/coordinator/types/msg.go now correctly disables Ethereum address validation by passing false as the third parameter. As verified by the definition in x/assets/types/keys.go, the function enforces lowercase formatting when the second parameter is true while selectively skipping Ethereum-specific checks when the third parameter is false. This change is consistent with the PR’s objective of removing the restriction to only Ethereum addresses.

x/operator/types/genesis.go (1)

64-75:

✅ Verification successful

Enforce identical addresses for operator validation

This change implements a key part of the PR objective by ensuring that the operator address, earnings address, and approval address are all identical. The code now directly compares these addresses rather than just checking format validity.

The previous implementation only validated the format of the earnings address, but this change enforces a stricter requirement that all three addresses must match exactly.


🏁 Script executed:

#!/bin/bash
# Look for any references to these address fields to ensure consistency
rg "EarningsAddr|ApproveAddr" --type go -A 2 -B 2

Length of output: 30525


Operator Address Equality Enforcement Verified

The changes in x/operator/types/genesis.go now correctly enforce that the operator address, earnings address, and approval address are identical. The code directly compares these addresses:

	if op.OperatorInfo.EarningsAddr != address {
		return nil, errorsmod.Wrapf(
			ErrInvalidGenesisData,
			"operator address %s has earnings address %s", address, op.OperatorInfo.EarningsAddr,
		)
	}
	if op.OperatorInfo.ApproveAddr != address {
		return nil, errorsmod.Wrapf(
			ErrInvalidGenesisData,
			"operator address %s has approve address %s", address, op.OperatorInfo.ApproveAddr,
		)
	}

A repository-wide search confirmed that all references to EarningsAddr and ApproveAddr consistently use the operator address for assignment and validation. This refines the validation logic from simply checking the format to ensuring full consistency as required by the PR.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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

@bwhour bwhour left a comment

Choose a reason for hiding this comment

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

LGTM.

@MaxMustermann2 MaxMustermann2 added this pull request to the merge queue Feb 26, 2025
Merged via the queue into imua-xyz:develop with commit cd50583 Feb 26, 2025
23 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.

3 participants