Skip to content

Conversation

@fbac
Copy link
Collaborator

@fbac fbac commented May 16, 2025

Add Ethereum address validation to ensure valid hex and non-zero contract addresses in configuration validation

Introduces a new validateHexAddress() function in validation.go that performs hex address validation for contract addresses. The function validates that addresses are non-empty, valid hex format, and not zero addresses using the go-ethereum/common package. This validation is applied to RateRegistryAddress, GroupMessageBroadcasterAddress, IdentityUpdateBroadcasterAddress, and NodeRegistryAddress configuration fields.

📍Where to Start

Start with the new validateHexAddress() function in validation.go which contains the core validation logic for Ethereum addresses.


Macroscope summarized 11a7665.

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for Ethereum contract addresses in configuration to better detect missing, invalid, or zero addresses.
  • Chores

    • Enhanced internal address validation logic for more robust configuration checks.

@fbac fbac requested a review from a team as a code owner May 16, 2025 15:00
@graphite-app
Copy link

graphite-app bot commented May 16, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 2025

"""

Walkthrough

The validation logic for Ethereum contract addresses in the configuration was updated. A new function, validateHexAddress, was introduced to perform explicit checks for empty, invalid, or zero addresses using Ethereum-specific utilities. This function replaces the previous generic validation approach for contract address fields and requires the Ethereum common package.

Changes

File(s) Change Summary
pkg/config/validation.go Introduced validateHexAddress for Ethereum address validation; updated contract address checks to use this function; imported Ethereum common package.

Sequence Diagram(s)

sequenceDiagram
    participant ConfigValidator
    participant HexAddressValidator
    participant EthereumCommon

    ConfigValidator->>HexAddressValidator: validateHexAddress(address, fieldName, set)
    HexAddressValidator->>EthereumCommon: IsHexAddress(address)
    EthereumCommon-->>HexAddressValidator: returns true/false
    HexAddressValidator->>EthereumCommon: HexToAddress(address)
    EthereumCommon-->>HexAddressValidator: returns Address
    HexAddressValidator->>ConfigValidator: Add error to set if invalid
Loading

"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 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 11a7665 and c9cc25f.

📒 Files selected for processing (1)
  • pkg/config/validation.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/config/validation.go
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Upgrade Tests
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
  • GitHub Check: Test (Node)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@fbac fbac force-pushed the 05-16-validate_chain_addresses branch from 11a7665 to c9cc25f Compare May 16, 2025 15:03
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🔭 Outside diff range comments (3)
pkg/config/validation.go (3)

98-102: ⚠️ Potential issue

Error return value is not checked

The error return value from validateHexAddress is not being checked here, which is also flagged by the linter. Either handle the error appropriately or modify the function to not return an error if it's not intended to be used.

-		validateHexAddress(
+		_ = validateHexAddress(
			options.Contracts.SettlementChain.RateRegistryAddress,
			"contracts.settlement-chain.rate-registry-address",
			missingSet,
		)
🧰 Tools
🪛 GitHub Check: Lint-Go

[failure] 98-98:
Error return value is not checked (errcheck)

🪛 GitHub Actions: Lint

[error] 98-98: Error return value is not checked (errcheck)


131-135: ⚠️ Potential issue

Error return value is not checked

The error return value from validateHexAddress is not being checked, as flagged by the linter. Either handle the error or explicitly discard it.

-	validateHexAddress(
+	_ = validateHexAddress(
		options.Contracts.AppChain.IdentityUpdateBroadcasterAddress,
		"contracts.app-chain.identity-update-broadcaster-address",
		missingSet,
	)
🧰 Tools
🪛 GitHub Check: Lint-Go

[failure] 131-131:
Error return value is not checked (errcheck)


158-162: ⚠️ Potential issue

Error return value is not checked

Similar to previous instances, the error return value from validateHexAddress is not being checked here.

-	validateHexAddress(
+	_ = validateHexAddress(
		options.Contracts.SettlementChain.NodeRegistryAddress,
		"contracts.settlement-chain.node-registry-address",
		missingSet,
	)
🛑 Comments failed to post (2)
pkg/config/validation.go (2)

126-130: ⚠️ Potential issue

Error return value is not checked

The error return value from validateHexAddress is not being checked, as indicated by the static analysis tool. Either handle the error or explicitly ignore it.

-	validateHexAddress(
+	_ = validateHexAddress(
		options.Contracts.AppChain.GroupMessageBroadcasterAddress,
		"contracts.app-chain.group-message-broadcaster-address",
		missingSet,
	)
📝 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.

	_ = validateHexAddress(
		options.Contracts.AppChain.GroupMessageBroadcasterAddress,
		"contracts.app-chain.group-message-broadcaster-address",
		missingSet,
	)
🧰 Tools
🪛 GitHub Check: Lint-Go

[failure] 126-126:
Error return value is not checked (errcheck)

🤖 Prompt for AI Agents
In pkg/config/validation.go around lines 126 to 130, the call to
validateHexAddress returns an error that is currently not checked. Modify the
code to capture the error return value and handle it appropriately, such as
returning the error from the current function or logging it. If the error can be
safely ignored, explicitly ignore it using the blank identifier. This ensures
proper error handling and satisfies the static analysis tool.

221-229: 🛠️ Refactor suggestion

Consider removing the error return if it's not being used

The validateHexAddress function returns an error, but none of the callers check this return value. Since all error conditions are already handled by adding to the provided set map parameter, consider simplifying the function signature by removing the error return.

-func validateHexAddress(address string, fieldName string, set map[string]struct{}) error {
+func validateHexAddress(address string, fieldName string, set map[string]struct{}) {
	if address == "" {
		set[fmt.Sprintf("--%s is required", fieldName)] = struct{}{}
	}
	if !common.IsHexAddress(address) || common.HexToAddress(address) == (common.Address{}) {
		set[fmt.Sprintf("--%s is invalid", fieldName)] = struct{}{}
	}
-	return nil
}

Alternatively, if you want to retain the error return for future use:

func validateHexAddress(address string, fieldName string, set map[string]struct{}) error {
	if address == "" {
		set[fmt.Sprintf("--%s is required", fieldName)] = struct{}{}
+		return fmt.Errorf("address is empty")
	}
	if !common.IsHexAddress(address) || common.HexToAddress(address) == (common.Address{}) {
		set[fmt.Sprintf("--%s is invalid", fieldName)] = struct{}{}
+		return fmt.Errorf("address is invalid")
	}
	return nil
}
📝 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.

func validateHexAddress(address string, fieldName string, set map[string]struct{}) {
	if address == "" {
		set[fmt.Sprintf("--%s is required", fieldName)] = struct{}{}
	}
	if !common.IsHexAddress(address) || common.HexToAddress(address) == (common.Address{}) {
		set[fmt.Sprintf("--%s is invalid", fieldName)] = struct{}{}
	}
}
func validateHexAddress(address string, fieldName string, set map[string]struct{}) error {
	if address == "" {
		set[fmt.Sprintf("--%s is required", fieldName)] = struct{}{}
		return fmt.Errorf("address is empty")
	}
	if !common.IsHexAddress(address) || common.HexToAddress(address) == (common.Address{}) {
		set[fmt.Sprintf("--%s is invalid", fieldName)] = struct{}{}
		return fmt.Errorf("address is invalid")
	}
	return nil
}
🤖 Prompt for AI Agents
In pkg/config/validation.go around lines 221 to 229, the function
validateHexAddress returns an error but never actually returns any error value,
and callers do not check this return. Remove the error return type from the
function signature and eliminate the return statement to simplify the function,
since all error conditions are handled by updating the provided set map.

@macroscopeapp
Copy link

macroscopeapp bot commented May 16, 2025

Add hex address validation for blockchain contract addresses in config validation

Introduces a new validateHexAddress() function in validation.go that performs validation checks on Ethereum addresses. The function verifies:

  • Empty address check
  • Valid hex address format using common.IsHexAddress()
  • Non-zero address verification

This validation is now applied to rate registry, group message broadcaster, identity update broadcaster, and node registry contract addresses in both app chain and settlement chain configurations.

📍Where to Start

Start with the new validateHexAddress() function in validation.go which contains the core validation logic for Ethereum addresses.


Macroscope summarized c9cc25f.

@fbac fbac merged commit acc2a81 into main May 16, 2025
9 checks passed
@fbac fbac deleted the 05-16-validate_chain_addresses branch May 16, 2025 16:05
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